Unverified Commit 60a847b0 authored by Josh Story's avatar Josh Story Committed by GitHub

Rewrite instant validation to use depth-based URL boundary discovery (#90905)

Instead of pre-planning validation tasks by walking the tree and
accumulating `navigationParents`, the new implementation drives
validation by URL depth. Starting from the deepest URL segment and
working backwards, it builds a combined payload at each depth where the
boundary between shared (already-mounted) and new (being-navigated-to)
content is determined by counting URL-consuming segments. If the new
subtree at that depth contains any `unstable_instant` configs, the
payload is validated. If not, it moves to the next shallower depth.

This approach has several advantages over the task-based model:

- Route group layouts no longer create spurious navigation boundaries —
they don\`t consume URL depth, so they naturally share the boundary of
their parent URL segment
- The `requiresInstantUI` requirement propagates correctly through the
tree: a local `false` config opts the subtree out, a non-false config
opts it in, and no config defers to the OR-union of children slots
- Both the static-stage and runtime-retry payloads are built in a single
tree walk, avoiding the separate retry pass
- The `<head>` stage correctly uses Runtime when any segment in the new
tree uses runtime prefetch
parent d1fcd201
......@@ -159,6 +159,31 @@ export default async function Page() {
</li>
</ul>
<h2>Route Groups</h2>
<ul>
<li>
<DebugLinks href="/suspense-in-root/static/route-group-config-only" />
</li>
<li>
<DebugLinks href="/suspense-in-root/static/route-group-config-and-segment-config" />
</li>
<li>
<DebugLinks href="/suspense-in-root/static/route-group-segment-config-only" />
</li>
<li>
<DebugLinks href="/suspense-in-root/static/route-group-config-with-deeper-segment/inner" />
</li>
<li>
<DebugLinks href="/suspense-in-root/static/route-group-deeper-segment-config/inner" />
</li>
<li>
<DebugLinks href="/suspense-in-root/static/route-group-shared-boundary" />
</li>
<li>
<DebugLinks href="/suspense-in-root/static/route-group-shared-boundary/foo" />
</li>
</ul>
<h2>Disable Validation</h2>
<ul>
<li>
......
import { ReactNode } from 'react'
export const unstable_instant = { prefetch: 'static' }
export default function GroupLayout({ children }: { children: ReactNode }) {
return (
<div>
<em>
This is a route group layout that also has unstable_instant (static)
</em>
<hr />
{children}
</div>
)
}
import { cookies } from 'next/headers'
export default async function Page() {
await cookies()
return (
<main>
<p>This page awaits cookies() without Suspense</p>
</main>
)
}
import { ReactNode } from 'react'
export const unstable_instant = { prefetch: 'static' }
export default function Layout({ children }: { children: ReactNode }) {
return (
<div>
<em>This is a URL-contributing layout with unstable_instant (static)</em>
<hr />
{children}
</div>
)
}
import { ReactNode } from 'react'
export const unstable_instant = { prefetch: 'static' }
export default function GroupLayout({ children }: { children: ReactNode }) {
return (
<div>
<em>This is a route group layout with unstable_instant (static)</em>
<hr />
{children}
</div>
)
}
import { cookies } from 'next/headers'
export default async function Page() {
await cookies()
return (
<main>
<p>This page awaits cookies() without Suspense</p>
</main>
)
}
import { ReactNode } from 'react'
export default function InnerLayout({ children }: { children: ReactNode }) {
return (
<div>
<em>This is a URL-contributing layout with no config</em>
<hr />
{children}
</div>
)
}
import { cookies } from 'next/headers'
export default async function Page() {
await cookies()
return (
<main>
<p>This page awaits cookies() without Suspense</p>
</main>
)
}
import { ReactNode } from 'react'
export const unstable_instant = { prefetch: 'static' }
export default function GroupLayout({ children }: { children: ReactNode }) {
return (
<div>
<em>This is a route group layout with unstable_instant (static)</em>
<hr />
{children}
</div>
)
}
import { ReactNode } from 'react'
export const unstable_instant = { prefetch: 'static' }
export default function InnerLayout({ children }: { children: ReactNode }) {
return (
<div>
<em>This is a URL-contributing layout with unstable_instant (static)</em>
<hr />
{children}
</div>
)
}
import { cookies } from 'next/headers'
export default async function Page() {
await cookies()
return (
<main>
<p>This page awaits cookies() without Suspense</p>
</main>
)
}
import { ReactNode } from 'react'
export default function GroupLayout({ children }: { children: ReactNode }) {
return (
<div>
<em>This is a route group layout with no config</em>
<hr />
{children}
</div>
)
}
import { ReactNode } from 'react'
export default function GroupLayout({ children }: { children: ReactNode }) {
return (
<div>
<em>This is a route group layout with no config</em>
<hr />
{children}
</div>
)
}
import { cookies } from 'next/headers'
export default async function Page() {
await cookies()
return (
<main>
<p>This page awaits cookies() without Suspense</p>
</main>
)
}
import { ReactNode } from 'react'
export const unstable_instant = { prefetch: 'static' }
export default function Layout({ children }: { children: ReactNode }) {
return (
<div>
<em>This is a URL-contributing layout with unstable_instant (static)</em>
<hr />
{children}
</div>
)
}
import { cookies } from 'next/headers'
import { ReactNode } from 'react'
// This layout awaits cookies() without its own Suspense boundary.
// When (outer)/layout is shared (e.g. navigating from /foo to /),
// there is no Suspense above this layout in the new tree, so
// the navigation will be blocking.
export default async function InnerLayout({
children,
}: {
children: ReactNode
}) {
await cookies()
return (
<div>
<em>Inner route group layout (awaits cookies, no Suspense)</em>
{children}
</div>
)
}
import Link from 'next/link'
export default function Page() {
return (
<main>
<p>Index page inside (inner) route group</p>
<Link href="/suspense-in-root/static/route-group-shared-boundary/foo">
./foo
</Link>
</main>
)
}
import Link from 'next/link'
export default function FooPage() {
return (
<main>
<p>Foo page (sibling of inner route group)</p>
<Link href="/suspense-in-root/static/route-group-shared-boundary">
./
</Link>
</main>
)
}
import { ReactNode, Suspense } from 'react'
// The unstable_instant config makes this route eligible for validation.
// The Suspense here covers children in the validation render (where both
// (outer) and (inner) are in the new tree), but in a real /foo → / client
// navigation, (outer)/layout is shared and its Suspense doesn't apply.
export const unstable_instant = { prefetch: 'static' }
export default function OuterLayout({ children }: { children: ReactNode }) {
return (
<div>
<em>Outer route group layout (has Suspense around children)</em>
<Suspense fallback={<div>Loading outer...</div>}>{children}</Suspense>
</div>
)
}
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