next.js icon indicating copy to clipboard operation
next.js copied to clipboard

[Next.js 13][Routing][Pre-fetching] Dynamic route fails to pre-fetch (404)

Open Smirow opened this issue 2 years ago • 5 comments

I have already made a ticket for this, but i'm giving here some details.

Pre-fetching (with <Link> or router.prefetch()) dynamic routes like app/test/[testId]/leaf (with one segment over the dynamic param) throws a 404 Not Found on Vercel (the page exists). It works fine on next dev and next start and with other cloud providers.

You can try it here https://test-headers-vercel.vercel.app/test In the inspector you can see that pre-fetching /test/1 works as expected, pre-fetching /test/1/leaf throws a 404.

For /test/1 Capture d’écran 2022-10-31 à 11 43 34

For /test/1/leaf Capture d’écran 2022-10-31 à 11 43 28 (The first cache hit is a MISS, Vercel then caches it)

This forces a hard navigation to /test/1/leaf (probably related to this issue).

I haven't tried it on Next 12.

BTW: pre-fetching seems to work in dev, contrary to what is written in the beta doc

Smirow avatar Oct 31 '22 10:10 Smirow

You'll find the repo to reproduce here. Tested on Next 13.0.1.

Smirow avatar Nov 01 '22 08:11 Smirow

Strangely enough, when trying with testId=[testId], Vercel matches the corrected route (x-matched-path: /test/[testId]/leaf.rsc) and it works as expected (with testId=[testId] which is not really useful). Definitely something going on with rsc routing, like if it's missing the deprecated as= parameter.

Smirow avatar Nov 01 '22 09:11 Smirow

To help the investigation, rewriting the url in middleware.ts with the same url seems to fix the issue on Vercel:

return NextResponse.rewrite(new URL(request.nextUrl.pathname, request.url));

Smirow avatar Nov 01 '22 17:11 Smirow

@timneutkens thanks for the transfer, but to be clear and as mentioned, as far as my testing goes, this behavior is only replicable on Vercel.

Smirow avatar Nov 02 '22 17:11 Smirow

Still falls under our team's work, we'll investigate 👍

timneutkens avatar Nov 02 '22 17:11 timneutkens

Hi, this should be corrected now, please re-deploy your project and give it a try!

ijjk avatar Nov 09 '22 04:11 ijjk

Thanks @ijjk ! Working as expected.

Smirow avatar Nov 09 '22 07:11 Smirow

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

github-actions[bot] avatar Dec 09 '22 12:12 github-actions[bot]