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
799f784c
Unverified
Commit
799f784c
authored
Mar 02, 2026
by
Tim Neutkens
Committed by
GitHub
Mar 02, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Skip writeToBfCache without window (#90771)
## What? Skip bfcache handling server-side.
parent
75988e43
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
3 deletions
+24
-3
bfcache.ts
packages/next/src/client/components/segment-cache/bfcache.ts
+13
-0
use-action-queue.ts
packages/next/src/client/components/use-action-queue.ts
+11
-3
No files found.
packages/next/src/client/components/segment-cache/bfcache.ts
View file @
799f784c
...
@@ -25,6 +25,9 @@ const bfcacheMap: CacheMap<BFCacheEntry> = createCacheMap()
...
@@ -25,6 +25,9 @@ const bfcacheMap: CacheMap<BFCacheEntry> = createCacheMap()
let
currentBfCacheVersion
=
0
let
currentBfCacheVersion
=
0
export
function
invalidateBfCache
():
void
{
export
function
invalidateBfCache
():
void
{
if
(
typeof
window
===
'undefined'
)
{
return
}
currentBfCacheVersion
++
currentBfCacheVersion
++
}
}
...
@@ -36,6 +39,10 @@ export function writeToBFCache(
...
@@ -36,6 +39,10 @@ export function writeToBFCache(
head
:
React
.
ReactNode
,
head
:
React
.
ReactNode
,
prefetchHead
:
React
.
ReactNode
prefetchHead
:
React
.
ReactNode
):
void
{
):
void
{
if
(
typeof
window
===
'undefined'
)
{
return
}
const
entry
:
BFCacheEntry
=
{
const
entry
:
BFCacheEntry
=
{
rsc
,
rsc
,
prefetchRsc
,
prefetchRsc
,
...
@@ -75,6 +82,9 @@ export function writeHeadToBFCache(
...
@@ -75,6 +82,9 @@ export function writeHeadToBFCache(
export
function
readFromBFCache
(
export
function
readFromBFCache
(
varyPath
:
SegmentVaryPath
varyPath
:
SegmentVaryPath
):
BFCacheEntry
|
null
{
):
BFCacheEntry
|
null
{
if
(
typeof
window
===
'undefined'
)
{
return
null
}
const
isRevalidation
=
false
const
isRevalidation
=
false
return
getFromCacheMap
(
return
getFromCacheMap
(
// During a back/forward navigation, it doesn't matter how stale the data
// During a back/forward navigation, it doesn't matter how stale the data
...
@@ -92,6 +102,9 @@ export function readFromBFCacheDuringRegularNavigation(
...
@@ -92,6 +102,9 @@ export function readFromBFCacheDuringRegularNavigation(
now
:
number
,
now
:
number
,
varyPath
:
SegmentVaryPath
varyPath
:
SegmentVaryPath
):
BFCacheEntry
|
null
{
):
BFCacheEntry
|
null
{
if
(
typeof
window
===
'undefined'
)
{
return
null
}
const
isRevalidation
=
false
const
isRevalidation
=
false
return
getFromCacheMap
(
return
getFromCacheMap
(
now
,
now
,
...
...
packages/next/src/client/components/use-action-queue.ts
View file @
799f784c
...
@@ -53,7 +53,9 @@ export function useActionQueue(
...
@@ -53,7 +53,9 @@ export function useActionQueue(
// of the router state that represents the eventual target if/when the gesture
// of the router state that represents the eventual target if/when the gesture
// completes. Otherwise it returns the canonical state.
// completes. Otherwise it returns the canonical state.
const
[
state
,
setGesture
]
=
useOptimistic
(
canonicalState
)
const
[
state
,
setGesture
]
=
useOptimistic
(
canonicalState
)
setGestureRouterState
=
setGesture
if
(
typeof
window
!==
'undefined'
)
{
setGestureRouterState
=
setGesture
}
// Because of a known issue that requires to decode Flight streams inside the
// Because of a known issue that requires to decode Flight streams inside the
// render phase, we have to be a bit clever and assign the dispatch method to
// render phase, we have to be a bit clever and assign the dispatch method to
...
@@ -62,22 +64,28 @@ export function useActionQueue(
...
@@ -62,22 +64,28 @@ export function useActionQueue(
// Ideally, what we'd do instead is pass the state as a prop to root.render;
// Ideally, what we'd do instead is pass the state as a prop to root.render;
// this is conceptually how we're modeling the app router state, despite the
// this is conceptually how we're modeling the app router state, despite the
// weird implementation details.
// weird implementation details.
let
nextDispatch
:
Dispatch
<
ReducerActions
>
if
(
process
.
env
.
NODE_ENV
!==
'production'
)
{
if
(
process
.
env
.
NODE_ENV
!==
'production'
)
{
const
{
useAppDevRenderingIndicator
}
=
const
{
useAppDevRenderingIndicator
}
=
require
(
'../../next-devtools/userspace/use-app-dev-rendering-indicator'
)
as
typeof
import
(
'../../next-devtools/userspace/use-app-dev-rendering-indicator'
)
require
(
'../../next-devtools/userspace/use-app-dev-rendering-indicator'
)
as
typeof
import
(
'../../next-devtools/userspace/use-app-dev-rendering-indicator'
)
// eslint-disable-next-line react-hooks/rules-of-hooks
// eslint-disable-next-line react-hooks/rules-of-hooks
const
appDevRenderingIndicator
=
useAppDevRenderingIndicator
()
const
appDevRenderingIndicator
=
useAppDevRenderingIndicator
()
d
ispatch
=
(
action
:
ReducerActions
)
=>
{
nextD
ispatch
=
(
action
:
ReducerActions
)
=>
{
appDevRenderingIndicator
(()
=>
{
appDevRenderingIndicator
(()
=>
{
actionQueue
.
dispatch
(
action
,
setState
)
actionQueue
.
dispatch
(
action
,
setState
)
})
})
}
}
}
else
{
}
else
{
d
ispatch
=
(
action
:
ReducerActions
)
=>
nextD
ispatch
=
(
action
:
ReducerActions
)
=>
actionQueue
.
dispatch
(
action
,
setState
)
actionQueue
.
dispatch
(
action
,
setState
)
}
}
if
(
typeof
window
!==
'undefined'
)
{
dispatch
=
nextDispatch
}
// When navigating to a non-prefetched route, then App Router state will be
// When navigating to a non-prefetched route, then App Router state will be
// blocked until the server responds. We need to transfer the `_debugInfo`
// blocked until the server responds. We need to transfer the `_debugInfo`
// from the underlying Flight response onto the top-level promise that is
// from the underlying Flight response onto the top-level promise that is
...
...
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