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

shallow: true calls the middleware when using middlewares #32655

Closed
hacknlove opened this issue Dec 19, 2021 · 2 comments · Fixed by #35047
Closed

shallow: true calls the middleware when using middlewares #32655

hacknlove opened this issue Dec 19, 2021 · 2 comments · Fixed by #35047
Labels
Middleware Related to Next.js Middleware

Comments

@hacknlove
Copy link

hacknlove commented Dec 19, 2021

What version of Next.js are you using?

12.0.7

What version of Node.js are you using?

v16.6.1

What browser are you using?

Crhome, Firefox

What operating system are you using?

Ubuntu

How are you deploying your application?

vercel

Describe the Bug

Shallow: true does not work, when

// pages/some/path.js
  router.push('/some/path', as, { shallow: true })
// /pages/_middleware.js
export function middleware(req) {
  return NextResponse.next()
}

the middleware is executed.

Expected Behavior

The documentation says nothing about middleware.

https://nextjs.org/docs/routing/shallow-routing

I excepted shallow-routing to be pure client-side. Calling the middleware slows down the UX.

If calling the middleware is the right behavior, I think the documentation should be updated, and also a new option might be needed, like {clientOnly: true} to prevent the middleware to be called, when you want a pure client-side interaction.

To Reproduce

https://codesandbox.io/s/happy-shannon-1dd78?file=/pages/index.js

@hacknlove hacknlove added the bug Issue was opened via the bug report template. label Dec 19, 2021
@hacknlove
Copy link
Author

For my case use, I workarounded this with

import { resolveHref } from 'next/dist/shared/lib/router/router';

history.pushState(newData, '', resolveHref(null, {
        pathName: xxx
        query: {...}
  }))

@balazsorban44 balazsorban44 added Middleware Related to Next.js Middleware kind: bug and removed bug Issue was opened via the bug report template. labels Jan 17, 2022
@javivelasco javivelasco added this to the Next.js Middleware GA milestone Feb 18, 2022
@kodiakhq kodiakhq bot closed this as completed in #35047 Mar 8, 2022
kodiakhq bot pushed a commit that referenced this issue Mar 8, 2022
…all wit… (#35047)

…h query parameter

Fixes #32655 and fixes #35006

## Bug

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

github-actions bot commented Apr 8, 2022

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 Apr 8, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants