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

Middleware breaks dynamic routes param matching #37753

Closed
1 task done
danielchabr opened this issue Jun 16, 2022 · 1 comment · Fixed by #37784
Closed
1 task done

Middleware breaks dynamic routes param matching #37753

danielchabr opened this issue Jun 16, 2022 · 1 comment · Fixed by #37784

Comments

@danielchabr
Copy link

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.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T8101
Binaries:
  Node: 16.15.0
  npm: 8.5.5
  Yarn: 1.22.10
  pnpm: N/A
Relevant packages:
  next: 12.1.7-canary.40
  react: 17.0.2
  react-dom: 17.0.2

What browser are you using? (if relevant)

Brave Version 1.39.111 Chromium: 102.0.5005.61 (Official Build) (arm64)

How are you deploying your application? (if relevant)

next dev

Describe the Bug

Adding middleware.ts to root of project breaks dynamic routes like [id]. The pages are correctly routed but router.query returns empty object even if the dynamic route matched the URL.

This behavior started appearing in v12.1.7-canary.34. Likely PR that broke this is #37574

Expected Behavior

router.query from useRouter should return { id: 'first' } if I go to /post/first and there is file pages/post/[id].js

To Reproduce

I reproduced using dynamic routing example: https://github.com/vercel/next.js/tree/canary/examples/dynamic-routing
Then bumping next version to 12.1.7-canary.40 and adding middleware.ts to root:

import { NextResponse } from 'next/server'

export async function middleware() {
  return NextResponse.next()
}

Then I run yarn next dev and go to http://localhost:3000/post/first
There should be "Post: first" but there is just "Post: " because router.query === {}
image

@danielchabr danielchabr added the bug Issue was opened via the bug report template. label Jun 16, 2022
@ijjk ijjk closed this as completed Jun 16, 2022
@ijjk ijjk reopened this Jun 16, 2022
@balazsorban44 balazsorban44 added kind: bug and removed bug Issue was opened via the bug report template. labels Jun 17, 2022
@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 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants