styled-components: SSR duplicates stylesheets on refresh
Environment
System:
- OS: macOS High Sierra 10.13.6
- CPU: x64 Intel® Core™ i5-7360U CPU @ 2.30GHz
- Memory: 111.95 MB / 8.00 GB
- Shell: 3.2.57 - /bin/bash
Binaries:
- Node: 9.10.1 - /usr/local/bin/node
- Yarn: 1.6.0 - /usr/local/bin/yarn
- npm: 6.1.0 - /usr/local/bin/npm
- Watchman: 4.9.0 - /usr/local/bin/watchman
npmPackages:
- babel-plugin-styled-components: ^1.5.1 => 1.5.1
- styled-components: 3.4.1 => 3.4.1
Reproduction
I cloned the official example of styled-components with NextJS: https://github.com/zeit/next.js/tree/master/examples/with-styled-components
It works as expected with initial version ^2.1.0. It works as expected with version 3.3.3. It does not work as expected with 3.4.0 and 3.4.1
Using different versions of NextJS or the Babel plugin did not impact the behavior.
Steps to reproduce
Run npm run dev, view page source and hit refresh with >= 3.4.0.
Expected Behavior
The created stylesheet exists once.
Actual Behavior
The created stylesheet gets duplicated with every browser refresh. ~It does not occur after a hot reload.~ It also happens in production mode. See comment by @elgubbo
~It’s by no means a show blocker, since you usually don’t refresh when using HMR, but~ I think it still might be a bug. As far as I saw in the NextJS repo this occured as well before styled-components SSR was stable at some point. If you’d like me to try to isolate the problem out of NextJS, shout. Thank you!
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (6 by maintainers)
If it helps, here’s how to re-create it using buildkite/site:
You can see the ever-growing style block:
vs doing the same, but on v3.3.3:
Having a quick look, they grow like this:
I don’t think we’re experiencing any problems on 3.3.3 — after reverting back (buildkite/site#173) https://buildkite.com/home is looking 👌🏼 again.
Second this - I’ve downgraded to
2.4.1which is working okay - I’ll do some more digging!Edit Downgrading to
3.3.3works for me too 💯same thing is happening here, even in production mode - meaning over time our document size grows very very large - will downgrade to 3.3.3 for now.
In production mode we use an alternate injection process that devtools doesn’t show yet for some reason. The styles are there though, just in the style sheet object model not in the DOM On Mon, Aug 6, 2018 at 5:27 AM Joseph Luck notifications@github.com wrote:
I can not confirm that it occurs on 3.3.3 as well.
Both running via Next and static export behave as expected. @elgubbo May I ask if you are absolutely sure that you downgraded properly?