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

Adding a middleware causing router.query to be empty when rewrite happens #42463

Closed
1 task done
moroshko opened this issue Nov 4, 2022 · 3 comments · Fixed by #42818
Closed
1 task done

Adding a middleware causing router.query to be empty when rewrite happens #42463

moroshko opened this issue Nov 4, 2022 · 3 comments · Fixed by #42818
Labels
bug Issue was opened via the bug report template.

Comments

@moroshko
Copy link

moroshko commented Nov 4, 2022

Verify canary release

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

Provide environment information

    Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
    Binaries:
      Node: 16.13.0
      npm: 8.1.0
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.0.2-canary.3
      eslint-config-next: 13.0.2-canary.3
      react: 18.2.0
      react-dom: 18.2.0

What browser are you using? (if relevant)

Chrome 107.0.5304.87

How are you deploying your application? (if relevant)

Vercel, but it happens locally in dev

Describe the Bug

I have the following rewrite in next.config.js:

async rewrites() {
  return [
    {
      source: "/movies/:movieId/settings",
      destination: "/settings",
    },
  ];
}

When I visit /movies/123/settings, router.query is { "movieId": "123" }, as expected.

However, when I add an empty middleware.js file, router.query becomes {}.

middleware.js

export function middleware() {}

next 12.3.1 didn't have this issue.

Expected Behavior

router.query should be { "movieId": "123" } when adding middleware.js.

Link to reproduction

https://github.com/moroshko/next-13-rewrite-issue

To Reproduce

  1. yarn
  2. yarn dev
  3. Visit http://localhost:3000/movies/123/settings
  4. Observe an empty router.query in the console.
@moroshko moroshko added the bug Issue was opened via the bug report template. label Nov 4, 2022
@lechim
Copy link

lechim commented Nov 6, 2022

I have the same issue with next 13.0.2. Initial render from middleware gives empty object in router.query, but if I client side navigate to the dynamic route the router.query is correctly populated. When I remove middleware.ts the page work as expected, reverting to next 12.3.2 for the time being.

@22mahmoud
Copy link

I have the same issue as well, any workaround?

ijjk added a commit that referenced this issue Nov 15, 2022
x-ref: [slack
thread](https://vercel.slack.com/archives/C035J346QQL/p1668195556550659)
Fixes: #42463

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
@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 Dec 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants