File size: 2,197 Bytes
94786da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
diff --git a/packages/next/src/client/components/segment-cache/navigation-testing-lock.ts b/packages/next/src/client/components/segment-cache/navigation-testing-lock.ts
index 6153b44e0628514eb9a96896641264066ca3f9f2..ed07e3cfb7d7d978e32660d926cee377f7459f7e 100644
--- a/packages/next/src/client/components/segment-cache/navigation-testing-lock.ts
+++ b/packages/next/src/client/components/segment-cache/navigation-testing-lock.ts
@@ -364,6 +364,32 @@ export function resetNavigationLockToPending(): void {
   writeCookieValue([0, `c${Math.random()}`])
 }
 
+/**
+ * Returns true if the request targets a dev-server endpoint — one of the
+ * hot-reloader middleware routes (error overlay, source maps, launch-editor,
+ * devtools). They all share the `/__nextjs_` path prefix and are always
+ * requested root-relative on the same origin.
+ */
+function isDevServerRequest(input: RequestInfo | URL): boolean {
+  let url: URL
+  try {
+    url = new URL(
+      typeof input === 'string'
+        ? input
+        : input instanceof URL
+          ? input
+          : input.url,
+      window.location.href
+    )
+  } catch {
+    return false
+  }
+  return (
+    url.origin === window.location.origin &&
+    url.pathname.startsWith('/__nextjs_')
+  )
+}
+
 /**
  * Global fetch override
  *
@@ -386,6 +412,15 @@ function globalFetchOverride(
     // scope and invoked it after release.
     return fetch(input, init)
   }
+  if (process.env.__NEXT_DEV_SERVER && isDevServerRequest(input)) {
+    // Dev-server requests must not be gated on the testing lock — blocking
+    // them would break the error overlay, source maps, and devtools for the
+    // whole scope. Dispatch immediately through the pre-lock fetch. Copy to a
+    // local so the call doesn't bind `this` to the lock state object (native
+    // fetch throws "Illegal invocation" for a foreign receiver).
+    const preLockFetch = lockState.fetch
+    return preLockFetch(input, init)
+  }
   // Block user-initiated fetches until the lock is released, then dispatch
   // through the fetch captured at acquire time. Reading from `lockState`
   // (rather than `window.fetch`) pins to the capture even if `window.fetch`