Unverified Commit 44304f00 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

Ensure custom Suspense boundaries in layouts resolve if they contain the page (#74552)

Co-authored-by: 's avatarZack Tanner <1939140+ztanner@users.noreply.github.com>
parent afdaf1ab
...@@ -389,6 +389,9 @@ function InnerLayoutRouter({ ...@@ -389,6 +389,9 @@ function InnerLayoutRouter({
return serverResponse return serverResponse
}) })
// Suspend while waiting for lazyData to resolve
use(lazyData)
} }
// Suspend infinitely as `changeByServerResponse` will cause a different part of the tree to be rendered. // 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. // A falsey `resolvedRsc` indicates missing data -- we should not commit that branch, and we need to wait for the data to arrive.
......
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
import { Suspense } from 'react'
import Link from 'next/link'
export const dynamic = 'force-dynamic'
export default async function Layout(props) {
return (
<>
<div>
<Link href={`/`} className="text-blue-500">
Home Page
</Link>
</div>
<Suspense fallback={<h1>Loading...</h1>}>{props.children}</Suspense>
</>
)
}
export default function NestedPage() {
return (
<>
<h1 data-testid="nested-resolved">This is the nested Page</h1>
</>
)
}
import Link from 'next/link'
export default function Home() {
return (
<>
<div>
<Link href={`/nested`} className="text-blue-500">
nested Page
</Link>
</div>
<h1>This is the Home Page</h1>
</>
)
}
import { nextTestSetup } from 'e2e-utils'
describe('app dir - navigation with Suspense in nested layout', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('resolves data after client navigation to a nested layout with Suspense', async () => {
const browser = await next.browser('/nested')
await browser.waitForElementByCss('[data-testid="nested-resolved"]')
await browser.waitForElementByCss('a[href="/"]').click()
await browser.waitForElementByCss('a[href="/nested"]').click()
await browser.waitForElementByCss('[data-testid="nested-resolved"]')
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment