-
Notifications
You must be signed in to change notification settings - Fork 48.9k
[Flight] Consistently encode sourceURLs #33731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eps1lon
wants to merge
2
commits into
facebook:main
Choose a base branch
from
eps1lon:sebbie/square-scare
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+55
−34
Conversation
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
c944cca
to
b31e714
Compare
b31e714
to
c577e78
Compare
eps1lon
commented
Jul 8, 2025
Comment on lines
-2755
to
-2761
if (filename.startsWith('/')) { | ||
// If the filename starts with `/` we assume that it is a file system file | ||
// rather than relative to the current host. Since on the server fully qualified | ||
// stack traces use the file path. | ||
// TODO: What does this look like on Windows? | ||
filename = 'file://' + filename; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The host should deal with this instead (e.g. in Node.js via url.pathToFileURL
if they need to). For CommonJS it'd be the wrong thing to do since the sourcemaps of CJS files are keyed by their file path in Node.js not their file URL.
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.
When a Server runs a Client reading from a third-party Server in the same VM, you might not want to implement
findSourceMapURL
for that Client in environments where HTTP is not available as a protocol insourceMappingURL
(e.g. Node.js).You also won't know the source map URL of a given source in Node.js. Only its payload and serializing that into
data:
URLs is too memory intensive.When you don't implement
findSourceMapURL
, React always appliedencodeURI
to the originlsourceURL
. This caused two problems:sourceURL
was already a valid URL). You can't blindly applydecodeURI
on locations in stack frames since you don't know if you're dealing with an original source URL or the source URL React encoded.findSourceMapURL
returns no source mapping URL. This breaks debuggers since the original source will be overwritten with React's fake sources ifsourceURL === encodeURI(sourceURL)
Now we always use the same mechanism to create unique source URLs:
"rsc://" environmentName "/" originalSourceURL "?" fakeFunctionIdx
environmentName
is put throughencodeURIComponent
.originalSourceURL
is put throughencodeURI
.fakeFunctionIdx
is a number with no meaning. It only exists to create unique sources.Not using
encodeURI
at all doesn't work for CommonJS wheregetScriptNameOrSourceURL
returns the script name which is a file path. If we encode that into a file URL,findSourceMap
will no longer work on the source URL from that fake script.