Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RenderContext and vnode to PluginRenderContext #928

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

NicoZweifel
Copy link

@NicoZweifel NicoZweifel commented Nov 30, 2022

I am unsure if there is any reason not to expose the whole RenderContext to the pluginContext, but I think getting the vnode or at least the type and other context properties would be really helpful for plugin development.

For example for something like styled-components e.g. #927

@adamgreg
Copy link
Contributor

Is this likely to merge? I'm putting together a Fresh project, and trying to use an existing React component library that uses styled-components. I've been trying to write a plugin for SSR, and it looks like I need this extra context to be able to interact with the tree before rendering.

@marvinhagemeister
Copy link
Collaborator

@adamgreg I'd love to hear more details. How would the changes in this PR aid with styled-components SSR? From what I can gather from their docs it seems like setting up a virtual stylesheet before rendering, then doing the render and then returning the stylesheet in the fresh plugin options would be the way to go.

@adamgreg
Copy link
Contributor

Hi @marvinhagemeister, thanks for the quick response! I'm new to Fresh and still finding my feet, to be honest, so please forgive me if I have the wrong idea about some of this.

My understanding of their docs is that I need to wrap the tree in a StyleSheetManager component before rendering (either directly, or via sheet.collectStyles()). As the PluginRenderContext that the plugin receives only includes the render method, I don't see an easy way to wrap the tree within the plugin.

At the moment my best guess is that instead of using a plugin I might be able to use _app.tsx to wrap every page in a StyleSheetManager, and handle the sheet in a custom render function I pass to start(). If I do that I'm still not sure how I would access the same ServerStyleSheet instance in both the App function and my custom render function (unless it's safe to use a global variable).

Any help would be gratefully appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants