Unverified Commit ae1efa41 authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

bugfix: aliased prefetches should flow through PPR handling (#69476)

I was previously incorrectly excluding aliased entries from flowing
through the PPR path. However, since accessing `searchParams` will
postpone, the aliased entry is safe to flow through the PPR branch. When
PPR is enabled and the non-PPR branch attempts to handle this
navigation, it won't know how to handle the postponed response.

Separately, I noticed that the PPR branch was not spawning a pending
task if the page segment contained search params, because it was
checking for strict equality, when in reality it'd be something like
`__PAGE__?{'foo':'bar'}`

Fixes #69437
Closes NDX-255
parent addafa51
...@@ -125,6 +125,12 @@ export function updateCacheNodeOnNavigation( ...@@ -125,6 +125,12 @@ export function updateCacheNodeOnNavigation(
const oldSegmentChild = const oldSegmentChild =
oldRouterStateChild !== undefined ? oldRouterStateChild[0] : undefined oldRouterStateChild !== undefined ? oldRouterStateChild[0] : undefined
// A dynamic segment will be an array, and doesn't correspond with a page segment.
const isPageSegment = Array.isArray(newSegmentChild)
? false
: // A page segment might contain search parameters, so we verify that it starts with the page segment key.
newSegmentChild.startsWith(PAGE_SEGMENT_KEY)
const oldCacheNodeChild = const oldCacheNodeChild =
oldSegmentMapChild !== undefined oldSegmentMapChild !== undefined
? oldSegmentMapChild.get(newSegmentKeyChild) ? oldSegmentMapChild.get(newSegmentKeyChild)
...@@ -136,7 +142,7 @@ export function updateCacheNodeOnNavigation( ...@@ -136,7 +142,7 @@ export function updateCacheNodeOnNavigation(
// We spawn a "task" just to keep track of the updated router state; unlike most, it's // We spawn a "task" just to keep track of the updated router state; unlike most, it's
// already fulfilled and won't be affected by the dynamic response. // already fulfilled and won't be affected by the dynamic response.
taskChild = spawnReusedTask(oldRouterStateChild) taskChild = spawnReusedTask(oldRouterStateChild)
} else if (newSegmentChild === PAGE_SEGMENT_KEY) { } else if (isPageSegment) {
// This is a leaf segment — a page, not a shared layout. We always apply // This is a leaf segment — a page, not a shared layout. We always apply
// its data. // its data.
taskChild = spawnPendingTask( taskChild = spawnPendingTask(
......
...@@ -215,7 +215,6 @@ export function navigateReducer( ...@@ -215,7 +215,6 @@ export function navigateReducer(
// an incremental step. // an incremental step.
seedData && seedData &&
isRootRender && isRootRender &&
!prefetchValues.aliased &&
postponed postponed
) { ) {
const task = updateCacheNodeOnNavigation( const task = updateCacheNodeOnNavigation(
......
import Link from 'next/link' import Link from 'next/link'
export default function Page() { export default function Page({ searchParams }) {
return ( return (
<> <>
<div id="root-params">{JSON.stringify(searchParams)}</div>
<Link href="/search">Go to search</Link> <Link href="/search">Go to search</Link>
<hr /> <hr />
......
...@@ -11,6 +11,7 @@ export default async function Page({ ...@@ -11,6 +11,7 @@ export default async function Page({
<> <>
<h1 id="params">{JSON.stringify(searchParams)}</h1> <h1 id="params">{JSON.stringify(searchParams)}</h1>
<Link href="/">Back</Link> <Link href="/">Back</Link>
<Link href="/?id=1">/id=1</Link>
</> </>
) )
} }
...@@ -31,6 +31,13 @@ describe('searchparams-reuse-loading', () => { ...@@ -31,6 +31,13 @@ describe('searchparams-reuse-loading', () => {
expect(await newSearchValue.text()).toBe('Search Value: another') expect(await newSearchValue.text()).toBe('Search Value: another')
}) })
it('should properly render root page with searchParams when prefetch is aliased', async () => {
const browser = await next.browser('/search-params')
await browser.elementByCss("[href='/?id=1']").click()
const params = await browser.waitForElementByCss('#root-params').text()
expect(params).toBe('{"id":"1"}')
})
// Dev doesn't perform prefetching, so this test is skipped, as it relies on intercepting // Dev doesn't perform prefetching, so this test is skipped, as it relies on intercepting
// prefetch network requests. // prefetch network requests.
if (!isNextDev) { if (!isNextDev) {
......
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