[DevTools] Don't try to load anonymous or empty urls (#34869)
This triggers unnecessary fetches.
Sebastian Markbåge committed
Oct 16, 2025 at 10:49 UTC
7bd8716acdd9a484e81addcaa923e0a69e61d533
2 files changed
+20
-15
packages/react-devtools-shared/src/hooks/parseHookNames/loadSourceAndMetadata.js
+17
-15
@@ -475,23 +475,25 @@ function loadSourceFiles(
475
476
const fetchPromise =
477
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
+ }
485
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
+ }
493
493
- return runtimeSourceCode;
494
- });
494
+ return runtimeSourceCode;
495
+ })
496
+ : Promise.reject(new Error('Empty url')));
497
dedupedFetchPromises.set(runtimeSourceURL, fetchPromise);
498
499
setterPromises.push(
packages/react-devtools-shared/src/symbolicateSource.js
+3
@@ -52,6 +52,9 @@ export async function symbolicateSource(
52
lineNumber: number, // 1-based
53
columnNumber: number, // 1-based
54
): Promise<SourceMappedLocation | null> {
55
+ if (!sourceURL || sourceURL.startsWith('<anonymous')) {
56
+ return null;
57
+ }
58
const resource = await fetchFileWithCaching(sourceURL).catch(() => null);
59
if (resource == null) {
60
return null;