You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 209317c
Browse filesBrowse the repository at this point in the historyBrowse files
* docs: payload dedup, precedence reasons, edge runtime, and lightweight-package bar
Corrects the Float claims in rsc-style-injection.md (plain styles keep
their attributes everywhere; precedence fails by bucket order, permanence,
attribute loss and position), specifies one shared style element per key
for the server-component payload, records why there is no exports map and
why edge server rendering is unsupported, and fixes the FAQ's advice for
long server-rendered lists.
* perf(rsc): share one style element across identical global style instances
* perf(rsc): share one style element across styled component instances with identical classes
* feat: clear errors when the browser build loads in an edge-runtime server render
* docs: correct the createGlobalStyle server-detection comment
* docs: add changeset for the edge runtime error
* perf(rsc): wrap the shared global style element in an array so the payload references it whole
* docs: record the class-string key and array-wrapped globals; drop guard byte counts
* docs: key styled-component elements on component ID plus classes; correct the styleSheet.server rationale
* fix(rsc): key the shared style element on component ID plus classes
An extension with no CSS of its own returns exactly its base's class
string, but its CSS wraps the base in :where() and its React key
differs, so whichever rendered first handed the other the wrong
element.
* refactor(rsc): build the style CSS in a module-level function
The hook body now asks buildRSCStyleCSS for the combined CSS and creates
the shared element only when it is non-empty. The comments describe the
element sharing instead of reading as no dedup.
* fix(rsc): point edge-runtime errors at the server build and correct the guard comments
Errors 19 and 20 now also cover a server bundle that resolves the
browser build. The edge tests assert against the generated error map.
The redundant-emit warning names its count without 'Over', since it
fires at exactly the threshold.
* test(rsc): read shared style elements without spying on createElement
The payload-dedup tests call the component's render function directly,
fold the namespace and stylisPlugins cases into one table, fold the
fixed-key checks into the distinct-element tests, and drop the
duplicated tag count and the any casts. The empty-leaf interpolation
case keeps its single-line template so the leaf earns no class of its own.
* style: wrap the edge guard comment
* docs: drop the agent rule against starting dev servers
* docs: note that the sandbox loads the built dist
Rendering styled-components on the server with the edge runtime (for example `export const runtime = 'edge'` in a Next.js route) now fails with a clear message that names the fix: use the Node.js runtime for routes that render styled-components. Previously the same setup ended in an obscure crash, either at `next build` or on the first request.
Copy file name to clipboardExpand all lines: .changeset/rsc-suspense-style-removal.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,4 +4,4 @@
4
4
5
5
Fixed styles disappearing from a server-rendered component when it is revealed from behind a React `<Suspense>` boundary, such as a streaming Next.js route (including `cacheComponents`). A component shown first in a Suspense fallback and then in the resolved content kept its class name but lost its CSS, because the rule had been emitted only inside the fallback that React discards on reveal.
6
6
7
-
Each server-rendered instance now carries its own inline `<style>`, so its styles always travel with it and survive the boundary. Nearby duplicates still compress away almost for free under gzip, but gzip can only look back about 32 KB, so once repeats are farther apart on the page each one costs roughly its own compressed size; brotli's much larger window keeps it cheap regardless of distance. Only a very large repeated list (thousands of instances of one component on a single page) is worth collapsing into a shared class, and a development-only warning points that out if it happens.
7
+
Each server-rendered instance now carries its own inline `<style>`, so its styles always travel with it and survive the boundary. The data React sends for server components includes each distinct style once on React 19, however many instances repeat it. In the HTML, nearby duplicates compress away almost for free under gzip, but gzip can only look back about 32 KB, so once repeats are farther apart on the page each one costs roughly its own compressed size; brotli's much larger window keeps it cheap regardless of distance. Only a very large repeated list (thousands of instances of one component on a single page) is worth restyling from a single parent element, and a development-only warning points that out if it happens.
Copy file name to clipboardExpand all lines: packages/styled-components/docs/faq.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,6 +74,29 @@ The registry collects styles from client components during SSR so pages are full
74
74
75
75
- React 16.8+ for client components
76
76
- React 19+ for RSC
77
+
- The Node.js runtime for any route that renders styled-components on the server. The edge runtime (`export const runtime = 'edge'`) is not supported; remove that line, or set it to `'nodejs'`
78
+
79
+
**Why is there a `<style>` tag before every server-rendered element?**
80
+
81
+
Each server component instance carries its own copy of its styles, so the styles survive React swapping a loading fallback for the finished content. The repeated tags cost little: the browser handles them quickly, compression shrinks identical copies to almost nothing, and the data React sends for server components includes each distinct style once. For a very long list, style the items from one styled parent so the whole list emits a single tag:
82
+
83
+
```tsx
84
+
const Slides =styled.ul`
85
+
& > li {
86
+
scroll-snap-align: center;
87
+
}
88
+
`;
89
+
90
+
exportdefaultfunction Carousel({ slides }) {
91
+
return (
92
+
<Slides>
93
+
{slides.map(slide=> (
94
+
<likey={slide.id}>{slide.title}</li>
95
+
))}
96
+
</Slides>
97
+
);
98
+
}
99
+
```
77
100
78
101
**For traditional SSR (Next.js Pages Router, custom SSR):**
@@ -172,17 +177,28 @@ export default function createGlobalStyle<Props extends object>(
172
177
counts.set(styledComponentId,count);
173
178
if(count===RSC_REDUNDANT_EMIT_WARN_THRESHOLD){
174
179
console.warn(
175
-
`Over ${count} instances of the global style ${styledComponentId} were rendered on one server-rendered page, so its styles repeat that many times in the HTML.\n`+
180
+
`${count} instances of the global style ${styledComponentId} were rendered on one server-rendered page, so its styles repeat that many times in the HTML.\n`+
176
181
'A global style is normally mounted once, at the root of the app. Move it higher in the tree so it renders only once per page.'
0 commit comments