Repository navigation
WIP: Fix: SSR doesn't include styles - #3061
StevenLangbroek wants to merge 2 commits into
Conversation
|
I've eliminated some suspects in the reproduction:
Since the tests in |
|
Test output in reproduction repo: <style data-styled="true" data-styled-version="5.0.1"></style>
<div class="Home__Wrapper-okpba1-0 ivJaOt">
<div>
<img src="react.svg" alt="logo" />
<h2>Welcome to Razzle</h2>
</div>
<p>To get started, edit <code>src/App.js</code> or
<!-- --> <code>src/Home.js</code> and save to reload.</p>
<ul>
<li><a href="https://github.com/jaredpalmer/razzle" class="Home__Anchor-okpba1-1 bsrTZk">Docs</a>
</li>
<li><a href="https://github.com/jaredpalmer/razzle/issues" class="Home__Anchor-okpba1-1 bsrTZk">Issues</a>
</li>
<li><a href="https://palmer.chat" class="Home__Anchor-okpba1-1 bsrTZk">Community Slack</a>
</li>
</ul>
</div>Test code: import React from "react";
import { renderToNodeStream } from "react-dom/server";
import { ServerStyleSheet } from "styled-components";
import ofStream from "stream-to-promise";
import Home from "./Home";
import beautify from "beautify";
describe("Style Hydration", () => {
it("should include styles", () => {
const sheet = new ServerStyleSheet();
const render$ = renderToNodeStream(<Home />);
const style$ = sheet.interleaveWithNodeStream(render$);
return ofStream(style$)
.then(b => b.toString())
.then(received => {
console.log(beautify(received, { format: "html" }));
});
});
});Run tests with |
|
Tried |
|
Ruled out |
|
Are you using yarn? One thing I’d do to rule out a whole class of issues is
set up a resolutions package.json entry for styled components and rerun
install
…On Thu, Mar 12, 2020 at 12:19 PM Steven Langbroek ***@***.***> wrote:
So _emitSheet's output is an empty style tag. I took a look and added
console statements to outputSheet, which leads me to this suspect output:
[image: image]
<https://user-images.githubusercontent.com/296796/76542529-e5503400-6463-11ea-81b2-ce2990a6feaf.png>
I'll keep digging unless anyone can point me in a specific direction for a
potential culprit.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#3061 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAELFVQLMBO2EZQAONUA763RHEDR7ANCNFSM4LGMRF6Q>
.
|
|
This is all in the |
|
Gotcha, sorry continue! It might have to do with the SERVER replacement token in our rollup config. Though I’d think the cjs and esm versions would work the same |
|
Yeah I tried all bundles, behavior is the same everywhere. Digging through the codebase now to remove it everywhere and see if that fixes things... |
|
Removing the |
|
In the built version, there are 0 rules, compared to 2 when running against dev: (see #3061 (comment)) |
|
Ok, I'm now in |
|
Alright; let’s jump in this tomorrow and I’ll take a look in the meantime and will verify that it’s not just a small mistake somewhere 😅 |
|
Thanks @kitten 🙇. |
|
Any movement on this guys? |
|
holy shit I had lost track of this entirely (sorry, zombie apocalypse etc). I'll pick this back up tomorrow. @kitten gave me a good walkthrough of the serverstylesheet and the gnarly array-like stuff going on there, I'm gonna dig into it further. |
|
I see the same issue when building with V5.x.x, When loading the page, the css is not entirely present and then is hydrated. I think that could be related to this PR. I'm using Nextjs 9.3.4. It's really visible so I'm going to publish a version if it can help. |
|
This is WIP, I'm gonna pick it up again as soon as I can. |
|
@StevenLangbroek Is there anything I can help with and have you had any epiphanies on this? From what I've read in here so far, it sounds like you've narrowed it down to a build issue? |
|
@tim-soft wow sorry, I really dropped the ball on this one. I had time off to spend digging into it, but am employed again so it kind of fell by the wayside. @kitten gave me an intro to how the Uint8Arrays work and the ID assignment, but I wasn't really closer to finding the root cause. There's a failing test and a repro, if you want to take a look that'd be great. I'll be back at it over the weekend, if there's anything I can do to help please ping me. |
| import stylisRTLPlugin from 'stylis-plugin-rtl'; | ||
| import ServerStyleSheet from '../models/ServerStyleSheet'; | ||
| import ofStream from 'stream-to-promise'; | ||
| import { ServerStyleSheet } from '../../dist/styled-components.esm'; |
There was a problem hiding this comment.
I’m actually not sure anymore whether this is a valid reproduction. But it could also hint at the root cause.
This bundle includes the global GroupIDAllocator, but the styled function that’s used in this test is imported separately by Jest:
So none of the group IDs are carried over and will match 🤔
There was a problem hiding this comment.
Yeah that makes sense. I'm still curious why my repro behaves the way it does then...
|
@tim-soft ok, I'm not able to continue work on this :(. If you want we can jump on a call and I can walk you through how we noticed this bug, what I did to investigate and the current status. |




Note: this is extremely early, I'm opening the PR to work out in the open and leave some documentation with regards to how to debug & fix these kind of issues.
Todo
Resolves #2962
The problem appears only in the built version of
sc, if you want I can duplicate the ssr test suite but run it against built version as a separate step to prevent this in the future. Thoughts? /cc @kitten @probablyupResult so far
I've narrowed the problem down to this:
If I run the tests as normal, the
DefaultGroupedTagcontains a normal amount ofrules(found by loggingtaginoutputSheet). If I buildsc, and point theServerStyleSheetimport at the built assets (as this branch does now), therulesarray is empty however. My best guess is the bug is somewhere ininsertRulesonDefaultGroupedTagorinsertRuleon the underlyingTag.Development:

Production:
