vercel / vercel/next.js

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

Open
#63,199 6 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Pages Router
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction project at https://github.com/fmacherey/poc-ssg and its next.config, then run yarn build && yarn start. Inspect the _next/data requests while navigating between /lexikon/a, /lexikon/b, and /lexikon/c, focusing on the differing dict and lexikon paths. Done means the rewritten SSG page no longer produces the incorrect HEAD request or requests the correct internal dict file.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, react
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.