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 returning empty 200 for old build ID instead of 404 #57207

Closed
1 task done
ben-propflo opened this issue Oct 22, 2023 · 9 comments
Closed
1 task done

Middleware returning empty 200 for old build ID instead of 404 #57207

ben-propflo opened this issue Oct 22, 2023 · 9 comments
Labels
bug Issue was opened via the bug report template. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation. Pages Router Related to Pages Router. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@ben-propflo
Copy link

ben-propflo commented Oct 22, 2023

Link to the code that reproduces this issue

https://github.com/ben-propflo/nextjs-middleware-deployment-repo

To Reproduce

  1. Clone the repro
  2. Run yarn build && yarn start
  3. Load http://localhost:3000/ssr and keep it open
  4. Stop Next.js
  5. Re-run yarn build && yarn start
  6. Click the SSR2 link, no SSR prop data is returned. A request is made to "http://localhost:3000/_next/data/build-id/ssr.json" which returns a 200 and an empty object. This will generally cause a client side exception as when rendering the page, props won't exist.

If you then delete middleware.ts and repeat the steps above, you'll notice that the request to _next/data/ will return a 404 which causes a new fetch to http://localhost:3000/ssr2 so everything works as expected.

Current vs. Expected behavior

Following the steps from the previous section, when using middleware I'd expect the same behaviour as when not using middleware. That is a 404 is returned so that the client re-fetches the page.

Verify canary release

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

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Fri Oct  6 19:02:35 UTC 2023
Binaries:
  Node: 18.18.0
  npm: 8.18.0
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 13.5.7-canary.14
  eslint-config-next: 13.5.6
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Data fetching (gS(S)P, getInitialProps), Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)

Additional context

I've gone back and tried previous versions of Next.js on my linked repro, the issue first starts appearing in v13.4.13-canary.0 (it works fine on 13.4.12)

@ben-propflo ben-propflo added the bug Issue was opened via the bug report template. label Oct 22, 2023
@github-actions github-actions bot added Pages Router Related to Pages Router. Runtime Related to Node.js or Edge Runtime with Next.js. Navigation Related to Next.js linking (e.g., <Link>) and navigation. labels Oct 22, 2023
@ben-propflo ben-propflo changed the title When using middleware, SSR pages will return a 200 and empty object for old clients after deployment When using middleware, SSR pages will return a 200 empty object for old clients after deployment Oct 22, 2023
@ben-propflo ben-propflo changed the title When using middleware, SSR pages will return a 200 empty object for old clients after deployment Out of date clients navigating to SSR pages will error when using middleware Oct 22, 2023
@ben-propflo ben-propflo changed the title Out of date clients navigating to SSR pages will error when using middleware 'Old' clients navigating to SSR pages will error when using middleware Oct 22, 2023
@EmilioAiolfi
Copy link

EmilioAiolfi commented Oct 23, 2023

Same happens with version 13.5.3 run with docker (self hosted)
Screenshot 2023-10-23 at 10 57 21

@ben-propflo
Copy link
Author

I've re-tested on v14.0.0 and that still has the same broken behaviour.

@ben-propflo
Copy link
Author

I've updated the repo to 14.0.3-canary.9 and the same broken behaviour still exists.

@ben-propflo
Copy link
Author

ben-propflo commented Nov 22, 2023

Did a bit more digging around, I think this might be the problem commit: 1398de9

PR from @ijjk: #53029

There are some changes in packages/next/src/server/next-server.ts, specifically L1228, where the buildId check disappears. The commit is rather massive so it might have been moved elsewhere?

@ben-propflo ben-propflo changed the title 'Old' clients navigating to SSR pages will error when using middleware Middleware returning empty 200 for invalid build ID instead of 404 Nov 25, 2023
@ben-propflo ben-propflo changed the title Middleware returning empty 200 for invalid build ID instead of 404 Middleware returning empty 200 for od build ID instead of 404 Nov 25, 2023
@ben-propflo ben-propflo changed the title Middleware returning empty 200 for od build ID instead of 404 Middleware returning empty 200 for old build ID instead of 404 Nov 25, 2023
@ben-propflo
Copy link
Author

Still reproducible on 14.0.5-canary.43

@ben-propflo
Copy link
Author

Updated the repro repo, the issue is still reproducible on 14.1.1-canary.7

@sabreu-teknorix
Copy link

Issue is still reproducible on 14.1.1-canary.27

@ben-propflo
Copy link
Author

This is resolved in v14.1.1-canary.37 🚀

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. 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 21, 2024
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. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation. Pages Router Related to Pages Router. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

3 participants