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

SSG pages with route rewrites request wrong files from _next/data #63199

Open
fmacherey opened this issue Mar 12, 2024 · 4 comments
Open

SSG pages with route rewrites request wrong files from _next/data #63199

fmacherey opened this issue Mar 12, 2024 · 4 comments
Labels
bug Issue was opened via the bug report template. Pages Router Related to Pages Router.

Comments

@fmacherey
Copy link
Contributor

fmacherey commented Mar 12, 2024

Link to the code that reproduces this issue

https://github.com/fmacherey/poc-ssg

To Reproduce

  1. yarn build && yarn start
  2. open page localhost:3000/lexikon/a
  3. open dev tools, filter network for "next/data"
  4. navigate between "a", "b" and "c"

Current vs. Expected behavior

You'll see several network requests for the static ssr json files e.g.

http://localhost:3000/_next/data/<BUILD_ID>/dict/b.json?character=b
http://localhost:3000/_next/data/<BUILD_ID>/lexikon/b.json?character=b

The first GET request is fine and correct, but the secondly listed HEAD request leads to a 404 Not Found.

Expected: the HEAD request should not occur or at least going correctly to the internal file "dict/b.json" and not the rewritten path (see next.config)

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Wed Feb 21 21:45:49 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 20.9.0
  npm: 10.1.0
  Yarn: 1.22.19
  pnpm: 8.15.1
Relevant Packages:
  next: 14.2.0-canary.17 // Latest available version is detected (14.2.0-canary.17).
  eslint-config-next: 14.1.3
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.2
Next.js Config:
  output: N/A
✨  Done in 1.45s.

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

Data fetching (gS(S)P, getInitialProps)

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

next build (local), next start (local)

Additional context

No response

@fmacherey fmacherey added the bug Issue was opened via the bug report template. label Mar 12, 2024
@github-actions github-actions bot added the Pages Router Related to Pages Router. label Mar 12, 2024
@cvolant
Copy link
Contributor

cvolant commented Mar 26, 2024

This issue probably comes from here, when Next sends "a HEAD request in the background when a non-prefetch request is made to signal revalidation", because the prefetches are fine, but the problem occurs on a client-side navigation (I mean it does not occurs on hard reload) to the page.

I tried to add the following to my rewrites and redirects, but it does not solve the problem:

{
  missing: [
    {
      type: 'header',
      key: 'x-nextjs-data',
    },
  ],
}

@gabor-at-reed
Copy link

We have a very similar issue. Up until 14.1.4, everything worked fine. But as soon as I upgrade to 14.2.0-canary.0, it starts happening.

The prefetch (.json) requests are 404 if the page is client-side rendered, but they load fine if SSR. If I open the page via a next/link, the page loads, but on the console there is an error: "Error: Failed to load static props".

With the latest 14.2.3 (or with the latest canary) it's even worse: the page is completely broken with a white screen and "Application error: a client-side exception has occurred (see the browser console for more information)." message if I open it via next/link, but after a page-reload, it loads just fine. 🤯

@lincolnremi
Copy link

I've noticed the same issue. Has anyone figured out a workaround?

@gabor-at-reed
Copy link

The v14.1.4 now has a high vulnerability issue, according to the NPM audit. The biggest issue is that the latest v14.2.12 still has the problem we mentioned above. Hence, we cannot upgrade.

The prefetch (.json) requests are 404 if the prefetched page is client-side rendered, but the prefetch request is fine if SSR.
Loading the pages either directly or via link is working fine.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Pages Router Related to Pages Router.
Projects
None yet
Development

No branches or pull requests

4 participants