Repository navigation
fix(rsc): drop Server Function source from client sourcemaps - #1497
Draft
james-elicx wants to merge 2 commits into
Draft
james-elicx wants to merge 2 commits into
james-elicx wants to merge 2 commits into
Conversation
This branch has not been deployed
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.
Description
In a production build with client sourcemaps enabled (
build.sourcemap: trueor--sourcemap), the browser.js.mappublishes the full source of any"use server"module imported by a client component. That includes code paths and constants that only ever run on the server.In the browser environment,
rsc:use-serverreplaces the module withcreateServerReference()proxies, so the implementation never reaches browser JavaScript. But the proxy's transform map (output.generateMap({ hires: 'boundary' })) maps it back to the original module. The bundler then embeds that module in the chunk map'ssourcesContent.This PR returns
{ mappings: '' }for the proxy in browser builds. Dev builds and the SSR environment keepgenerateMap(...), so dev source locations (findSourceMapURL) are unaffected. This matches Next.js, which drops the original spans when compiling server actions for the client layer in production but keeps them in development and server builds (theis_react_server_layer || is_developmentchecks incrates/next-custom-transforms/src/transforms/server_actions.rs, from vercel/next.js#76157). Next.js's matching e2e test is "should not expose action content in sourcemaps" intest/e2e/app-dir/actions/app-action.test.ts.Draft: blocked on Rolldown
The new e2e test (
source map buildine2e/source-map.test.ts) buildsexamples/source-mapwith--sourcemap. It then checks that no client map carries a"use server"module's source, while the client component importing the action keeps its own.Rollup documents
map: { mappings: '' }as the way to return a transform with no sourcemap. It buildssourcesandsourcesContentonly from files that traced mappings reach, so the module drops out. Rolldown doesn't support that yet:normalize_transform_sourcemapfills an empty map'ssourcesandsourcesContentwith the module id and its pre-transform code.collapse_sourcemapscopiessourcesandsourcesContentwholesale from the first map in the chain, whether or not any mapping reaches them. So an earlier transform's map (for example TypeScript stripping) keeps the original even when a later transform returns{ mappings: '' }or no map.Feature request on Rolldown: rolldown/rolldown#11176
I'll mark this ready once Rolldown supports it. The Vite 7 CI job should already pass with this change.