fix(sourcemap): skip URL source roots when injecting sources content - #23516
Closed
murugappan-medme-1 wants to merge 1 commit into
Closed
murugappan-medme-1 wants to merge 1 commit into
murugappan-medme-1 wants to merge 1 commit into
Conversation
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.
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
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
Load any package that still ships a URL
sourceRootthrough Vite or Vitest — for exampledomutils@3.2.2, which old majors ofhtmlparser2/linkedomstill depend on — and the warning above appears even though nothing is wrong with the package.fb55/domutils#2196andfb55/entities#2084are the package-side reports; their new majors shipsrc/instead, but the old majors are still installed transitively across the ecosystem.Tests
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.