Unverified Commit 412992ad authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

fix: prevent infinite dev refresh on nested parallel routes (#52362)

### What?
HMR causes infinite reloads for parallel routes when the corresponding page component is nested

### Why?
In 4900fa21b078fd1ec1adc5d570fcfb560be8aeb6, code was added to remove `/@children` from the page path (if present) but in 59b36349eb86427ac7b679ac62fa6628c9fc4886, `normalizeParallelKey` removes the @ prefix from children, so this doesn't seem to be catching the scenario it was intended to prevent

### How?
This updates the existing replace logic to consider `/children/page` rather than `/@children/page` -- it doesn't seem like `/@children` is a valid scenario given the `normalizeParallelKey` behavior

Fixes #52342 and addresses the concerns in https://github.com/vercel/next.js/pull/52061#issuecomment-1619145129 
parent eb3d7487
...@@ -98,9 +98,9 @@ export function getEntryKey( ...@@ -98,9 +98,9 @@ export function getEntryKey(
pageBundleType: 'app' | 'pages' | 'root', pageBundleType: 'app' | 'pages' | 'root',
page: string page: string
) { ) {
// TODO: handle the /@children slot better // TODO: handle the /children slot better
// this is a quick hack to handle when children is provided as @children/page instead of /page // this is a quick hack to handle when children is provided as children/page instead of /page
return `${compilerType}@${pageBundleType}@${page.replace(/\/@children/g, '')}` return `${compilerType}@${pageBundleType}@${page.replace(/\/children/g, '')}`
} }
function getPageBundleType(pageBundlePath: string) { function getPageBundleType(pageBundlePath: string) {
......
export default function ParallelPage() {
return (
<>
<p>Hello from nested parallel page!</p>
<div id="timestamp">{Date.now()}</div>
</>
)
}
export default function Layout({ parallelB }: { parallelB: React.ReactNode }) {
return (
<main>
<h3>{`(parallelB)`}</h3>
<div>{parallelB}</div>
</main>
)
}
export default function Parallel({ children }) {
return (
<div>
parallel/layout:
<div className="parallel" title="children">
{children}
</div>
</div>
)
}
...@@ -354,6 +354,21 @@ createNextDescribe( ...@@ -354,6 +354,21 @@ createNextDescribe(
return newTimestamp !== timestamp ? 'failure' : 'success' return newTimestamp !== timestamp ? 'failure' : 'success'
}, 'success') }, 'success')
}) })
it('should support nested parallel routes', async () => {
const browser = await next.browser('parallel-nested/home/nested')
const timestamp = await browser.elementByCss('#timestamp').text()
await new Promise((resolve) => {
setTimeout(resolve, 3000)
})
await check(async () => {
// an invalid response triggers a fast refresh, so if the timestamp doesn't update, this behaved correctly
const newTimestamp = await browser.elementByCss('#timestamp').text()
return newTimestamp !== timestamp ? 'failure' : 'success'
}, 'success')
})
} }
}) })
......
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