next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Next middleware requests wasteful .json file

Open mlstubblefield opened this issue 2 years ago • 1 comments

Verify canary release

  • [X] 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 Pro
Binaries:
  Node: 16.15.1
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 12.3.1-canary.2
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

not relevant

How are you deploying your application? (if relevant)

vercel

Describe the Bug

A minimal repro of the issue can be found here https://next-json-repro.vercel.app/ https://github.com/mlstubblefield/next-json-repro

When requesting a static page when you have middleware enabled, a .json file providing the static props is requested even though the data is already in the body of the html document. This did not happen prior to the recent middleware change (requiring middleware to be moved to the root directory among other changes).

Expected Behavior

Nextjs should just use the data in NEXT_DATA in the dom and not make the wasteful request.

Link to reproduction

https://github.com/mlstubblefield/next-json-repro

To Reproduce

This can be reproduced by browsing to https://next-json-repro.vercel.app/ You'll see the same data in the dom as well as the network request being made. image image While in my example this isn't an incredibly big deal, it is impactful on pages with much larger data sizes. As far as I can tell, this because of the "initialMatchesMiddleware" value is set in /next/dist/client/index.js Container's componentDidMount. image The shallow flag being set to true ultimately triggers these files to be requested (there might be a bit more to it than that, but it's a start).

mlstubblefield avatar Sep 15 '22 15:09 mlstubblefield

Seems like related with my issue too 😥

7iomka avatar Sep 15 '22 17:09 7iomka

Hi, I'm gonna close this in favor of https://github.com/vercel/next.js/issues/40611 as they are very closely related

ijjk avatar Oct 11 '22 20:10 ijjk

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[bot] avatar Nov 11 '22 00:11 github-actions[bot]