Skip to content

Commit 7bd8716

Browse files
authored
[DevTools] Don't try to load anonymous or empty urls (#34869)
This triggers unnecessary fetches.
1 parent 7385d1f commit 7bd8716

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

packages/react-devtools-shared/src/hooks/parseHookNames/loadSourceAndMetadata.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -475,23 +475,25 @@ function loadSourceFiles(
475475

476476
const fetchPromise =
477477
dedupedFetchPromises.get(runtimeSourceURL) ||
478-
fetchFileFunction(runtimeSourceURL).then(runtimeSourceCode => {
479-
// TODO (named hooks) Re-think this; the main case where it matters is when there's no source-maps,
480-
// because then we need to parse the full source file as an AST.
481-
if (runtimeSourceCode.length > MAX_SOURCE_LENGTH) {
482-
throw Error('Source code too large to parse');
483-
}
478+
(runtimeSourceURL && !runtimeSourceURL.startsWith('<anonymous')
479+
? fetchFileFunction(runtimeSourceURL).then(runtimeSourceCode => {
480+
// TODO (named hooks) Re-think this; the main case where it matters is when there's no source-maps,
481+
// because then we need to parse the full source file as an AST.
482+
if (runtimeSourceCode.length > MAX_SOURCE_LENGTH) {
483+
throw Error('Source code too large to parse');
484+
}
484485

485-
if (__DEBUG__) {
486-
console.groupCollapsed(
487-
`loadSourceFiles() runtimeSourceURL "${runtimeSourceURL}"`,
488-
);
489-
console.log(runtimeSourceCode);
490-
console.groupEnd();
491-
}
486+
if (__DEBUG__) {
487+
console.groupCollapsed(
488+
`loadSourceFiles() runtimeSourceURL "${runtimeSourceURL}"`,
489+
);
490+
console.log(runtimeSourceCode);
491+
console.groupEnd();
492+
}
492493

493-
return runtimeSourceCode;
494-
});
494+
return runtimeSourceCode;
495+
})
496+
: Promise.reject(new Error('Empty url')));
495497
dedupedFetchPromises.set(runtimeSourceURL, fetchPromise);
496498

497499
setterPromises.push(

packages/react-devtools-shared/src/symbolicateSource.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export async function symbolicateSource(
5252
lineNumber: number, // 1-based
5353
columnNumber: number, // 1-based
5454
): Promise<SourceMappedLocation | null> {
55+
if (!sourceURL || sourceURL.startsWith('<anonymous')) {
56+
return null;
57+
}
5558
const resource = await fetchFileWithCaching(sourceURL).catch(() => null);
5659
if (resource == null) {
5760
return null;

0 commit comments

Comments
 (0)