Repository navigation
Rework stylesheet for ssr - #679
Conversation
Conflicts: src/test/basic.test.js
…e BrowserStyleSheet
Conflicts: src/constructors/keyframes.js src/models/ComponentStyle.js src/models/test/ThemeProvider.test.js src/test/extending.test.js src/vendor/glamor/hash.js
…till using hashes as a cache
…ed until something has to change
| clones.delete(this.instance) | ||
| this.closed = true | ||
| if (!this.closed) { | ||
| clones.splice(clones.indexOf(this.instance), 1) |
Why is that? Just the public API? |
Generated by 🚫 dangerJS |
|
Thanks for your help! I've tweaked a bunch of things, changed up the Context key, exported StyleSheetManager. I'm gonna merge this and cut a new v2 release. |
|
Before you cut a new release, this will break a lot of folks. We should add documentation. |
|
It... shouldn't break anything except users of the current SSR API, right? |
|
@mxstbr @philpl just deployed this to https://frontend.center. I'm using react-snapshot so not actually hitting the SSR api yet but I'm getting server-rendered styles with full rehydration 👌 |
Yeah but people are using that and they'll be pissed if we don't at least tell them what the new API is! |
|
@geelen Specifically, the API in next.js doesn't let you wrap another provider around the app. Or at least I haven't figured out how to do it in a nice way. |
|
@geelen Any chance of getting all the styles as a component as well as text? Wouldn't that make it possible to avoid |
|
react-helmet for instance has both toString() and toComponent() for similar reasons. |
|
Proof of concept: oscar-b@3ba3a36 I don't know Flow enough to do it properly, and there are no tests. It works for both global and local styles, by just doing |
|
Have these changes made it into a release on npm yet? |
|
Sorry I got stuck on something and haven't pushed it. Gimme a sec! |
|
I just ran into an edge-case with the previous API which I couldn't get past even after updating to RC. The project in question is a Lerna project with common components extracted into a
This is caused by Is there a way to explicitly provide |
|
I'm migrating to styled-components v2 for a couple of our sites and I'm getting the same warning as @simenbrekken. We also have common components extracted out into a a couple of packages. Is there any resolution or workaround for this? |
|
I'm also experiencing this context type warning issue. Anyone have any further insights on this? |
So, this is the all-singing, all-dancing StyleSheet to end all stylesheets. So far I have rehydration working, as well as deterministic local & global stylesheets. The serialised format looks like this:
What this lets us do is figure out that there have been two
injectGlobalcalls and two StyledComponents generated. When theBrowserStyleSheetis created, it reads anything in the DOM with adata-styled-componentsattribute and builds up a picture of the existing styles.In the above case, that means four componentIds
sc-global-1455077013,sc-global-557410406,ONEandTWO. It also reads the classnamesgZjIaranddzbzmIso it knows not to generate those in future.What this means is that when your app boots, whether or not it's using the
no-parserstuff, it won't inject CSS into the head that it doesn't need to. But, when a dynamic style comes along, it all still works.Here's my todo list for this feature (which I'll be updating as I go):
injectAPI call as possible.StyleSheetacross<style>tag with a single text node child to a one-node-per-component so we can useappendDatato inject new CSS in the right order.hoistGonna raise this separately@importstatements to the top of style tags (pulls @import rules to the top of the stylesheet threepointone/glamor#151)injectGlobalandkeyframesfrom the singleton to each instanceLots still to do, but this feels like a really good feature to make SSR really well integrated into Styled Components. Will try to get this finished as soon as I can!