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

Intercepting Routes with Catch-all Segments broken #51784

Closed
1 task done
nowlena opened this issue Jun 25, 2023 · 1 comment · Fixed by #51787
Closed
1 task done

Intercepting Routes with Catch-all Segments broken #51784

nowlena opened this issue Jun 25, 2023 · 1 comment · Fixed by #51787
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@nowlena
Copy link

nowlena commented Jun 25, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023
Binaries:
  Node: 18.16.0
  npm: 9.5.1
  Yarn: N/A
  pnpm: 8.6.3
Relevant Packages:
  next: 13.4.8-canary.2
  eslint-config-next: 13.4.7
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Routing (next/router, next/navigation, next/link)

Link to the code that reproduces this issue or a replay of the bug

/~https://github.com/vercel-labs/nextgram

To Reproduce

It looks as though the pathing is broken when trying to use Catch-all Segments with Intercepting routes.

  • works: /(.)photo/[id]
  • breaks: /(.)photo/[...id]

Describe the Bug

The error that I receive is:

/node_modules/next/dist/compiled/path-to-regexp/index.js:47
    throw new TypeError("Missing parameter name at " + i);

TypeError: Missing parameter name at 9
    at lexer (/next/dist/compiled/path-to-regexp/index.js:47:23)
    at parse (/next/dist/compiled/path-to-regexp/index.js:97:18)
    at stringToRegexp (/next/dist/compiled/path-to-regexp/index.js:329:27)
    at pathToRegexp (/next/dist/compiled/path-to-regexp/index.js:403:12)
    at getPathMatch (/next/dist/shared/lib/router/utils/path-match.js:14:51)
    at getCustomRoute (/next/dist/server/server-route-utils.js:40:47)
    at buildRewrite (/next/dist/server/next-server.js:1408:75)
    at /next/dist/server/next-server.js:1476:79
    at Array.map (<anonymous>)
    at DevServer.generateRewrites (/next/dist/server/next-server.js:1476:70)
    at Watchpack.<anonymous> (/next/dist/server/dev/next-dev-server.js:576:50)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

note: I've shortened the paths to node_modules above

Expected Behavior

I'd expect this intercepting routes to work properly with catch-all segments

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@nowlena nowlena added the bug Issue was opened via the bug report template. label Jun 25, 2023
@github-actions github-actions bot added area: app App directory (appDir: true) Navigation Related to Next.js linking (e.g., <Link>) and navigation. labels Jun 25, 2023
ijjk pushed a commit that referenced this issue Jun 25, 2023
### What?
Interception route rewrites are not properly parsing catch-all segments,
which leads to "missing parameter name" errors when passed to
`pathToRegexp`.

### Why?
The existing `toPathToRegexpPath` function ignores `...` and keeps it as
part of the regexp path. This means `pathToRegexp` will attempt to
handle `/foo/bar/:...baz` and `/foo/bar/:[...baz]` rather than
`/foo/bar/:baz*`

### How?
The regex used for matching the path was updated to support the dynamic
optional segment, and then we special case catch-all segments

Fixes #51784

---------
@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 Jul 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant