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
ec5cd52b
Unverified
Commit
ec5cd52b
authored
Aug 24, 2026
by
David Alexandru Ilie
Committed by
GitHub
Aug 24, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: cover metadata across dynamic route params
parent
30e73d2d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
181 additions
and
1 deletion
+181
-1
link-accordion.tsx
...metadata-soft-nav-cache-components/app/link-accordion.tsx
+40
-0
page.tsx
...e/app-dir/metadata-soft-nav-cache-components/app/page.tsx
+2
-1
client-content.tsx
...cache-components/app/products/[handle]/client-content.tsx
+21
-0
page.tsx
...-soft-nav-cache-components/app/products/[handle]/page.tsx
+61
-0
product-info.tsx
...v-cache-components/app/products/[handle]/product-info.tsx
+5
-0
metadata-soft-nav-cache-components.test.ts
...che-components/metadata-soft-nav-cache-components.test.ts
+52
-0
No files found.
test/e2e/app-dir/metadata-soft-nav-cache-components/app/link-accordion.tsx
View file @
ec5cd52b
...
...
@@ -3,6 +3,8 @@
import
Link
,
{
type
LinkProps
}
from
'next/link'
import
{
useState
}
from
'react'
const
productHandles
=
[
'alpha'
,
'gamma'
,
'delta'
,
'epsilon'
,
'zeta'
,
'eta'
]
export
function
LinkAccordion
({
href
,
children
,
...
...
@@ -31,3 +33,41 @@ export function LinkAccordion({
</>
)
}
export
function
ProductLinks
()
{
const
[
areVisible
,
setAreVisible
]
=
useState
(
false
)
const
[
isBetaVisible
,
setIsBetaVisible
]
=
useState
(
false
)
return
(
<>
<
input
type=
"checkbox"
checked=
{
areVisible
}
onChange=
{
()
=>
setAreVisible
(
!
areVisible
)
}
data
-
product
-
links
/>
<
input
type=
"checkbox"
checked=
{
isBetaVisible
}
onChange=
{
()
=>
setIsBetaVisible
(
!
isBetaVisible
)
}
data
-
beta
-
link
/>
{
areVisible
?
(
<
ul
>
{
productHandles
.
map
((
handle
)
=>
(
<
li
key=
{
handle
}
>
<
Link
href=
{
`/products/${handle}`
}
>
{
handle
}
</
Link
>
</
li
>
))
}
</
ul
>
)
:
(
'product links are hidden'
)
}
{
isBetaVisible
?
(
<
Link
href=
"/products/beta"
prefetch=
{
false
}
>
beta
</
Link
>
)
:
null
}
</>
)
}
test/e2e/app-dir/metadata-soft-nav-cache-components/app/page.tsx
View file @
ec5cd52b
import
{
LinkAccordion
}
from
'./link-accordion'
import
{
LinkAccordion
,
ProductLinks
}
from
'./link-accordion'
export
default
function
Home
()
{
return
(
...
...
@@ -14,6 +14,7 @@ export default function Home() {
</
LinkAccordion
>
</
li
>
</
ul
>
<
ProductLinks
/>
</
main
>
)
}
test/e2e/app-dir/metadata-soft-nav-cache-components/app/products/[handle]/client-content.tsx
0 → 100644
View file @
ec5cd52b
'use client'
import
{
lazy
,
Suspense
,
useEffect
,
useState
}
from
'react'
const
ProductInfo
=
lazy
(()
=>
import
(
'./product-info'
))
export
function
ClientContent
({
title
}:
{
title
:
string
})
{
const
[
isMounted
,
setIsMounted
]
=
useState
(
false
)
useEffect
(()
=>
setIsMounted
(
true
),
[])
return
(
<
Suspense
fallback=
{
<
p
id=
"client-fallback"
>
Loading client content
</
p
>
}
>
{
isMounted
?
(
<
ProductInfo
title=
{
title
}
/>
)
:
(
<
p
id=
"client-pending"
>
Waiting for hydration
</
p
>
)
}
</
Suspense
>
)
}
test/e2e/app-dir/metadata-soft-nav-cache-components/app/products/[handle]/page.tsx
0 → 100644
View file @
ec5cd52b
import
{
cacheLife
}
from
'next/cache'
import
Link
from
'next/link'
import
type
{
Metadata
}
from
'next'
import
{
Suspense
}
from
'react'
import
{
ClientContent
}
from
'./client-content'
const
products
:
Record
<
string
,
{
title
:
string
}
>
=
{
alpha
:
{
title
:
'Alpha Product'
},
beta
:
{
title
:
'Beta Product'
},
gamma
:
{
title
:
'Gamma Product'
},
delta
:
{
title
:
'Delta Product'
},
epsilon
:
{
title
:
'Epsilon Product'
},
zeta
:
{
title
:
'Zeta Product'
},
eta
:
{
title
:
'Eta Product'
},
}
async
function
getProduct
({
handle
,
locale
,
}:
{
handle
:
string
locale
:
string
})
{
'use cache'
cacheLife
(
'max'
)
return
{
...
products
[
handle
],
locale
}
}
export
function
generateStaticParams
()
{
return
[{
handle
:
'alpha'
}]
}
export
async
function
generateMetadata
({
params
,
}:
{
params
:
Promise
<
{
handle
:
string
}
>
}):
Promise
<
Metadata
>
{
const
{
handle
}
=
await
params
const
product
=
await
getProduct
({
handle
,
locale
:
'en'
})
return
{
title
:
product
.
title
}
}
export
const
instant
=
false
export
default
async
function
ProductPage
({
params
,
}:
{
params
:
Promise
<
{
handle
:
string
}
>
})
{
const
{
handle
}
=
await
params
const
product
=
await
getProduct
({
handle
,
locale
:
'en'
})
return
(
<
main
>
<
Suspense
fallback=
{
<
p
id=
"product-fallback"
>
Loading product
</
p
>
}
>
<
ClientContent
title=
{
product
.
title
}
/>
</
Suspense
>
<
Link
href=
"/"
>
Home
</
Link
>
</
main
>
)
}
test/e2e/app-dir/metadata-soft-nav-cache-components/app/products/[handle]/product-info.tsx
0 → 100644
View file @
ec5cd52b
'use client'
export
default
function
ProductInfo
({
title
}:
{
title
:
string
})
{
return
<
h1
id=
"product-title"
>
{
title
}
</
h1
>
}
test/e2e/app-dir/metadata-soft-nav-cache-components/metadata-soft-nav-cache-components.test.ts
View file @
ec5cd52b
...
...
@@ -87,4 +87,56 @@ describe('metadata-soft-nav-cache-components', () => {
)
})
})
it
(
'does not reuse metadata across dynamic params'
,
async
()
=>
{
let
page
:
Playwright
.
Page
=
null
as
any
const
browser
=
await
next
.
browser
(
'/'
,
{
beforePageLoad
(
p
:
Playwright
.
Page
)
{
page
=
p
},
})
const
act
=
createRouterAct
(
page
,
{
includeAppShellRequests
:
true
})
// Reveal several links to the same dynamic route in one render. This
// populates shared prefetch state for the route, while the final metadata
// depends on the concrete `handle` param.
await
act
(
async
()
=>
{
await
browser
.
elementByCss
(
'input[data-product-links]'
).
click
()
})
await
act
(
async
()
=>
{
await
browser
.
elementByCss
(
'a[href="/products/gamma"]'
).
click
()
})
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'#product-title'
).
text
()).
toBe
(
'Gamma Product'
)
expect
(
await
browser
.
eval
(()
=>
document
.
title
)).
toBe
(
'Gamma Product | Site'
)
})
await
browser
.
elementByCss
(
'a[href="/"]'
).
click
()
await
browser
.
waitForElementByCss
(
'#home'
)
// Beta is intentionally not prefetched. Its full navigation response
// contains Beta's metadata and body; neither may be replaced by the
// previously visited Gamma route's cached result.
await
browser
.
elementByCss
(
'input[data-beta-link]'
).
click
()
await
browser
.
waitForElementByCss
(
'a[href="/products/beta"]'
)
await
act
(
async
()
=>
{
await
browser
.
elementByCss
(
'a[href="/products/beta"]'
).
click
()
},
{
includes
:
'Beta Product'
}
)
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'#product-title'
).
text
()).
toBe
(
'Beta Product'
)
expect
(
await
browser
.
eval
(()
=>
document
.
title
)).
toBe
(
'Beta Product | Site'
)
})
})
})
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