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
7b0ab1ec
Unverified
Commit
7b0ab1ec
authored
Nov 24, 2024
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Nov 24, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Current behavior for fallbacks with async metadata and prefetching (#73106)
parent
560bfdb3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
19 deletions
+53
-19
page.js
...-dir/navigation/app/metadata-await-promise/nested/page.js
+2
-2
page.js
...e2e/app-dir/navigation/app/metadata-await-promise/page.js
+1
-1
navigation.test.ts
test/e2e/app-dir/navigation/navigation.test.ts
+50
-16
No files found.
test/e2e/app-dir/navigation/app/metadata-await-promise/nested/page.js
View file @
7b0ab1ec
...
@@ -3,13 +3,13 @@ import React from 'react'
...
@@ -3,13 +3,13 @@ import React from 'react'
// ensure this page is dynamically rendered so we always trigger a loading state
// ensure this page is dynamically rendered so we always trigger a loading state
export
const
dynamic
=
'force-dynamic'
export
const
dynamic
=
'force-dynamic'
export
default
function
p
age
()
{
export
default
function
P
age
()
{
return
<
div
id
=
"page-content"
>
Content
<
/div
>
return
<
div
id
=
"page-content"
>
Content
<
/div
>
}
}
async
function
getTitle
()
{
async
function
getTitle
()
{
return
await
new
Promise
((
resolve
)
=>
return
await
new
Promise
((
resolve
)
=>
setTimeout
(()
=>
resolve
(
'Async Title'
),
1
000
)
setTimeout
(()
=>
resolve
(
'Async Title'
),
5
000
)
)
)
}
}
...
...
test/e2e/app-dir/navigation/app/metadata-await-promise/page.js
View file @
7b0ab1ec
import
Link
from
'next/link'
import
Link
from
'next/link'
export
default
function
p
age
()
{
export
default
function
P
age
()
{
return
(
return
(
<
div
>
<
div
>
<
Link
href
=
"/metadata-await-promise/nested"
>
Link
to
nested
<
/Link
>
<
Link
href
=
"/metadata-await-promise/nested"
>
Link
to
nested
<
/Link
>
...
...
test/e2e/app-dir/navigation/navigation.test.ts
View file @
7b0ab1ec
...
@@ -881,29 +881,63 @@ describe('app dir - navigation', () => {
...
@@ -881,29 +881,63 @@ describe('app dir - navigation', () => {
})
})
describe
(
'navigating to a page with async metadata'
,
()
=>
{
describe
(
'navigating to a page with async metadata'
,
()
=>
{
it
(
'should render the final state of the page with correct metadata'
,
async
()
=>
{
it
(
'shows a fallback when prefetch was pending'
,
async
()
=>
{
const
resolveMetadataDuration
=
5000
const
browser
=
await
next
.
browser
(
'/metadata-await-promise'
)
const
browser
=
await
next
.
browser
(
'/metadata-await-promise'
)
// dev doesn't trigger the loading boundary as it's not prefetched
// Hopefully this click happened before the prefetch was completed.
if
(
isNextDev
)
{
// TODO: Programmatically trigger prefetch e.g. by mounting the link later.
await
browser
await
browser
.
elementByCss
(
"[href='/metadata-await-promise/nested']"
)
.
elementByCss
(
"[href='/metadata-await-promise/nested']"
)
.
click
()
.
click
()
}
else
{
const
loadingText
=
await
browser
.
elementByCss
(
"[href='/metadata-await-promise/nested']"
)
.
click
()
.
waitForElementByCss
(
'#loading'
)
.
text
()
expect
(
loadingText
).
toBe
(
'Loading'
)
if
(
!
isNextDev
)
{
// next-dev has no prefetch
expect
(
await
browser
.
waitForElementByCss
(
'#loading'
,
// Wait a bit longer than the prefetch duration since the click takes a while to register and the fallback render also takes time.
resolveMetadataDuration
+
500
)
.
text
()
).
toEqual
(
'Loading'
)
expect
(
await
browser
.
elementByCss
(
'title'
).
text
()).
toBe
(
'Async Title'
)
}
}
await
retry
(
async
()
=>
{
await
waitFor
(
resolveMetadataDuration
)
expect
(
await
browser
.
elementById
(
'page-content'
).
text
()).
toBe
(
'Content'
)
expect
(
await
browser
.
elementById
(
'page-content'
).
text
()).
toBe
(
'Content'
)
})
it
(
'shows a fallback when prefetch completed'
,
async
()
=>
{
const
resolveMetadataDuration
=
5000
const
browser
=
await
next
.
browser
(
'/metadata-await-promise'
)
if
(
!
isNextDev
)
{
await
waitFor
(
resolveMetadataDuration
+
500
)
}
await
browser
.
elementByCss
(
"[href='/metadata-await-promise/nested']"
)
.
click
()
if
(
!
isNextDev
)
{
expect
(
await
browser
.
waitForElementByCss
(
'#loading'
,
// Give it some time to commit
100
)
.
text
()
).
toEqual
(
'Loading'
)
expect
(
await
browser
.
elementByCss
(
'title'
).
text
()).
toBe
(
'Async Title'
)
expect
(
await
browser
.
elementByCss
(
'title'
).
text
()).
toBe
(
'Async Title'
)
})
await
waitFor
(
resolveMetadataDuration
+
500
)
}
expect
(
await
browser
.
elementById
(
'page-content'
).
text
()).
toBe
(
'Content'
)
})
})
})
})
...
...
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