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 causes additional requests to /_next/data/**/*.json and their reponses are empty {}. #59295

Closed
1 task done
inside opened this issue Dec 5, 2023 · 5 comments · Fixed by #60968
Closed
1 task done
Labels
bug Issue was opened via the bug report template. locked Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@inside
Copy link

inside commented Dec 5, 2023

Link to the code that reproduces this issue

https://github.com/inside/repro-next-data-empty-object

To Reproduce

  1. Clone this repo
  2. npm install
  3. npm run build
  4. npm start
  5. Open your browser to http://localhost:3000
  6. Open the devtools
  7. Go to the network tab
  8. Notice each additional _next/data request for each link to a page

network-tab

  1. Click on either of the request
  2. Click on the Response tab
  3. Notice the empty json response like this {}

request-response

Current vs. Expected behavior

BUG:

When a middleware is active like this one: src/middleware.js, additional requests are made with an empty response {}.

A request url example looks like this: http://localhost:3000/_next/data/K-vmVE_c03yQwV9UdiOv2/page1.json and its reponse is empty {}.

EXPECTED BEHAVIOR:

No additional request should be performed. This is the case if you deactivate the middleware.

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: #99~20.04.1-Ubuntu SMP Thu Nov 2 15:16:47 UTC 2023
Binaries:
  Node: 20.10.0
  npm: 10.2.3
  Yarn: 1.22.21
  pnpm: 7.11.0
Relevant Packages:
  next: 14.0.4-canary.41
  eslint-config-next: 13.5.6
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.2
Next.js Config:
  output: N/A

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

Middleware / Edge (API routes, runtime)

Additional context

If you access the url http://localhost:3000/_next/data/K-vmVE_c03yQwV9UdiOv2/page1.json directly in your browser, the page1 will be displayed like if we are accessing this url http://localhost:3000/page1

@inside inside added the bug Issue was opened via the bug report template. label Dec 5, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Dec 5, 2023
@warpdesign
Copy link

warpdesign commented Dec 6, 2023

May already have been reported in #56157.
This appears to be intended?

@inside
Copy link
Author

inside commented Dec 6, 2023

It probably is. Nevertheless this features has caused huge traffic and cpu spikes and we rolled back the activation of nextjs middlewares. Moreover these requests aren't cached which can explain the spikes:

image

In the meantime, we will deactivate the link prefetch of next/link to move forward.

@inside
Copy link
Author

inside commented Feb 7, 2024

Hi, I've updated the reproduction repo with https://github.com/vercel/next.js/releases/tag/v14.1.1-canary.37 which contains the fix #60968 and I'm still encountering the issue.

@ijjk
Copy link
Member

ijjk commented Feb 7, 2024

In the latest canary these requests are no-ops, they shouldn't cause CPU spikes or incur additional rendering/data fetching and further in the latest version these requests won't have an incorrect status code.

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 22, 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 Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
3 participants