Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading navigation with metadata and prefetch #66447

Merged
merged 4 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/next/src/client/components/layout-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,10 @@ function InnerLayoutRouter({
// It's important that we mark this as resolved, in case this branch is replayed, we don't want to continously re-apply
// the patch to the tree.
childNode.lazyDataResolved = true

// Suspend infinitely as `changeByServerResponse` will cause a different part of the tree to be rendered.
use(unresolvedThenable) as never
}
// Suspend infinitely as `changeByServerResponse` will cause a different part of the tree to be rendered.
// A falsey `resolvedRsc` indicates missing data -- we should not commit that branch, and we need to wait for the data to arrive.
use(unresolvedThenable) as never
}

// We use `useDeferredValue` to handle switching between the prefetched and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
'use client'
import { useEffect } from 'react'

export default function Loading() {
useEffect(() => {
window.shownLoading = true
}, [])
return <div id="loading">Loading</div>
}
22 changes: 14 additions & 8 deletions test/e2e/app-dir/navigation/navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,16 +864,22 @@ describe('app dir - navigation', () => {
it('should render the final state of the page with correct metadata', async () => {
const browser = await next.browser('/metadata-await-promise')

await browser
.elementByCss("[href='/metadata-await-promise/nested']")
.click()
// dev doesn't trigger the loading boundary as it's not prefetched
if (isNextDev) {
await browser
.elementByCss("[href='/metadata-await-promise/nested']")
.click()
} else {
const loadingText = await browser
.elementByCss("[href='/metadata-await-promise/nested']")
.click()
.waitForElementByCss('#loading')
.text()

await retry(async () => {
// dev doesn't trigger the loading boundary as it's not prefetched
if (!isNextDev) {
expect(await browser.eval(`window.shownLoading`)).toBe(true)
}
expect(loadingText).toBe('Loading')
}

await retry(async () => {
expect(await browser.elementById('page-content').text()).toBe('Content')

expect(await browser.elementByCss('title').text()).toBe('Async Title')
Expand Down
Loading