-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland static prefetches & fix prefetch bailout behavior (#56228)
Reland #54403 Also modifies the implementation of #55950 to not change the prefetch behavior when there is flight router state - we should only check the entire loader tree in the static prefetch case, otherwise we're inadvertently rendering the component tree for prefetches that match the current flight router state segment. ([slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1695862974745849)) This includes a few other misc fixes for static prefetch generation: - `next start` was not serving them (which also meant tests weren't catching a few small bugs) - the router cache key casing can differ between build and runtime, resulting in a bad cache lookup which results suspending indefinitely during navigation - We cannot generate static prefetches for pages that opt into `searchParams`, as the prefetch response won't have the right cache key in the RSC payload - Layouts that use headers/cookies shouldn't use a static prefetch because it can result in unexpected behavior (ie, being redirected to a login page, if the prefetch contains redirect logic for unauthed users) Closes NEXT-1665 Closes NEXT-1643
- Loading branch information
Showing
31 changed files
with
474 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
test/e2e/app-dir/app-prefetch-static/app-prefetch-static.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
import { waitFor } from 'next-test-utils' | ||
|
||
createNextDescribe( | ||
'app-prefetch-static', | ||
{ | ||
files: __dirname, | ||
}, | ||
({ next, isNextDev }) => { | ||
if (isNextDev) { | ||
it('should skip next dev', () => {}) | ||
return | ||
} | ||
|
||
it('should correctly navigate between static & dynamic pages', async () => { | ||
const browser = await next.browser('/') | ||
// Ensure the page is prefetched | ||
await waitFor(1000) | ||
|
||
await browser.elementByCss('#static-prefetch').click() | ||
|
||
expect(await browser.elementByCss('#static-prefetch-page').text()).toBe( | ||
'Hello from Static Prefetch Page' | ||
) | ||
|
||
await browser.elementByCss('#dynamic-prefetch').click() | ||
|
||
expect(await browser.elementByCss('#dynamic-prefetch-page').text()).toBe( | ||
'Hello from Dynamic Prefetch Page' | ||
) | ||
|
||
await browser.elementByCss('#static-prefetch').click() | ||
|
||
expect(await browser.elementByCss('#static-prefetch-page').text()).toBe( | ||
'Hello from Static Prefetch Page' | ||
) | ||
}) | ||
} | ||
) |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/app-prefetch-static/app/[region]/(default)/dynamic-area/[slug]/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default async function DynamicPage({ params, searchParams }) { | ||
return <div id="dynamic-prefetch-page">Hello from Dynamic Prefetch Page</div> | ||
} |
13 changes: 13 additions & 0 deletions
13
test/e2e/app-dir/app-prefetch-static/app/[region]/(default)/layout.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const regions = ['SE', 'DE'] | ||
|
||
export default async function Layout({ children, params }) { | ||
return children | ||
} | ||
|
||
export function generateStaticParams() { | ||
return regions.map((region) => ({ | ||
region, | ||
})) | ||
} | ||
|
||
export const dynamicParams = false |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/app-prefetch-static/app/[region]/(default)/static-prefetch/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const dynamic = 'force-dynamic' | ||
|
||
export default async function StaticPrefetchPage({ params }) { | ||
return ( | ||
<div id="static-prefetch-page"> | ||
<h1>Hello from Static Prefetch Page</h1> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Link from 'next/link' | ||
export default function RootLayout({ children }) { | ||
return ( | ||
<html> | ||
<body> | ||
{children} | ||
|
||
<Link href="/se/static-prefetch" id="static-prefetch"> | ||
Static Prefetch | ||
</Link> | ||
<Link href="/se/dynamic-area/slug" id="dynamic-prefetch"> | ||
Dynamic Prefetch | ||
</Link> | ||
</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Main() { | ||
return <div>Main Page</div> | ||
} |
Oops, something went wrong.