Skip to content
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

fix: path handling in react devtools #29199

Merged
merged 7 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions packages/react-devtools-shared/src/symbolicateSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ async function symbolicateSource(
resourceLine.length,
);

const sourceMap = await fetchFileWithCaching(sourceMapURL).catch(
() => null,
);
const sourceMap = await fetchFileWithCaching(
new URL(sourceMapURL, sourceURL).toString(),
).catch(() => null);
Jack-Works marked this conversation as resolved.
Show resolved Hide resolved
if (sourceMap != null) {
try {
const parsedSourceMap = JSON.parse(sourceMap);
Expand All @@ -91,22 +91,20 @@ async function symbolicateSource(
return {sourceURL: normalizedURL, line, column};
} catch (e) {
// This is not valid URL
if (possiblyURL.startsWith('/')) {
// /path or X:\\path
if (
possiblyURL.startsWith('/') ||
possiblyURL.slice(1).startsWith(':\\\\')
) {
// This is an absolute path
return {sourceURL: possiblyURL, line, column};
}

// This is a relative path
const [sourceMapAbsolutePathWithoutQueryParameters] =
sourceMapURL.split(/[?#&]/);

const absoluteSourcePath =
sourceMapAbsolutePathWithoutQueryParameters +
(sourceMapAbsolutePathWithoutQueryParameters.endsWith('/')
? ''
: '/') +
possiblyURL;

const absoluteSourcePath = new URL(
possiblyURL,
sourceMapURL,
).toString();
return {sourceURL: absoluteSourcePath, line, column};
}
} catch (e) {
Expand Down
3 changes: 1 addition & 2 deletions packages/react-devtools-shared/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,6 @@ export function backendToFrontendSerializedElementMapper(
};
}

// This is a hacky one to just support this exact case.
export function normalizeUrl(url: string): string {
return url.replace('/./', '/');
return new URL(url).toString();
Jack-Works marked this conversation as resolved.
Show resolved Hide resolved
}