Skip to content

Commit a1d830e

Browse files
authored
Fix prefetching for static app paths (vercel#41398)
Ensures we delete the prefetch header when the path is static as it can't be honored and the full tree must be sent instead. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` x-ref: [slack thread](https://vercel.slack.com/archives/C035J346QQL/p1665610012952039?thread_ts=1665582783.184029&cid=C035J346QQL)
1 parent 5cd31e4 commit a1d830e

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

packages/next/server/base-server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
10641064
) {
10651065
delete req.headers['__rsc__']
10661066
delete req.headers['__next_router_state_tree__']
1067+
delete req.headers['__next_router_prefetch__']
10671068
}
10681069
}
10691070
}

test/e2e/app-dir/app-prefetch/app/dashboard/[id]/page.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ async function getData() {
88
}
99
}
1010

11+
export function generateStaticParams() {
12+
return [{ id: 'static' }]
13+
}
14+
1115
export default function IdPage({ params }) {
1216
const data = use(getData())
1317
console.log(data)

test/e2e/app-dir/app-prefetch/app/dashboard/page.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { experimental_use as use } from 'react'
22

3+
export const config = {
4+
revalidate: 0,
5+
}
6+
37
async function getData() {
48
await new Promise((resolve) => setTimeout(resolve, 3000))
59
return {

test/e2e/app-dir/app-prefetch/app/layout.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
export const config = {
2-
revalidate: 0,
3-
}
4-
51
export default function Root({ children }) {
62
return (
73
<html>

test/e2e/app-dir/prefetching.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ describe('app dir prefetching', () => {
5555
'Welcome to the dashboard'
5656
)
5757
})
58+
59+
it('should not have prefetch error for static path', async () => {
60+
const browser = await webdriver(next.url, '/')
61+
await browser.eval('window.nd.router.prefetch("/dashboard/123")')
62+
await waitFor(3000)
63+
await browser.eval('window.nd.router.push("/dashboard/123")')
64+
expect(next.cliOutput).not.toContain('ReferenceError')
65+
expect(next.cliOutput).not.toContain('is not defined')
66+
})
5867
})

0 commit comments

Comments
 (0)