Skip to content

fix(example): flatten Windows segment prefetch files in react demo - #131

Merged
vannt-dev merged 1 commit into
developfrom
fix/react-demo-prefetch
Oct 22, 2026
Merged

vannt-dev merged 1 commit into
developfrom
fix/react-demo-prefetch

Conversation

@vannt-dev

Copy link
Copy Markdown
Owner

What

The React demo logged three 404s on load when built on Windows:
GET /wizard/__next.wizard.__PAGE__.txt?_rsc=... (same for /new-features/, /schema-form/).

Root cause

A Next.js 16 static export bug on Windows, not our config
(vercel/next.js#85374, open; fix in
#92340, not merged; still in canary).
The export collects segment files with path.relative, which returns backslashes on Windows,
and only turns / into .. So a Windows build writes wizard/__next.wizard/__PAGE__.txt
(a folder) while the client asks for wizard/__next.wizard.__PAGE__.txt.
No Next option (trailingSlash etc.) changes this.

The deployed site is built on ubuntu and is already clean: all 8 .txt prefetches return 200
and the console has no errors on https://vannt-dev.github.io/dynamic-field-kit/react/.

Fix

example/react-app/scripts/flatten-segment-files.js, wired as postbuild, moves any file
under an out/**/__next.*/ folder back to the flat, dotted name. It does nothing on
Linux/macOS. Remove it once the upstream fix ships. Prefetching stays on.

Verification (Windows, Chromium via Playwright, python -m http.server)

  • Before, PAGES_BASE_PATH=/dynamic-field-kit/react: 3 console errors, the three
    __PAGE__.txt prefetches 404.
  • After, same base path: 0 console errors, all __PAGE__.txt and _tree.txt prefetches 200.
    Clicked Wizard, JSON Schema + Undo, Form state, Basics: URL and heading change and a
    window marker survives, so navigation is client-side.
  • After, no base path (served at /): same result, 0 errors, 0 404s in the server log.
  • Running the script again on a flat out/ is a no-op.

Empty changeset: no published package changes.

Next 16 static export names each segment prefetch file from path.relative,
which gives backslashes on Windows, so a Windows build writes
wizard/__next.wizard/__PAGE__.txt instead of wizard/__next.wizard.__PAGE__.txt.
Every link prefetch then 404s on load (vercel/next.js#85374, fix in #92340).

A postbuild step moves those files back to the flat, dotted name. Linux
builds (the Pages workflow) have no such folders, so it is a no-op there.
@vannt-dev
vannt-dev merged commit 547ab64 into develop Oct 22, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant