Skip to content

Pages router data requests returning 404 when middleware is used #2471

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

Open
serhalp opened this issue Jun 13, 2024 · 1 comment
Open

Pages router data requests returning 404 when middleware is used #2471

serhalp opened this issue Jun 13, 2024 · 1 comment
Labels
Next.js e2e test failure Errors identified through the Next.js repo e2e tests Next.js

Comments

@serhalp
Copy link
Member

serhalp commented Jun 13, 2024

On sites that use pages router and have middleware, loading a page using next/link will attempt to load a JSON file, which will return a 404. If there is no middleware then it works fine. This applies even if the middleware does nothing.

Data

The following is parsed automatically by the Next.js repo e2e test report generator.

test: test/e2e/middleware-base-path/test/index.test.ts
reason: Pages router data requests returning 404 when middleware is used
test case: "Middleware base tests router.query must exist when Link clicked page routing"

@serhalp serhalp added type: bug code to address defects in shipped code Next.js e2e test failure Errors identified through the Next.js repo e2e tests labels Jun 13, 2024
@orinokai orinokai closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2024
@orinokai orinokai reopened this Jun 14, 2024
@serhalp serhalp added the Next.js label Jun 14, 2024 — with Linear
@serhalp serhalp removed the type: bug code to address defects in shipped code label Jun 14, 2024
@mrbalov
Copy link

mrbalov commented May 21, 2025

We have reported this problem to the Netlify Team several times already. Looks like it doesn't cause pages to be 404; however, I'm not 100% sure and still gathering the statistics.

As a local solution, we agreed with the team to make some pages fully static where it is possible: to make sure that the page is generated during the build time, and it does not crash due to the 404 issue. But it doesn't work for pages that require ISR, and they are at risk.

Chat GPT suggested checking cache policies for static assets and making sure that static assets are not cached and are always revalidated. Previously, we had problems with indefinitely cached 404 pages that were created on the fly (probably, not related to this 404 issue with the middleware). You can set/update cache policy for static assets in the netlify.toml file, if you host your website on Netlify.

Hopefully, there will be a solution to this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Next.js e2e test failure Errors identified through the Next.js repo e2e tests Next.js
Projects
None yet
Development

No branches or pull requests

3 participants