mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
[devtools] Fix "View source" for sources with URLs that aren't normalized (#32951)
This commit is contained in:
parent
ce578f9c59
commit
bc6184dd99
|
|
@ -1,6 +1,6 @@
|
||||||
/* global chrome */
|
/* global chrome */
|
||||||
|
|
||||||
import {normalizeUrl} from 'react-devtools-shared/src/utils';
|
import {normalizeUrlIfValid} from 'react-devtools-shared/src/utils';
|
||||||
import {__DEBUG__} from 'react-devtools-shared/src/constants';
|
import {__DEBUG__} from 'react-devtools-shared/src/constants';
|
||||||
|
|
||||||
let debugIDCounter = 0;
|
let debugIDCounter = 0;
|
||||||
|
|
@ -117,7 +117,7 @@ async function fetchFileWithCaching(url: string): Promise<string> {
|
||||||
chrome.devtools.inspectedWindow.getResources(r => resolve(r)),
|
chrome.devtools.inspectedWindow.getResources(r => resolve(r)),
|
||||||
);
|
);
|
||||||
|
|
||||||
const normalizedReferenceURL = normalizeUrl(url);
|
const normalizedReferenceURL = normalizeUrlIfValid(url);
|
||||||
const resource = resources.find(r => r.url === normalizedReferenceURL);
|
const resource = resources.find(r => r.url === normalizedReferenceURL);
|
||||||
|
|
||||||
if (resource != null) {
|
if (resource != null) {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import {
|
||||||
LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY,
|
LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY,
|
||||||
} from 'react-devtools-shared/src/constants';
|
} from 'react-devtools-shared/src/constants';
|
||||||
import {logEvent} from 'react-devtools-shared/src/Logger';
|
import {logEvent} from 'react-devtools-shared/src/Logger';
|
||||||
|
import {normalizeUrlIfValid} from 'react-devtools-shared/src/utils';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
setBrowserSelectionFromReact,
|
setBrowserSelectionFromReact,
|
||||||
|
|
@ -128,7 +129,11 @@ function createBridgeAndStore() {
|
||||||
: source;
|
: source;
|
||||||
|
|
||||||
// We use 1-based line and column, Chrome expects them 0-based.
|
// We use 1-based line and column, Chrome expects them 0-based.
|
||||||
chrome.devtools.panels.openResource(sourceURL, line - 1, column - 1);
|
chrome.devtools.panels.openResource(
|
||||||
|
normalizeUrlIfValid(sourceURL),
|
||||||
|
line - 1,
|
||||||
|
column - 1,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration.
|
// TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration.
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
* @flow
|
* @flow
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {normalizeUrl} from 'react-devtools-shared/src/utils';
|
|
||||||
import SourceMapConsumer from 'react-devtools-shared/src/hooks/SourceMapConsumer';
|
import SourceMapConsumer from 'react-devtools-shared/src/hooks/SourceMapConsumer';
|
||||||
|
|
||||||
import type {Source} from 'react-devtools-shared/src/shared/types';
|
import type {Source} from 'react-devtools-shared/src/shared/types';
|
||||||
|
|
@ -91,9 +90,8 @@ export async function symbolicateSource(
|
||||||
try {
|
try {
|
||||||
// sourceMapURL = https://react.dev/script.js.map
|
// sourceMapURL = https://react.dev/script.js.map
|
||||||
void new URL(possiblyURL); // test if it is a valid URL
|
void new URL(possiblyURL); // test if it is a valid URL
|
||||||
const normalizedURL = normalizeUrl(possiblyURL);
|
|
||||||
|
|
||||||
return {sourceURL: normalizedURL, line, column};
|
return {sourceURL: possiblyURL, line, column};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// This is not valid URL
|
// This is not valid URL
|
||||||
if (
|
if (
|
||||||
|
|
|
||||||
14
packages/react-devtools-shared/src/utils.js
vendored
14
packages/react-devtools-shared/src/utils.js
vendored
|
|
@ -996,9 +996,17 @@ export function backendToFrontendSerializedElementMapper(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chrome normalizes urls like webpack-internals:// but new URL don't, so cannot use new URL here.
|
/**
|
||||||
export function normalizeUrl(url: string): string {
|
* Should be used when treating url as a Chrome Resource URL.
|
||||||
return url.replace('/./', '/');
|
*/
|
||||||
|
export function normalizeUrlIfValid(url: string): string {
|
||||||
|
try {
|
||||||
|
// TODO: Chrome will use the basepath to create a Resource URL.
|
||||||
|
return new URL(url).toString();
|
||||||
|
} catch {
|
||||||
|
// Giving up if it's not a valid URL without basepath
|
||||||
|
return url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getIsReloadAndProfileSupported(): boolean {
|
export function getIsReloadAndProfileSupported(): boolean {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user