Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
094dccb2
Unverified
Commit
094dccb2
authored
Jul 20, 2026
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Jul 20, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[instant] Let dev-server requests bypass the fetch lock (#95761)
parent
163e45e4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
navigation-testing-lock.ts
...lient/components/segment-cache/navigation-testing-lock.ts
+35
-0
instant-navigation-testing-api.test.ts
...gation-testing-api/instant-navigation-testing-api.test.ts
+27
-0
No files found.
packages/next/src/client/components/segment-cache/navigation-testing-lock.ts
View file @
094dccb2
...
@@ -364,6 +364,32 @@ export function resetNavigationLockToPending(): void {
...
@@ -364,6 +364,32 @@ export function resetNavigationLockToPending(): void {
writeCookieValue([0, `
c$
{
Math
.
random
()}
`])
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
* Global fetch override
*
*
...
@@ -386,6 +412,15 @@ function globalFetchOverride(
...
@@ -386,6 +412,15 @@ function globalFetchOverride(
// scope and invoked it after release.
// scope and invoked it after release.
return fetch(input, init)
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
// Block user-initiated fetches until the lock is released, then dispatch
// through the fetch captured at acquire time. Reading from `
lockState
`
// through the fetch captured at acquire time. Reading from `
lockState
`
// (rather than `
window
.
fetch
`) pins to the capture even if `
window
.
fetch
`
// (rather than `
window
.
fetch
`) pins to the capture even if `
window
.
fetch
`
...
...
test/e2e/app-dir/instant-navigation-testing-api/instant-navigation-testing-api.test.ts
View file @
094dccb2
...
@@ -1100,6 +1100,33 @@ describe('instant-navigation-testing-api', () => {
...
@@ -1100,6 +1100,33 @@ describe('instant-navigation-testing-api', () => {
expect
(
await
fetchedData
.
textContent
()).
toContain
(
'api response'
)
expect
(
await
fetchedData
.
textContent
()).
toContain
(
'api response'
)
})
})
if
(
isNextDev
)
{
it
(
'lets dev-server requests through during instant scope'
,
async
()
=>
{
const
page
=
await
openPage
(
next
,
'/'
)
await
instant
(
page
,
async
()
=>
{
await
page
.
click
(
'#link-to-client-fetch'
)
// The out-of-band fetch to /api/data is blocked by the lock
const
loading
=
page
.
locator
(
'[data-testid="fetched-data-loading"]'
)
await
loading
.
waitFor
({
state
:
'visible'
})
// But dev-server requests (hot-reloader middleware endpoints like the
// error overlay and source maps) bypass the lock and resolve while the
// scope is still active. Without the bypass this evaluate would hang
// until the scope ends.
const
status
=
await
page
.
evaluate
(()
=>
fetch
(
'/__nextjs_server_status'
).
then
((
res
)
=>
res
.
status
)
)
expect
(
status
).
toBe
(
200
)
// The blocked fetch still hasn't resolved
const
fetchedData
=
page
.
locator
(
'[data-testid="fetched-data"]'
)
expect
(
await
fetchedData
.
count
()).
toBe
(
0
)
})
})
}
it
(
'clears cookie even when callback throws'
,
async
()
=>
{
it
(
'clears cookie even when callback throws'
,
async
()
=>
{
const
page
=
await
openPage
(
next
,
'/'
)
const
page
=
await
openPage
(
next
,
'/'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment