fix(sourcemap): skip URL source roots when injecting sources content - #23519
Merged
Merged
Conversation
murugu-21
force-pushed
the
fix/url-source-root
branch
from
September 18, 2026 12:03
28acc37 to
50fdd34
Compare
A URL sourceRoot cannot be realpath'd, so the relative sources were resolved against the cwd and flagged as escaping the package. Remote sources have no local file to inject; leave the map untouched.
murugu-21
force-pushed
the
fix/url-source-root
branch
from
September 18, 2026 12:34
50fdd34 to
3e731bb
Compare
btea
previously approved these changes
Sep 18, 2026
Contributor
Author
|
@btea this is my first pr in Vite and I don't have merge access, can u help me request the right maintainer to review and merge this pr? Thanks! |
Contributor
|
Don't worry, we still need to wait for the review from others. |
sapphi-red
approved these changes
Sep 24, 2026
sapphi-red
left a comment
Member
There was a problem hiding this comment.
LGTM. I've also added the handling for sources field
This was referenced Sep 24, 2026
Merged
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.
What
Fixes #23518.
injectSourcesContentmisreads source maps whosesourceRootis a URL.computeSourceRoutetriesrealpath(path.resolve(dirname(file), map.sourceRoot)), which fails for a URL, so the root is treated as missing. The relativesourcesare then resolved withpath.resolve(sourcePath)— againstprocess.cwd()— and for a file insidenode_modulesthat lands outside its package, producing:Packages like
domutils@3andentities@4publish maps with"sourceRoot": "https://raw.githubusercontent.com/…/src/"deliberately, so devtools can fetch the original sources from the tag they were built from.webpack://roots take the same path. There is nothing local to read, and the package-boundary check is meaningless for a remote root.This skips sources-content injection for maps with an external
sourceRoot. The map is passed through unchanged, so other consumers keep resolvingsourcesagainst the remote root.Reproduction
https://github.com/murugu-21/vite-url-source-root-repro- — pure
vite(createServer+ssrLoadModulewithssr.noExternal), no test runner:git clone https://github.com/murugu-21/vite-url-source-root-repro-.git cd vite-url-source-root-repro- npm install npm run reproTests
Two cases added to
packages/vite/src/node/server/__tests__/sourcemap.spec.ts:sourceRootis left untouched and does not warn;pnpm vitest run packages/vite/src/node/server/__tests__/sourcemap.spec.tspasses (11 passed, 2 Windows-only skipped). The first case fails without the change.