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 middleware breaks 404 functionality on dynamic page for client side #43953

Closed
1 task done
TheMatrixan opened this issue Dec 12, 2022 · 5 comments
Closed
1 task done
Labels
bug Issue was opened via the bug report template.

Comments

@TheMatrixan
Copy link

Verify canary release

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

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Enterprise
Binaries:
  Node: 18.12.1
  npm: 8.19.2
  Yarn: 1.22.19
  pnpm: N/A
Relevant packages:
  next: 13.0.7-canary.4
  eslint-config-next: N/A       
  react: 18.2.0
  react-dom: 18.2.0

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

Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)

Link to the code that reproduces this issue

https://github.com/TheMatrixan/next-bug-middleware-dynamic-page

To Reproduce

  1. Go to home page, you will see list of links to 404, dynamic pages that exists and do not exists.
  2. Go to /dynamic/123 - this url should exists and should return dynamic component content - DynamicPage
  3. Go to /dynamic/789 - this url doesn't exist in dynamic path routes and when you go to that page, it will display DynamicPage instead of custom 404 page. BUT, when you refresh the page, it will display correct custom 404 page.
  4. When you delete that empty middleware, above mentioned bug will not occur. Just delete middleware.ts file and when you will click on link /dynamic/789, it will display correct 404 page.

Describe the Bug

By adding just empty function as a middleware, when we navigate to page that doesn't exist in static paths, next will show empty dynamic page content on client side instead of 404. When we delete middleware, Next will correctly show 404 page for page that doesn't exist.

Expected Behavior

link /dynamic/789 should display custom 404 page on client side while navigating between pages.

Which browser are you using? (if relevant)

Chrome 108.0.5359.95 (64-bits)

How are you deploying your application? (if relevant)

No response

@TheMatrixan TheMatrixan added the bug Issue was opened via the bug report template. label Dec 12, 2022
@TheMatrixan
Copy link
Author

Any updates?

@mataspetrikas
Copy link

mataspetrikas commented Jan 3, 2023

might be related or duplicate of the #44293.
it seems that that the default middleware reponse handler from NextResponse.next() chokes on the 404 pages since the 13.0 (reproducible in 13.1.1 as well)

@dgtllion
Copy link

dgtllion commented Jan 19, 2023

+1 will be nice to have it fixed!
In my case the 404 page keeps refreshing (loop).

@jankaifer
Copy link
Contributor

Closing as duplicate of #44293.

@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 Feb 19, 2023
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

No branches or pull requests

5 participants
@mataspetrikas @jankaifer @TheMatrixan @dgtllion and others