Repository navigation
feat(rsc): add configureServerStyles to set plugins for every server component - #5865
Conversation
🦋 Changeset detectedLatest commit: 2e2bce2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
ℹ️ Minor suggestions only.
Reviewed changes
configureServerStyles— new process-wide plugin configuration for server components, held onglobalThisunder a major-versionedSymbol.forkey, read throughserverDefaults(), with a development-only browser warning.- Manager inheritance — a server
StyleSheetManagerstarts from the configured plugins, replaces them with its ownstylisPlugins, andstylisPlugins={[]}drops them, including the override-clear comparison moving frommainStylisto the server default. stylisPluginRSCname —Object.definePropertybecomes an annotated initializer, so the pure annotation only drops it together with the plugin.- Tests — RSC matrix (manager combinations,
[]scoped per request, separate library copy, reconfiguration, unnamed plugin on every request,StyleSheetConsumer), the one-time browser warning, and a production webpack bundle asserting the plugin name. - Docs / changesets / sandbox — README section,
docs/rsc-style-injection.mdsubsection, plugin JSDoc, two changesets, and the sandbox moved from a/rsclayout manager to a root-layout call.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
docs/rsc-style-injection.mdplacement — the### configureServerStylessubsection now sits below the manager section's trailingnonceparagraph, sononcekeeps reading as part of theStyleSheetManageroverride rather than the new API.- Docs list formatting — that subsection's bullets are hard-wrapped and period-terminated, matching the file's convention, and the slot paragraph points page-wide plugins at the new section.
The one prior minor finding is addressed, and the commit since the last review changes documentation only.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
c43adbf to
2e2bce2
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Re-review of the two commits after the branch was rebased onto 6.x, which brought the per-request StyleSheetManager slot into the base.
- Configured defaults feed the slot —
serverDefaults()now backs the slot-empty read paths, so a server component whose layout did not render in that request still sees the plugins set byconfigureServerStyles. - Override-clear comparison — the manager compares its resolved stylis instance against the server default rather than the plugin-free one, so
stylisPlugins={[]}keeps writing an override under a configured default. The existing[], replace, and replace-then-reconfigure tests still pass unchanged. - Docs — the
stylisPlugins={[]}paragraph now matches the base's behavior (falling back to a plugin-free instance that keepsnamespace/enableVendorPrefixes), and theconfigureServerStylessection is unchanged.
I ran the RSC and manager suites after the rebase (122 tests, green) and probed the combinations the base change made newly reachable: [] plus a namespace under a configured default, a nested manager inheriting a parent [] override, a manager repeating the configured array identity, and a configuration call made after a component was defined. All behaved as the docs describe.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Plugins set with a
StyleSheetManagerin a shared Next.js layout miss pages reached by client-side navigation, because Next doesn't re-render that layout on the way to the new page. A page can look right on a direct load and lose its plugin output after navigating to it (#5838). This adds a way to set plugins that doesn't depend on what rendered first.What changes
configureServerStylessets the plugins every server component is styled with, for the whole server process:It reaches every server-rendered page and nested layout, including prerendered pages and pages reached by client-side navigation.
A
StyleSheetManagerin a server component starts from these plugins. ItsstylisPluginsprop replaces them, andstylisPlugins={[]}drops them. A manager with no configured plugins behaves as it did.It applies to server components only. Client components take their plugins from a
StyleSheetManagerrendered on the client, and callingconfigureServerStylesin the browser does nothing apart from a development warning.Also fixed
stylisPluginRSClost its name in production bundles. Together with the unreleased plugin name check, that failed production Next.js builds that use it. This should land before the next 6.x release.Cost
Bundle size, gzip -9 bytes:
The browser bundles grow by the function's warning and export; none of the server code reaches them.
Server component render time with nothing configured, from the repo's RSC benchmark: median of 6 rounds on the same machine, run from source, with the build-time server flag read once at load to approximate the published bundle, where it is a constant:
That is about 30 to 50 ns per styled component, near the limit of what this benchmark resolves (repeat runs of one tree vary by up to 4%). It pays for reading the configuration on each render, so that a call from another copy of the library in the same process takes effect.
Testing