12.1.3-canary.0 breaks catch-all dynamic routes with Edge runtime
See original GitHub issueVerify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.4.0: Mon Feb 21 20:36:53 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T8101
Binaries:
Node: 16.14.0
npm: 8.3.1
Yarn: 1.22.17
pnpm: 6.30.1
Relevant packages:
next: 12.1.3-canary.0
react: 18.0.0-rc.1
react-dom: 18.0.0-rc.1
What browser are you using? (if relevant)
Chrome 99.0.4844.84
How are you deploying your application? (if relevant)
Vercel
Describe the Bug
Upgrading from 12.1.2-canary.1
to 12.1.3-canary.0
prevents next dev
from working:
[REDACTED]/node_modules/next/dist/shared/lib/router/utils/sorted-routes.js:62
throw new Error(`Catch-all must be the last part of the URL.`);
^
Error: Catch-all must be the last part of the URL.
at UrlNode._insert ([REDACTED]/node_modules/next/dist/shared/lib/router/utils/sorted-routes.js:62:19)
at UrlNode._insert ([REDACTED]/node_modules/next/dist/shared/lib/router/utils/sorted-routes.js:146:40)
at UrlNode._insert ([REDACTED]/node_modules/next/dist/shared/lib/router/utils/sorted-routes.js:146:40)
at UrlNode._insert ([REDACTED]/node_modules/next/dist/shared/lib/router/utils/sorted-routes.js:146:40)
at UrlNode._insert ([REDACTED]/node_modules/next/dist/shared/lib/router/utils/sorted-routes.js:146:40)
at UrlNode.insert ([REDACTED]/node_modules/next/dist/shared/lib/router/utils/sorted-routes.js:8:14)
at [REDACTED]/node_modules/next/dist/shared/lib/router/utils/sorted-routes.js:170:46
at Array.forEach (<anonymous>)
at Object.getSortedRoutes ([REDACTED]/node_modules/next/dist/shared/lib/router/utils/sorted-routes.js:170:21)
at Object.getRoutingItems ([REDACTED]/node_modules/next/dist/shared/lib/router/utils/routing-items.js:20:45)
The error isn’t being very clear, but I’m assuming it’s complaining about one of the dynamic routes I’ve configured. I have to guess which one it is, since the error doesn’t say that, but perhaps this one:
/pages/[capture-a]/something/[capture-b]/[...capture-c].server.tsx
After removing it, next dev
works just fine. It also worked just fine with 12.1.2-canary.1
, so this seems like a bug.
My guess is that it was caused by https://github.com/vercel/next.js/pull/32601 (I verified that https://github.com/vercel/next.js/issues/35451 is fixed, though, which I’ve reported a couple days ago).
Expected Behavior
I’d expect the behavior for the dynamic route mentioned above to be what it was with version 12.1.2-canary.1
and therefore not break when running next dev
.
To Reproduce
- Add a file at
/pages/[capture-a]/something/[capture-b]/[...capture-c].server.tsx
- Run
next dev
- See the error in your terminal
Issue Analytics
- State:
- Created a year ago
- Comments:9 (8 by maintainers)
Top GitHub Comments
Thanks! I could confirm a bug, but it is not related to experimental features. I created a more minimal reproduction myself here, using React 17 and no experimental features.
The only requirement for the bug to appear is
export const config = { runtime: "edge" }
in the page component.The PR #32601 indeed seems to be the problem.
When building the route nodes,
[ '[...capture-c]', '_middleware' ]
will be problematic, as previously it was not possible to have anything after a dynamic route path segment. That’s what’s throwing the error at:https://github.com/nkzawa/next.js/blob/a2accb22999ec12c49a3621f04d6b7d3567f00a3/packages/next/shared/lib/router/utils/sorted-routes.ts#L78
Ah, interesting!
Should the
kind: bug
label be assigned too then?Removed my own repo, btw, now that you’ve created one too.