Repository navigation
fix(server-functions): ship server components' stylesheets in production - #486
Merged
Merged
Conversation
…ion (#456) The client compile replaces a 'use server' module with references, so the stylesheets it reached never joined the client graph. Dev's CSS crawl walks the SSR graph, so only production rendered server components unstyled. With components on, the client build now walks the module's imports (scripts are loaded, never imported) and imports the stylesheets it finds from the client module. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNQHxQ9311k7tQMEKs
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNQHxQ9311k7tQMEKs
🦋 Changeset detectedLatest commit: f3e568b 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 |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #456.
Problem
With
serverFunctions: { components: true }, the client compile replaces a'use server'module withcreateServerReferencestubs. Everything that module imported therefore drops out of the client graph. A stylesheet reached only through a server component got no client asset and no manifest entry, so the production document linked nothing for it and the component rendered unstyled. Frame navigation had the same problem. Dev looked right, because its CSS crawl walks the SSR graph, which hid the bug.Change
In a client build with
componentson,transformModulenow collects the stylesheets a'use server'module reaches and appends side-effect imports for them to the client stub. The new helper issrc/server-functions/server-styles.ts:this.parse(code, { lang: 'tsx' }), skipping type-only imports, and resolved in the client environment.?url,?inlineand?rawimports are skipped.this.load(), and the walk followsimportedIds, so dependencies innode_modulesare covered too. Loading runs the module's transforms, so compile-time CSS plugins such as StyleX record their rules (the case from the issue thread). The module is never imported, so its code stays out of the client bundle.'use server'module loads as its own stub, which carries its own stylesheet imports.The stylesheets then land in the client chunk that imports the stub (the entry CSS in the example), so the SSR document links them. Dev is unchanged, since its crawl already handles this, and builds without
componentsskip the walk entirely.Tests
framesmode:src/frames/data.tsxnow rendersPanelBadge, a component imported only below the boundary, which importspanel-badge.css. A new browser check asserts that its computed color is applied.frames-prodfails the check andframes-devpasses, matching the issue.SOLID_SERVER_COMPONENTS=1build,dist/clientcontains the rule in the entry CSS, and none of the server text (SERVER-ROW-TEXT,server-styled,PanelBadge). The suite's existing secret scan also passes.vitest runpasses (71),tsc --noEmitis clean, and the full start-ssr suite passes (779/779).Generated by Claude Code