Importing the CSS for remote components #714
-
Min reproducible repo: Background But I can't figure out a way to retrieve the CSS code for the remote component on server-side rendering. At the moment, while the HTML markup of the remote component is rendered correctly in SSR, the CSS link tag is only inserted into the DOM by It appears that the only "workaround" for the remote component's CSS to be SSR-ed correctly is to use inline style (aka using the HTML Question: Otherwise, if using inline style is unavoidable, is anyone aware of any webpack plugin that converts CSS modules into inline styles during transpilation? Hence allowing me to continue using the CSS modules convention in my codebase? 🤞🏻 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 20 replies
-
I have the same problem. Did you come up with a solution? |
Beta Was this translation helpful? Give feedback.
-
What I've done is to use This works, but isn't an ideal solution as it doesn't do any code splitting, so I'm on the hunt for something better too. For projects using loadable-components, I think this issue is relevant, though I'm using NextJS myself. For NextJS, I think this is solved with a Fetch-based solution (accessible via paid workshop). |
Beta Was this translation helpful? Give feedback.
-
Key here is you need to flush the chunks out or include them. How I do it is I expose a module at the end of the cycle that adds all the chunk mappings for my remotes. So when I load a federated module, it can look up the styles that should be SSRd as well. I'd be happy to work with someone on this, like I've solved this directly built into next.js, I know what to do more or less, but don't have the time or resources to "just whip one out" - timeframe wise, with some help this could be solved in a few days. So if someone wants to help, I can write out most the hooks or basic boilerplate with some references to other plugins where I'm doing the same exact thing. |
Beta Was this translation helpful? Give feedback.
-
Is there a recommended way to bring styles (Tailwind) from a remote app (external UI package library) into a host app using NextJS? The only way I can get styles working between the two is by modifying the tailwind config to read the whole repo. This feels like quite a hacky method to bring in styles from one place to another. |
Beta Was this translation helpful? Give feedback.
We successfully used https://twind.style/ + Next.js. It requires fewer changes and is more or less predictable/stable
We had light/dark theme + accent colors so far, so good