Skip to content

fix: hard-invalidate importers when dependency is deleted (#23527) - #23533

Open
mystmn wants to merge 2 commits into
vitejs:mainfrom
mystmn:fix/hard-invalidate-importers-on-delete
Open

mystmn wants to merge 2 commits into
vitejs:mainfrom
mystmn:fix/hard-invalidate-importers-on-delete

Conversation

@mystmn

@mystmn mystmn commented Sep 20, 2026

Copy link
Copy Markdown

Description

Fixes #23527.

When a module file (e.g. src/dep.ts) is renamed (e.g. to src/dep.tsx) or deleted while the dev server is running, any importer statically importing that module (e.g. import { value } from "./dep") was being soft-invalidated instead of hard-invalidated.

Because importer.staticImportedUrls?.has(mod.url) evaluated to true, Vite soft-invalidated the importer, preserving its cached transformed code with the old resolved URL (/src/dep.ts) and appending an HMR timestamp (/src/dep.ts?t=...). Requesting that stale URL failed with a pre-transform error (Does the file exist?).

This PR:

  1. Marks module nodes as isDeleted in onFileDelete and ensures they are invalidated in the module graph.
  2. Prevents soft-invalidation of importers when the imported module was deleted (!mod.isDeleted). Importers are now hard-invalidated so that their import specifiers are re-transformed and re-resolved against the filesystem.
  3. In propagateUpdate, ensures deleted modules cannot self-accept or be accepted via acceptedHmrDeps, propagating to importers and falling back to a full reload.
  4. Resets isDeleted = false on file creation/change or when re-ensuring the entry in the module graph.
  5. Adds unit tests covering importer hard-invalidation on file deletion.

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.

Dev server keeps stale import URL for importers after a file rename ("Does the file exist?")

1 participant