question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

12.1.3-canary.0 breaks catch-all dynamic routes with Edge runtime

See original GitHub issue

Verify 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

  1. Add a file at /pages/[capture-a]/something/[capture-b]/[...capture-c].server.tsx
  2. Run next dev
  3. See the error in your terminal

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
balazsorban44commented, Mar 29, 2022

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

1reaction
leocommented, Mar 29, 2022

Ah, interesting!

Should the kind: bug label be assigned too then?

Removed my own repo, btw, now that you’ve created one too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Routes - Next.js
Dynamic Routes are pages that allow you to add custom params to your URLs. Start creating Dynamic Routes and learn more here.
Read more >
Catch all dynamic route in Next.js results in unwanted link in ...
I solved the issue by providing all path parameters instead of just an array of post ids. Solution: paths: [{params: {postId: ['Python', ...
Read more >
Implementing SSR in Next.js: Dynamic routing and prefetching
Server-side rendering (SSR) has become a widely adopted technique to enhance the performance and SEO of web applications. And while static site ...
Read more >
VMware SD-WAN Routing Overview
Tie-Breaking Scenarios for Dynamic Routes. What happens when an Edge receives the same prefix for two or more sources/neighbors? A potential ...
Read more >
Routing - Astro Documentation
An Astro page file can specify dynamic route parameters in its filename to generate matching pages. For example, you might create an authors/[author].astro ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found