-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the bug
When running the dev server with bun (bun --bun vite dev) hydration errors can occur. In practice these are intermittent but can be reproduced by anything that calls sync.create() (see reproduction steps below).
As best as I understand it, create_manifest_data assigns numeric node indices based on the order fs.readdirSync() returns directory entries. This ordering is not guaranteed by POSIX and differs between runtimes: node returns entries alphabetically, while bun returns them in filesystem/creation order.
This means the same project produces different client/app.js manifests depending on which runtime calls sync.create(). When the dev server's in-memory SSR manifest uses one ordering but the on-disk client manifest uses another, the SSR-emitted node_ids point to the wrong components, causing hydration failures and wrong page content.
This can happen if while you are running the dev server, you run a different command with node or your IDE or AI agent run something with node that triggers the sync.
Root cause (?)
packages/kit/src/core/sync/create_manifest_data/index.js line 217:
const files = fs.readdirSync(dir).map((name) => ({Node indices are assigned from this traversal order (line 416) before sort_routes() is called (line 464).
Reproduction
- Create a SvelteKit project with multiple route groups - e.g.
(app),(marketing) - Start the dev server with
bun --bun vite dev - In a separate terminal, run
sync.create()under Node:node --input-type=module -e ' import { load_config } from "./node_modules/@sveltejs/kit/src/core/config/index.js"; import * as sync from "./node_modules/@sveltejs/kit/src/core/sync/sync.js"; const config = await load_config(); sync.all(config, "development"); '
- Navigate to any route — wrong page content loads, console shows
HierarchyRequestError: The operation would yield an incorrect node tree
Logs
System Info
System:
OS: macOS 26.3
CPU: (10) arm64 Apple M1 Max
Memory: 179.69 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 25.6.0 - /opt/homebrew/bin/node
npm: 11.8.0 - /opt/homebrew/bin/npm
bun: 1.3.9 - /Users/jake/.bun/bin/bun
Browsers:
Chrome: 144.0.7559.134
Safari: 26.3
npmPackages:
@sveltejs/kit: ^2.50.2 => 2.50.2
@sveltejs/vite-plugin-svelte: ^6.2.4 => 6.2.4
svelte: ^5.50.1 => 5.50.1
vite: ^7.3.1 => 7.3.1Severity
annoyance
Additional Information
No response