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
b455670b
Commit
b455670b
authored
Jul 17, 2025
by
Janka Uryga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrate some tests to from prefetch=true to unstable_forceStale
parent
8719a85b
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
77 additions
and
59 deletions
+77
-59
page.tsx
test/e2e/app-dir/searchparams-reuse-loading/app/page.tsx
+4
-4
page.tsx
...r/searchparams-reuse-loading/app/with-middleware/page.tsx
+9
-3
link-accordion.tsx
...ent-cache/cdn-cache-busting/components/link-accordion.tsx
+2
-2
link-accordion.tsx
...nt-cache/client-only-opt-in/components/link-accordion.tsx
+2
-2
link-accordion.tsx
...gment-cache/deployment-skew/components/link-accordion.tsx
+2
-2
link-accordion.tsx
...ment-cache/dynamic-on-hover/components/link-accordion.tsx
+2
-2
link-accordion.tsx
...r/segment-cache/incremental-opt-in/app/link-accordion.tsx
+2
-2
page.tsx
...he/incremental-opt-in/app/mixed-fetch-strategies/page.tsx
+2
-2
segment-cache-incremental-opt-in.test.ts
...cremental-opt-in/segment-cache-incremental-opt-in.test.ts
+7
-7
link-accordion.tsx
...e2e/app-dir/segment-cache/metadata/app/link-accordion.tsx
+2
-3
page.tsx
test/e2e/app-dir/segment-cache/metadata/app/page.tsx
+7
-4
link-accordion.tsx
...gment-cache/mpa-navigations/components/link-accordion.tsx
+2
-2
link-accordion.tsx
...segment-cache/prefetch-auto/components/link-accordion.tsx
+1
-1
layout.tsx
...ache/revalidation/app/refetch-on-new-base-tree/layout.tsx
+16
-9
link-accordion.tsx
.../segment-cache/revalidation/components/link-accordion.tsx
+6
-3
segment-cache-revalidation.test.ts
...ent-cache/revalidation/segment-cache-revalidation.test.ts
+1
-1
page.tsx
...ir/segment-cache/search-params/app/search-params/page.tsx
+4
-4
link-accordion.tsx
...segment-cache/search-params/components/link-accordion.tsx
+2
-2
segment-cache-search-params.test.ts
...t-cache/search-params/segment-cache-search-params.test.ts
+4
-4
No files found.
test/e2e/app-dir/searchparams-reuse-loading/app/page.tsx
View file @
b455670b
...
...
@@ -16,13 +16,13 @@ export default async function Page(props) {
<
Link
href=
"/search-params?id=2"
>
/search-params?id=2
</
Link
>
</
li
>
<
li
>
<
Link
href=
"/search-params?id=3"
prefetch
>
/search-params?id=3 (prefetch:
tru
e)
<
Link
href=
"/search-params?id=3"
prefetch
=
"unstable_forceStale"
>
/search-params?id=3 (prefetch:
unstable_forceStal
e)
</
Link
>
</
li
>
<
li
>
<
Link
href=
"/search-params"
prefetch
>
/search-params (prefetch:
tru
e)
<
Link
href=
"/search-params"
prefetch
=
"unstable_forceStale"
>
/search-params (prefetch:
unstable_forceStal
e)
</
Link
>
</
li
>
<
li
>
...
...
test/e2e/app-dir/searchparams-reuse-loading/app/with-middleware/page.tsx
View file @
b455670b
...
...
@@ -5,7 +5,7 @@ export default function Page() {
<
ul
>
<
li
>
<
Link
href=
"/with-middleware/search-params?id=1"
>
/search-params?id=1
(prefetch: true)
/search-params?id=1
</
Link
>
</
li
>
<
li
>
...
...
@@ -14,12 +14,18 @@ export default function Page() {
</
Link
>
</
li
>
<
li
>
<
Link
href=
"/with-middleware/search-params?id=3"
prefetch
>
<
Link
href=
"/with-middleware/search-params?id=3"
prefetch=
"unstable_forceStale"
>
/search-params?id=3 (prefetch: true)
</
Link
>
</
li
>
<
li
>
<
Link
href=
"/with-middleware/search-params"
prefetch
>
<
Link
href=
"/with-middleware/search-params"
prefetch=
"unstable_forceStale"
>
/search-params (prefetch: true)
</
Link
>
</
li
>
...
...
test/e2e/app-dir/segment-cache/cdn-cache-busting/components/link-accordion.tsx
View file @
b455670b
'use client'
import
Link
from
'next/link'
import
Link
,
{
type
LinkProps
}
from
'next/link'
import
{
useState
}
from
'react'
export
function
LinkAccordion
({
...
...
@@ -10,7 +10,7 @@ export function LinkAccordion({
}:
{
href
:
string
children
:
React
.
ReactNode
prefetch
?:
boolean
prefetch
?:
LinkProps
[
'prefetch'
]
})
{
const
[
isVisible
,
setIsVisible
]
=
useState
(
false
)
return
(
...
...
test/e2e/app-dir/segment-cache/client-only-opt-in/components/link-accordion.tsx
View file @
b455670b
'use client'
import
Link
from
'next/link'
import
Link
,
{
type
LinkProps
}
from
'next/link'
import
{
useState
}
from
'react'
export
function
LinkAccordion
({
...
...
@@ -10,7 +10,7 @@ export function LinkAccordion({
}:
{
href
:
string
children
:
React
.
ReactNode
prefetch
?:
boolean
prefetch
?:
LinkProps
[
'prefetch'
]
})
{
const
[
isVisible
,
setIsVisible
]
=
useState
(
false
)
return
(
...
...
test/e2e/app-dir/segment-cache/deployment-skew/components/link-accordion.tsx
View file @
b455670b
'use client'
import
Link
from
'next/link'
import
Link
,
{
type
LinkProps
}
from
'next/link'
import
{
useState
}
from
'react'
export
function
LinkAccordion
({
...
...
@@ -10,7 +10,7 @@ export function LinkAccordion({
}:
{
href
:
string
children
:
React
.
ReactNode
prefetch
?:
boolean
prefetch
?:
LinkProps
[
'prefetch'
]
})
{
const
[
isVisible
,
setIsVisible
]
=
useState
(
false
)
return
(
...
...
test/e2e/app-dir/segment-cache/dynamic-on-hover/components/link-accordion.tsx
View file @
b455670b
'use client'
import
Link
from
'next/link'
import
Link
,
{
type
LinkProps
}
from
'next/link'
import
{
useState
}
from
'react'
export
function
LinkAccordion
({
...
...
@@ -11,7 +11,7 @@ export function LinkAccordion({
}:
{
href
:
string
children
:
React
.
ReactNode
prefetch
?:
boolean
prefetch
?:
LinkProps
[
'prefetch'
]
unstable_dynamicOnHover
?:
boolean
})
{
const
[
isVisible
,
setIsVisible
]
=
useState
(
false
)
...
...
test/e2e/app-dir/segment-cache/incremental-opt-in/app/link-accordion.tsx
View file @
b455670b
'use client'
import
Link
from
'next/link'
import
Link
,
{
type
LinkProps
}
from
'next/link'
import
{
useState
}
from
'react'
export
function
LinkAccordion
({
...
...
@@ -11,7 +11,7 @@ export function LinkAccordion({
}:
{
href
:
string
children
:
string
prefetch
?:
boolean
prefetch
?:
LinkProps
[
'prefetch'
]
id
?:
string
})
{
const
[
isVisible
,
setIsVisible
]
=
useState
(
false
)
...
...
test/e2e/app-dir/segment-cache/incremental-opt-in/app/mixed-fetch-strategies/page.tsx
View file @
b455670b
...
...
@@ -22,10 +22,10 @@ export default function MixedFetchStrategies() {
<
li
>
<
LinkAccordion
id=
"ppr-enabled-prefetch-true"
prefetch=
{
true
}
prefetch=
"unstable_forceStale"
href=
"/mixed-fetch-strategies/has-loading-boundary/a/b/shared-layout/ppr-enabled"
>
Same link, but with prefetch=
true
Same link, but with prefetch=
"unstable_forceStale"
</
LinkAccordion
>
</
li
>
</
ul
>
...
...
test/e2e/app-dir/segment-cache/incremental-opt-in/segment-cache-incremental-opt-in.test.ts
View file @
b455670b
...
...
@@ -285,7 +285,7 @@ describe('segment cache (incremental opt in)', () => {
)
it
(
'when a link is prefetched with <Link prefetch=
true
>, no dynamic request '
+
'when a link is prefetched with <Link prefetch=
"unstable_forceStale"
>, no dynamic request '
+
'is made on navigation'
,
async
()
=>
{
let
act
...
...
@@ -324,7 +324,7 @@ describe('segment cache (incremental opt in)', () => {
)
it
(
'when prefetching with prefetch=
true
, refetches cache entries that only '
+
'when prefetching with prefetch=
"unstable_forceStale"
, refetches cache entries that only '
+
'contain partial data'
,
async
()
=>
{
let
act
...
...
@@ -343,7 +343,7 @@ describe('segment cache (incremental opt in)', () => {
{
includes
:
'Loading (PPR shell of shared-layout)...'
}
)
// Prefetch the same link again, this time with prefetch=
true
to include
// Prefetch the same link again, this time with prefetch=
"unstable_forceStale"
to include
// the dynamic data
await
act
(
async
()
=>
{
...
...
@@ -370,7 +370,7 @@ describe('segment cache (incremental opt in)', () => {
// If this fails, it likely means that the partial cache entry that
// resulted from prefetching the normal link (<Link prefetch={false}>)
// was not properly re-fetched when the full link (<Link
// prefetch=
{true}
>) was prefetched.
// prefetch=
'unstable_forceStale'
>) was prefetched.
await
browser
.
elementById
(
'page-content'
)
},
// Assert that no network requests are initiated within this block.
...
...
@@ -380,7 +380,7 @@ describe('segment cache (incremental opt in)', () => {
)
it
(
'when prefetching with prefetch=
true
, refetches partial cache entries '
+
'when prefetching with prefetch=
"unstable_forceStale"
, refetches partial cache entries '
+
"even if there's already a pending PPR request"
,
async
()
=>
{
// This test is hard to describe succinctly because it involves a fairly
...
...
@@ -427,7 +427,7 @@ describe('segment cache (incremental opt in)', () => {
)
// Before the previous prefetch finishes, prefetch the same link again,
// this time with prefetch=
true
to include the dynamic data.
// this time with prefetch=
"unstable_forceStale"
to include the dynamic data.
await
act
(
async
()
=>
{
const
checkbox
=
await
browser
.
elementById
(
...
...
@@ -457,7 +457,7 @@ describe('segment cache (incremental opt in)', () => {
// If this fails, it likely means that the pending cache entry that
// resulted from prefetching the normal link (<Link prefetch={false}>)
// was not properly re-fetched when the full link (<Link
// prefetch=
{true}
>) was prefetched.
// prefetch=
'unstable_forceStale'
>) was prefetched.
await
browser
.
elementById
(
'page-content'
)
},
// Assert that no network requests are initiated within this block.
...
...
test/e2e/app-dir/segment-cache/metadata/app/link-accordion.tsx
View file @
b455670b
'use client'
import
Link
from
'next/link'
import
Link
,
{
type
LinkProps
}
from
'next/link'
import
{
useState
}
from
'react'
export
function
LinkAccordion
({
...
...
@@ -11,7 +11,7 @@ export function LinkAccordion({
}:
{
href
:
string
children
:
string
prefetch
?:
boolean
|
'unstable_forceStale'
|
'auto'
prefetch
?:
LinkProps
[
'prefetch'
]
id
?:
string
})
{
const
[
isVisible
,
setIsVisible
]
=
useState
(
false
)
...
...
@@ -25,7 +25,6 @@ export function LinkAccordion({
id=
{
id
}
/>
{
isVisible
?
(
// @ts-expect-error - unstable_forceStale is not yet part of the types
<
Link
href=
{
href
}
prefetch=
{
prefetch
}
>
{
children
}
</
Link
>
...
...
test/e2e/app-dir/segment-cache/metadata/app/page.tsx
View file @
b455670b
...
...
@@ -5,16 +5,19 @@ export default function Page() {
<>
<
ul
>
<
li
>
<
LinkAccordion
prefetch=
{
true
}
href=
"/page-with-dynamic-head"
>
Page with dynamic head (prefetch=true))
<
LinkAccordion
prefetch=
"unstable_forceStale"
href=
"/page-with-dynamic-head"
>
Page with dynamic head (prefetch=unstable_forceStale)
</
LinkAccordion
>
</
li
>
<
li
>
<
LinkAccordion
prefetch=
{
true
}
prefetch=
"unstable_forceStale"
href=
"/rewrite-to-page-with-dynamic-head"
>
Rewrite to page with dynamic head (prefetch=
tru
e)
Rewrite to page with dynamic head (prefetch=
unstable_forceStal
e)
</
LinkAccordion
>
</
li
>
</
ul
>
...
...
test/e2e/app-dir/segment-cache/mpa-navigations/components/link-accordion.tsx
View file @
b455670b
'use client'
import
Link
from
'next/link'
import
Link
,
{
type
LinkProps
}
from
'next/link'
import
{
useState
}
from
'react'
export
function
LinkAccordion
({
...
...
@@ -10,7 +10,7 @@ export function LinkAccordion({
}:
{
href
:
string
children
:
React
.
ReactNode
prefetch
?:
boolean
prefetch
?:
LinkProps
[
'prefetch'
]
})
{
const
[
isVisible
,
setIsVisible
]
=
useState
(
false
)
return
(
...
...
test/e2e/app-dir/segment-cache/prefetch-auto/components/link-accordion.tsx
View file @
b455670b
'use client'
import
Link
,
{
LinkProps
}
from
'next/link'
import
Link
,
{
type
LinkProps
}
from
'next/link'
import
{
useState
}
from
'react'
export
function
LinkAccordion
({
...
...
test/e2e/app-dir/segment-cache/revalidation/app/refetch-on-new-base-tree/layout.tsx
View file @
b455670b
...
...
@@ -10,16 +10,17 @@ export default function RefetchOnNewBaseTreeLayout({
<
div
style=
{
{
backgroundColor
:
'lightgray'
,
padding
:
'1rem'
}
}
>
<
p
>
This demonstrates what happens when a link is prefetched using
{
' '
}
<
code
>
{
'prefetch=
{true}'
}
</
code
>
and the URL changes. Next.js should
re-prefetch the link in case the delta between the base tree and th
e
target tree has changed.
<
code
>
{
'prefetch=
"unstable_forceStale"'
}
</
code
>
and the URL changes.
Next.js should re-prefetch the link in case the delta between the bas
e
t
ree and the t
arget tree has changed.
</
p
>
<
p
>
Everything in this gray section is part of a shared layout. The links
below are prefetched using
<
code
>
{
'prefetch={true}'
}
</
code
>
. If the
first loaded page is "/refetch-on-new-base-tree/a", the prefetch for
this link will be empty, because there's no delta between the base
tree and the target tree.
below are prefetched using
{
' '
}
<
code
>
{
'prefetch="unstable_forceStale"'
}
</
code
>
. If the first loaded
page is "/refetch-on-new-base-tree/a", the prefetch for this link will
be empty, because there's no delta between the base tree and the
target tree.
</
p
>
<
p
>
However, if you then navigate to page B, we should re-prefetch the
...
...
@@ -48,10 +49,16 @@ export default function RefetchOnNewBaseTreeLayout({
because it was fully prefetched.
</
li
>
</
ul
>
<
LinkAccordion
prefetch=
{
true
}
href=
"/refetch-on-new-base-tree/a"
>
<
LinkAccordion
prefetch=
"unstable_forceStale"
href=
"/refetch-on-new-base-tree/a"
>
Page A
</
LinkAccordion
>
<
LinkAccordion
prefetch=
{
true
}
href=
"/refetch-on-new-base-tree/b"
>
<
LinkAccordion
prefetch=
"unstable_forceStale"
href=
"/refetch-on-new-base-tree/b"
>
Page B
</
LinkAccordion
>
</
div
>
...
...
test/e2e/app-dir/segment-cache/revalidation/components/link-accordion.tsx
View file @
b455670b
'use client'
import
Link
from
'next/link'
import
Link
,
{
type
LinkProps
}
from
'next/link'
import
Form
from
'next/form'
import
{
useEffect
,
useState
}
from
'react'
import
{
useRouter
}
from
'next/navigation'
...
...
@@ -12,7 +12,7 @@ export function LinkAccordion({
}:
{
href
:
string
children
:
React
.
ReactNode
prefetch
?:
boolean
prefetch
?:
LinkProps
[
'prefetch'
]
})
{
const
[
isVisible
,
setIsVisible
]
=
useState
(
false
)
return
(
...
...
@@ -92,6 +92,9 @@ export function ManualPrefetchLinkAccordion({
)
}
type
Router
=
ReturnType
<
typeof
useRouter
>
type
PrefetchOptions
=
Parameters
<
Router
[
'prefetch'
]
>
[
1
]
function
ManualPrefetchLink
({
href
,
children
,
...
...
@@ -109,8 +112,8 @@ function ManualPrefetchLink({
let
didUnmount
=
false
const
pollPrefetch
=
()
=>
{
if
(
!
didUnmount
)
{
// @ts-expect-error: onInvalidate is not yet part of public types
router
.
prefetch
(
href
,
{
kind
:
'auto'
as
PrefetchOptions
[
'kind'
],
onInvalidate
:
pollPrefetch
,
})
}
...
...
test/e2e/app-dir/segment-cache/revalidation/segment-cache-revalidation.test.ts
View file @
b455670b
...
...
@@ -272,7 +272,7 @@ describe('segment cache (revalidation)', () => {
includes
:
'Page B content'
,
},
// Page A's content should not be prefetched because we're already on that
// page. When prefetching with `prefetch=
{true}
`, we only prefetch the
// page. When prefetching with `prefetch=
'unstable_forceStale'
`, we only prefetch the
// delta between the current route and the target route.
{
includes
:
'Page A content'
,
...
...
test/e2e/app-dir/segment-cache/search-params/app/search-params/page.tsx
View file @
b455670b
...
...
@@ -19,10 +19,10 @@ export default function SearchParamsPage({
</
li
>
<
li
>
<
LinkAccordion
prefetch=
{
true
}
prefetch=
"unstable_forceStale"
href=
"/search-params/target-page?searchParam=b_full"
>
searchParam=b_full, prefetch=
true
searchParam=b_full, prefetch=
"unstable_forceStale"
</
LinkAccordion
>
</
li
>
<
li
>
...
...
@@ -32,10 +32,10 @@ export default function SearchParamsPage({
</
li
>
<
li
>
<
LinkAccordion
prefetch=
{
true
}
prefetch=
"unstable_forceStale"
href=
"/search-params/target-page?searchParam=d_full"
>
searchParam=d_full, prefetch=
true
searchParam=d_full, prefetch=
"unstable_forceStale"
</
LinkAccordion
>
</
li
>
</
ul
>
...
...
test/e2e/app-dir/segment-cache/search-params/components/link-accordion.tsx
View file @
b455670b
'use client'
import
Link
from
'next/link'
import
Link
,
{
type
LinkProps
}
from
'next/link'
import
{
useState
}
from
'react'
export
function
LinkAccordion
({
...
...
@@ -10,7 +10,7 @@ export function LinkAccordion({
}:
{
href
:
string
children
:
React
.
ReactNode
prefetch
?:
boolean
prefetch
?:
LinkProps
[
'prefetch'
]
})
{
const
[
isVisible
,
setIsVisible
]
=
useState
(
false
)
return
(
...
...
test/e2e/app-dir/segment-cache/search-params/segment-cache-search-params.test.ts
View file @
b455670b
...
...
@@ -67,7 +67,7 @@ describe('segment cache (search params)', () => {
expect
(
await
result
.
innerText
()).
toBe
(
'Search param: c_PPR'
)
})
it
(
'when fetching without PPR (e.g. prefetch=
{true}
), includes the search params in the cache key'
,
async
()
=>
{
it
(
'when fetching without PPR (e.g. prefetch=
"unstable_forceStale"
), includes the search params in the cache key'
,
async
()
=>
{
let
act
:
ReturnType
<
typeof
createRouterAct
>
const
browser
=
await
next
.
browser
(
'/search-params'
,
{
beforePageLoad
(
page
)
{
...
...
@@ -75,7 +75,7 @@ describe('segment cache (search params)', () => {
},
})
// Prefetch a page with search param `b_full`. This link has prefetch=
{true}
// Prefetch a page with search param `b_full`. This link has prefetch=
'unstable_forceStale'
// so it will fetch the entire page, including the search param.
const
revealB
=
await
browser
.
elementByCss
(
'input[data-link-accordion="/search-params/target-page?searchParam=b_full"]'
...
...
@@ -91,7 +91,7 @@ describe('segment cache (search params)', () => {
)
// Prefetch a link with a different search param, and without
// prefetch=
{true}
. This must fetch a new shell, because it can't use the
// prefetch=
'unstable_forceStale'
. This must fetch a new shell, because it can't use the
// entry we fetched for `searchParam=b_full` (because that one wasn't a
// shell — it included the search param).
const
revealA
=
await
browser
.
elementByCss
(
...
...
@@ -106,7 +106,7 @@ describe('segment cache (search params)', () => {
{
includes
:
'target-page-with-search-param'
}
)
// Prefetch a different link using prefetch=
{true}
. Again, this must issue
// Prefetch a different link using prefetch=
'unstable_forceStale'
. Again, this must issue
// a new request, because it's a full page prefetch and we haven't fetched
// this particular search param before.
// TODO: As an future optimization, if a navigation to this link occurs
...
...
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