File tree Expand file tree Collapse file tree 4 files changed +20
-9
lines changed
react-devtools-extensions/src/main
react-devtools-shared/src Expand file tree Collapse file tree 4 files changed +20
-9
lines changed Original file line number Diff line number Diff line change 11/* global chrome */
22
3- import { normalizeUrl } from 'react-devtools-shared/src/utils' ;
3+ import { normalizeUrlIfValid } from 'react-devtools-shared/src/utils' ;
44import { __DEBUG__ } from 'react-devtools-shared/src/constants' ;
55
66let debugIDCounter = 0 ;
@@ -117,7 +117,7 @@ async function fetchFileWithCaching(url: string): Promise<string> {
117117 chrome . devtools . inspectedWindow . getResources ( r => resolve ( r ) ) ,
118118 ) ;
119119
120- const normalizedReferenceURL = normalizeUrl ( url ) ;
120+ const normalizedReferenceURL = normalizeUrlIfValid ( url ) ;
121121 const resource = resources . find ( r => r . url === normalizedReferenceURL ) ;
122122
123123 if ( resource != null ) {
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {
1616 LOCAL_STORAGE_TRACE_UPDATES_ENABLED_KEY ,
1717} from 'react-devtools-shared/src/constants' ;
1818import { logEvent } from 'react-devtools-shared/src/Logger' ;
19+ import { normalizeUrlIfValid } from 'react-devtools-shared/src/utils' ;
1920
2021import {
2122 setBrowserSelectionFromReact ,
@@ -128,7 +129,11 @@ function createBridgeAndStore() {
128129 : source ;
129130
130131 // We use 1-based line and column, Chrome expects them 0-based.
131- chrome . devtools . panels . openResource ( sourceURL , line - 1 , column - 1 ) ;
132+ chrome . devtools . panels . openResource (
133+ normalizeUrlIfValid ( sourceURL ) ,
134+ line - 1 ,
135+ column - 1 ,
136+ ) ;
132137 } ;
133138
134139 // TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration.
Original file line number Diff line number Diff line change 77 * @flow
88 */
99
10- import { normalizeUrl } from 'react-devtools-shared/src/utils' ;
1110import SourceMapConsumer from 'react-devtools-shared/src/hooks/SourceMapConsumer' ;
1211
1312import type { Source } from 'react-devtools-shared/src/shared/types' ;
@@ -91,9 +90,8 @@ export async function symbolicateSource(
9190 try {
9291 // sourceMapURL = https://react.dev/script.js.map
9392 void new URL ( possiblyURL ) ; // test if it is a valid URL
94- const normalizedURL = normalizeUrl ( possiblyURL ) ;
9593
96- return { sourceURL : normalizedURL , line, column} ;
94+ return { sourceURL : possiblyURL , line, column} ;
9795 } catch ( e ) {
9896 // This is not valid URL
9997 if (
Original file line number Diff line number Diff line change @@ -996,9 +996,17 @@ export function backendToFrontendSerializedElementMapper(
996996 } ;
997997}
998998
999- // Chrome normalizes urls like webpack-internals:// but new URL don't, so cannot use new URL here.
1000- export function normalizeUrl ( url : string ) : string {
1001- return url . replace ( '/./' , '/' ) ;
999+ /**
1000+ * Should be used when treating url as a Chrome Resource URL.
1001+ */
1002+ export function normalizeUrlIfValid ( url : string ) : string {
1003+ try {
1004+ // TODO: Chrome will use the basepath to create a Resource URL.
1005+ return new URL ( url ) . toString ( ) ;
1006+ } catch {
1007+ // Giving up if it's not a valid URL without basepath
1008+ return url ;
1009+ }
10021010}
10031011
10041012export function getIsReloadAndProfileSupported ( ) : boolean {
You can’t perform that action at this time.
0 commit comments