Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix prefetching for static app paths #41398

Merged
merged 2 commits into from Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/next/server/base-server.ts
Expand Up @@ -1064,6 +1064,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
) {
delete req.headers['__rsc__']
delete req.headers['__next_router_state_tree__']
delete req.headers['__next_router_prefetch__']
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/app-dir/app-prefetch/app/dashboard/[id]/page.js
Expand Up @@ -8,6 +8,10 @@ async function getData() {
}
}

export function generateStaticParams() {
return [{ id: 'static' }]
}

export default function IdPage({ params }) {
const data = use(getData())
console.log(data)
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/app-dir/app-prefetch/app/dashboard/page.js
@@ -1,5 +1,9 @@
import { experimental_use as use } from 'react'

export const config = {
revalidate: 0,
}

async function getData() {
await new Promise((resolve) => setTimeout(resolve, 3000))
return {
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/app-dir/app-prefetch/app/layout.js
@@ -1,7 +1,3 @@
export const config = {
revalidate: 0,
}

export default function Root({ children }) {
return (
<html>
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/app-dir/prefetching.test.ts
Expand Up @@ -55,4 +55,13 @@ describe('app dir prefetching', () => {
'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')
})
})