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 f17f6c0
Browse filesBrowse the repository at this point in the historyBrowse files
`configureServerStyles({ stylisPlugins })` sets the plugins every server component is styled with, for the whole server process. Call it once, at the top level of a module every server render loads first. In Next.js that's the root layout file:
exportdefaultfunction RootLayout({ children }: { children:React.ReactNode }) {
14
+
// ...
15
+
}
16
+
```
17
+
18
+
It reaches every server-rendered page and nested layout, including pages prerendered at build time and pages reached by client-side navigation, which a `StyleSheetManager` in a shared layout does not reach. A `StyleSheetManager` in a server component starts from these plugins; its own `stylisPlugins` prop replaces them, and `stylisPlugins={[]}` drops them.
19
+
20
+
It applies to server components only. Client components take their plugins from a `StyleSheetManager` rendered on the client, such as the one in your style registry. Make one call per app: a later call replaces an earlier one and applies to renders that start after it.
`stylisPluginRSC` keeps its name through a production bundle, so its class names match in development and production and it passes the plugin name check.
Copy file name to clipboardExpand all lines: packages/styled-components/README.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -188,6 +188,23 @@ const Card = styled.div`
188
188
</ThemeProvider>
189
189
```
190
190
191
+
### Plugins in server components
192
+
193
+
A `StyleSheetManager` in a server component applies to what renders after it in the same request, and Next.js does not re-render a shared layout on a client-side navigation. To give every server component the same plugins, call `configureServerStyles` once, at the top level of the root layout file:
exportdefaultfunction RootLayout({ children }: { children:React.ReactNode }) {
202
+
// ...
203
+
}
204
+
```
205
+
206
+
The call is a plain statement, not a component, so it reaches every page, nested layout, and client-side navigation, including pages prerendered at build time. Make one call per app. A `StyleSheetManager` in a server component starts from these plugins; `stylisPlugins={[]}` drops them. Client components take their plugins from a `StyleSheetManager` rendered on the client.
207
+
191
208
### Shared styles with `css`
192
209
193
210
Extract reusable style blocks to share across components or apply conditionally.
0 commit comments