Unverified Commit a1d830ee authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix prefetching for static app paths (#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)
parent 5cd31e41
...@@ -1064,6 +1064,7 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -1064,6 +1064,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
) { ) {
delete req.headers['__rsc__'] delete req.headers['__rsc__']
delete req.headers['__next_router_state_tree__'] delete req.headers['__next_router_state_tree__']
delete req.headers['__next_router_prefetch__']
} }
} }
} }
......
...@@ -8,6 +8,10 @@ async function getData() { ...@@ -8,6 +8,10 @@ async function getData() {
} }
} }
export function generateStaticParams() {
return [{ id: 'static' }]
}
export default function IdPage({ params }) { export default function IdPage({ params }) {
const data = use(getData()) const data = use(getData())
console.log(data) console.log(data)
......
import { experimental_use as use } from 'react' import { experimental_use as use } from 'react'
export const config = {
revalidate: 0,
}
async function getData() { async function getData() {
await new Promise((resolve) => setTimeout(resolve, 3000)) await new Promise((resolve) => setTimeout(resolve, 3000))
return { return {
......
export const config = {
revalidate: 0,
}
export default function Root({ children }) { export default function Root({ children }) {
return ( return (
<html> <html>
......
...@@ -55,4 +55,13 @@ describe('app dir prefetching', () => { ...@@ -55,4 +55,13 @@ describe('app dir prefetching', () => {
'Welcome to the dashboard' 'Welcome to the dashboard'
) )
}) })
it('should not have prefetch error for static path', async () => {
const browser = await webdriver(next.url, '/')
await browser.eval('window.nd.router.prefetch("/dashboard/123")')
await waitFor(3000)
await browser.eval('window.nd.router.push("/dashboard/123")')
expect(next.cliOutput).not.toContain('ReferenceError')
expect(next.cliOutput).not.toContain('is not defined')
})
}) })
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