Skip to content

fix(ssr): preserve in-flight module identity (fix #24046) - #24081

Open
boyfeiyu wants to merge 3 commits into
vitejs:mainfrom
boyfeiyu:boyf-775-ssr-reload-module-identity
Open

boyfeiyu wants to merge 3 commits into
vitejs:mainfrom
boyfeiyu:boyf-775-ssr-reload-module-identity

Conversation

@boyfeiyu

@boyfeiyu boyfeiyu commented Nov 12, 2026 •

Copy link
Copy Markdown

Description

Fixes #24046.

An SSR import can pause in top-level await while a file change triggers a full reload. Its later imports then use the newly cleared module cache, so one completed import can contain two instances of the same registry module.

Keep module indexes and pending fetches associated with their import graph across a full reload. Resolve late URL aliases through that graph, retain the supplied public cache object, and preserve the existing three-argument directRequest override. Retired HMR contexts share persistent hot.data and register callbacks while their graph is current.

The merge with main 4db98449 incorporates bundled SSR from #21626. It preserves bundled runtime reset, HMR queues, transport and lazy loading, and associates custom hot contexts and retained source maps with their owning graph. The contribution against that main covers five files.

Reproduction and validation

The regression fixture uses public createServer, configFile: false, envFile: false, real watched file edits, and independent gates for old and fresh evaluations. It covers both completion orders, static and dynamic imports, pending fetches, aliases, cycles/TLA, live bindings, persistent data and subsequent HMR. The 22 cases include three integration regressions for custom hot contexts and retained source maps. Exact reviewed regression source

With repository dependencies installed, run the focused regression and package checks.

pnpm --config.verify-deps-before-run=false exec vitest run packages/vite/src/node/ssr/runtime/__tests__/server-full-reload.spec.ts
pnpm --config.verify-deps-before-run=false --filter vite run build
pnpm --config.verify-deps-before-run=false --filter vite run typecheck

Independent execution on macOS arm64, Node 24.22.2, for ef7817cc8a751365fb438546c3779ac6b2004c17 passed 230 related runtime/SSR/HMR/worker/source-map tests and 100 filesystem-safety tests. Main passed 208 related tests and the same 100 safety tests. Both retain five upstream skips, including the two bundled-mode exclusions. Build, declarations, typecheck, lint and formatting passed. The module-runner build is 70,935 bytes against main's existing 71,000-byte limit, with 65 bytes remaining. A clean, uncommitted integration with newer main f8988882 passed the same runtime and safety suites, formal build and typecheck, plus Node SSR rendering controls for CSS, Sass and Less package imports.

Unchanged public afa16694 and the merge head both passed normal import controls and real watcher reloads with old-first and fresh-first completion. The observed identity trace for each completion order was as follows.

no reload       old 1/1, joined import shared, reloads 0
full reload     old 1/1, fresh 2/2, reloads 1

The compiled browser HMR client passed an isolated VM control with simulated WebSocket and dynamic loading. Real-browser/DOM/network and ecosystem suites remain untested. Native Windows Node26 remains untested locally, and the earlier Windows CI timeout cause remains unresolved. Retired-graph collection was observed in one bounded GC check. Large-graph performance remains unmeasured.

Review

AI coding agents assisted implementation and independent review. The review covered the complete original-base range of 114 files and 17 commits, the public-head-to-merge range, both merge parents, and actual current-main integration. It checked the 109 upstream-identical file entries and examined the five contribution files, graph ownership, callback registration, shared persistent data, custom caches, source maps and API compatibility.

Per-graph retention lets pending evaluations finish independently. Already loaded exports retain graph-local identity. A dependency first loaded later can read current disk contents.

This branch has not been deployed

No deployments
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.

Module runner: an import in flight during an SSR full-reload finishes on a mix of old and new module instances

1 participant