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
d12493b7
Unverified
Commit
d12493b7
authored
Jul 03, 2025
by
Zack Tanner
Committed by
GitHub
Jul 03, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfix: propagate staleTime to seeded prefetch entry (#81263) (#81266)
Backports: - #81263
parent
632d4abc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
6 deletions
+65
-6
create-initial-router-state.ts
.../components/router-reducer/create-initial-router-state.ts
+11
-2
prefetch-cache-utils.ts
.../client/components/router-reducer/prefetch-cache-utils.ts
+1
-1
page.js
test/e2e/app-dir/app-prefetch/app/page.js
+3
-0
page.js
.../app-dir/app-prefetch/app/static-page-no-prefetch/page.js
+14
-0
prefetching.stale-times.test.ts
.../e2e/app-dir/app-prefetch/prefetching.stale-times.test.ts
+36
-3
No files found.
packages/next/src/client/components/router-reducer/create-initial-router-state.ts
View file @
d12493b7
...
@@ -4,7 +4,10 @@ import type { FlightDataPath } from '../../../server/app-render/types'
...
@@ -4,7 +4,10 @@ import type { FlightDataPath } from '../../../server/app-render/types'
import
{
createHrefFromUrl
}
from
'./create-href-from-url'
import
{
createHrefFromUrl
}
from
'./create-href-from-url'
import
{
fillLazyItemsTillLeafWithHead
}
from
'./fill-lazy-items-till-leaf-with-head'
import
{
fillLazyItemsTillLeafWithHead
}
from
'./fill-lazy-items-till-leaf-with-head'
import
{
extractPathFromFlightRouterState
}
from
'./compute-changed-path'
import
{
extractPathFromFlightRouterState
}
from
'./compute-changed-path'
import
{
createSeededPrefetchCacheEntry
}
from
'./prefetch-cache-utils'
import
{
createSeededPrefetchCacheEntry
,
STATIC_STALETIME_MS
,
}
from
'./prefetch-cache-utils'
import
{
PrefetchKind
,
type
PrefetchCacheEntry
}
from
'./router-reducer-types'
import
{
PrefetchKind
,
type
PrefetchCacheEntry
}
from
'./router-reducer-types'
import
{
addRefreshMarkerToActiveParallelSegments
}
from
'./refetch-inactive-parallel-segments'
import
{
addRefreshMarkerToActiveParallelSegments
}
from
'./refetch-inactive-parallel-segments'
import
{
getFlightDataPartsFromPath
}
from
'../../flight-data-helpers'
import
{
getFlightDataPartsFromPath
}
from
'../../flight-data-helpers'
...
@@ -132,7 +135,13 @@ export function createInitialRouterState({
...
@@ -132,7 +135,13 @@ export function createInitialRouterState({
// add a way to split a single Flight stream into static and dynamic
// add a way to split a single Flight stream into static and dynamic
// parts. But in the meantime we should at least make this work for
// parts. But in the meantime we should at least make this work for
// fully static pages.
// fully static pages.
staleTime
:
-
1
,
staleTime
:
// In the old router, there was only a single configurable staleTime (experimental.staleTimes)
// As an abundance of caution, this will only set the initial staleTime to the configured value
// if we're not leveraging the segment cache, which has its own prefetching semantics.
prerendered
&&
!
process
.
env
.
__NEXT_CLIENT_SEGMENT_CACHE
?
STATIC_STALETIME_MS
:
-
1
,
},
},
tree
:
initialState
.
tree
,
tree
:
initialState
.
tree
,
prefetchCache
:
initialState
.
prefetchCache
,
prefetchCache
:
initialState
.
prefetchCache
,
...
...
packages/next/src/client/components/router-reducer/prefetch-cache-utils.ts
View file @
d12493b7
...
@@ -291,7 +291,7 @@ export function createSeededPrefetchCacheEntry({
...
@@ -291,7 +291,7 @@ export function createSeededPrefetchCacheEntry({
kind
,
kind
,
prefetchTime
:
Date
.
now
(),
prefetchTime
:
Date
.
now
(),
lastUsedTime
:
Date
.
now
(),
lastUsedTime
:
Date
.
now
(),
staleTime
:
-
1
,
staleTime
:
data
.
staleTime
,
key
:
prefetchCacheKey
,
key
:
prefetchCacheKey
,
status
:
PrefetchCacheEntryStatus
.
fresh
,
status
:
PrefetchCacheEntryStatus
.
fresh
,
url
,
url
,
...
...
test/e2e/app-dir/app-prefetch/app/page.js
View file @
d12493b7
...
@@ -8,6 +8,9 @@ export default function HomePage() {
...
@@ -8,6 +8,9 @@ export default function HomePage() {
<
Link
href
=
"/static-page"
id
=
"to-static-page"
>
<
Link
href
=
"/static-page"
id
=
"to-static-page"
>
To
Static
Page
To
Static
Page
<
/Link
>
<
/Link
>
<
Link
href
=
"/static-page-no-prefetch"
id
=
"to-static-page-no-prefetch"
>
To
Static
Page
No
Prefetch
<
/Link
>
<
Link
href
=
"/dynamic-page"
id
=
"to-dynamic-page-no-params"
>
<
Link
href
=
"/dynamic-page"
id
=
"to-dynamic-page-no-params"
>
To
Dynamic
Page
To
Dynamic
Page
<
/Link
>
<
/Link
>
...
...
test/e2e/app-dir/app-prefetch/app/static-page-no-prefetch/page.js
0 → 100644
View file @
d12493b7
import
Link
from
'next/link'
export
default
async
function
Page
()
{
return
(
<>
<
p
id
=
"static-page-no-prefetch"
>
Static
Page
No
Prefetch
<
/p
>
<
p
>
<
Link
href
=
"/"
id
=
"to-home"
>
To
home
<
/Link
>
<
/p
>
<
/
>
)
}
test/e2e/app-dir/app-prefetch/prefetching.stale-times.test.ts
View file @
d12493b7
...
@@ -8,8 +8,8 @@ describe('app dir - prefetching (custom staleTime)', () => {
...
@@ -8,8 +8,8 @@ describe('app dir - prefetching (custom staleTime)', () => {
nextConfig
:
{
nextConfig
:
{
experimental
:
{
experimental
:
{
staleTimes
:
{
staleTimes
:
{
static
:
3
0
,
static
:
1
0
,
dynamic
:
20
,
dynamic
:
5
,
},
},
},
},
},
},
...
@@ -86,7 +86,7 @@ describe('app dir - prefetching (custom staleTime)', () => {
...
@@ -86,7 +86,7 @@ describe('app dir - prefetching (custom staleTime)', () => {
.
waitForElementByCss
(
'#to-static-page'
)
.
waitForElementByCss
(
'#to-static-page'
)
// Wait for the stale time to pass.
// Wait for the stale time to pass.
await
waitFor
(
3
0000
)
await
waitFor
(
1
0000
)
// Click on the link to the static page again
// Click on the link to the static page again
await
linkToStaticPage
.
click
()
await
linkToStaticPage
.
click
()
// Wait for the static page to load again
// Wait for the static page to load again
...
@@ -131,4 +131,37 @@ describe('app dir - prefetching (custom staleTime)', () => {
...
@@ -131,4 +131,37 @@ describe('app dir - prefetching (custom staleTime)', () => {
// the initial fetch, 2 sub-page fetches, and a final fetch when reloading the page
// the initial fetch, 2 sub-page fetches, and a final fetch when reloading the page
expect
(
await
browser
.
elementById
(
'count'
).
text
()).
toBe
(
'4'
)
expect
(
await
browser
.
elementById
(
'count'
).
text
()).
toBe
(
'4'
)
})
})
it
(
'should fetch again when the initially visited static page is visited after the stale time has passed'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/404'
)
let
requests
:
string
[]
=
[]
browser
.
on
(
'request'
,
(
req
)
=>
{
// only consider requests that have RSC header but not the prefetch header
if
(
req
.
headers
()[
'rsc'
]
&&
!
req
.
headers
()[
'next-router-prefetch'
])
{
requests
.
push
(
new
URL
(
req
.
url
()).
pathname
)
}
})
await
browser
.
eval
(
'location.href = "/static-page-no-prefetch"'
)
await
browser
.
elementByCss
(
'#to-home'
)
.
click
()
.
waitForElementByCss
(
'#to-static-page'
)
// Wait for the stale time to pass.
await
waitFor
(
10000
)
await
browser
.
elementByCss
(
'#to-static-page-no-prefetch'
).
click
()
// Wait for the static page to load again
await
browser
.
waitForElementByCss
(
'#static-page-no-prefetch'
)
await
retry
(
async
()
=>
{
expect
(
requests
.
filter
((
request
)
=>
request
===
'/static-page-no-prefetch'
)
).
toHaveLength
(
1
)
})
})
})
})
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