Here's how im thinking to solve rendering the minimal amount of CSS on the server while also not blowing out the bundle size 👇
1
3
1. Context on the server. It's the only solution because of async ssr. Singleton won't work like I thought it could before (and tbh the api was yuck, having a flush func to call after SSR? Gross!)
Each compiled component needs to both be a context provider and consumer.
2
I assumed there needs to be a provider *somewhere* above any compiled component, but not necessarily wrapping every compiled component. What am I missing?
1
1
that's why (on the server) every compiled component will be BOTH a provider AND a consumer
it keeps it 0 config - so you as a consumer don't have to worry about it
1
so the top most compiled component will be the one to create the actual data - and then every child will read from it
2
One thing that caught me out with using emotion is rendering content into an iframe (this story wasn't well supported until emotion 10). I would imagine this use case would be harder to support without using context.
2
As an example use case, I render a "component playground" into an iframe on our design system doc-site. It's used to sandbox styles from the main page.
1
1
yeah true so any storybook basically.
its still isolated though right? the iframe is rendering itself - not the parent dipping into the iframe?
1
oh fascinating. want to make an issue and i'll make sure it works as expected github.com/atlassian-labs/co…
bonus points for an example codesandbox i can test against later (just use emotion or something)
Apr 20, 2020 · 1:34 AM UTC
Sure thing, I will do, and thanks!
It's a pretty handy use case, gives you all the benefits of sandboxed code, but with the simplicity of being authored in a single React tree.
There's a emotion based example the emotion folks put together here:
stackoverflow.com/a/59141668
1
1

