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

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

Closed
1 task done
leo opened this issue Mar 29, 2022 · 9 comments
Closed
1 task done

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

leo opened this issue Mar 29, 2022 · 9 comments
Labels
Middleware Related to Next.js Middleware Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@leo
Copy link
Contributor

leo commented Mar 29, 2022

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 #32601 (I verified that #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
@leo leo added the bug Issue was opened via the bug report template. label Mar 29, 2022
@balazsorban44 balazsorban44 added area: Server Components Navigation Related to Next.js linking (e.g., <Link>) and navigation. labels Mar 29, 2022
@balazsorban44
Copy link
Member

balazsorban44 commented Mar 29, 2022

Could you link to a reproduction? I am unable to reproduce 🤔 :

// pages/[capture-a]/something/[capture-b]/[...capture-c].server.jsx

export const config = { runtime: "edge" }

export default function Page({router}) {
  return <pre>{JSON.stringify(router, null, 2)}</pre>
}

image

@leo
Copy link
Contributor Author

leo commented Mar 29, 2022

The error only seems to be happening if this is set within the page:

// Next.js currently requires this because of:
// https://github.com/vercel/next.js/issues/35633
export const config = { runtime: 'edge' };

@leo leo changed the title 12.1.3-canary.0 breaks catch-all dynamic routes 12.1.3-canary.0 breaks catch-all dynamic routes with Edge runtime Mar 29, 2022
@balazsorban44
Copy link
Member

Updated my example above, does not reproduce still. Could you distill the problem into a repository and link to it so we can investigate further? 🙏

@balazsorban44 balazsorban44 added please add a complete reproduction The issue lacks information for further investigation and removed bug Issue was opened via the bug report template. labels Mar 29, 2022
@leo
Copy link
Contributor Author

leo commented Mar 29, 2022

Here you go: next-dynamic-routes-bug.

CleanShot 2022-03-29 at 12 33 07@2x

@balazsorban44 balazsorban44 added type: needs investigation and removed please add a complete reproduction The issue lacks information for further investigation labels Mar 29, 2022
@balazsorban44
Copy link
Member

balazsorban44 commented 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

@balazsorban44 balazsorban44 added Middleware Related to Next.js Middleware and removed type: needs investigation labels Mar 29, 2022
@leo
Copy link
Contributor Author

leo commented 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.

@leo
Copy link
Contributor Author

leo commented Apr 6, 2022

Seems like the bug might've been reverted here (will test with the next stable): 9805399

@javivelasco
Copy link
Member

Indeed, closing it.

@github-actions
Copy link
Contributor

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 github-actions bot locked as resolved and limited conversation to collaborators May 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Middleware Related to Next.js Middleware Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

No branches or pull requests

3 participants