Skip to content

fix(cache): revalidate cached imports - #11254

Closed
GTUTETTY wants to merge 1 commit into
vitest-dev:mainfrom
GTUTETTY:codex/fix-11246-stale-import
Closed

GTUTETTY wants to merge 1 commit into
vitest-dev:mainfrom
GTUTETTY:codex/fix-11246-stale-import

Conversation

@GTUTETTY

Copy link
Copy Markdown

Description

Written by Codex on behalf of @GTUTETTY, who reviewed this contribution and approved submission. GPT-5.6 Luna assisted with implementation and testing.

The filesystem module cache stores resolved import URLs. If an extensionless dependency changes from b.ts to b.tsx while its importer stays unchanged, the cached transform still imports the removed file.

This checks cached filesystem dependency nodes before Vitest restores a transform. If a resolved file no longer exists, Vitest discards that cache entry and lets Vite resolve the import again. Virtual and non-filesystem entries keep their current behavior.

The regression test runs the same project twice. It warms the cache with b.ts, renames the file to b.tsx, then confirms the unchanged importer runs on the second pass.

Resolves #11246

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • pnpm test:ci
  • pnpm build
  • pnpm typecheck
  • pnpm --dir test/e2e test fs-module-cache-resiliency.test.ts
  • pnpm --dir test/e2e test caching.test.ts
  • CI=true pnpm lint

Documentation

  • No public API or user-facing option changed.

Changesets

  • The proposed PR title is fix(cache): revalidate cached imports.

@netlify

netlify Bot commented Sep 13, 2026

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 6051b72
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6aa71ff9a9499f0008d95949
😎 Deploy Preview https://deploy-preview-11254--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines +294 to +301
const importedModules = await Promise.all(cachedModule.importedUrls.map(async (url) => {
return environment.moduleGraph.ensureEntryFromUrl(url).catch(() => null)
}))
if (importedModules.some(moduleNode => moduleNode?.file && !existsSync(moduleNode.file))) {
debugFs?.(`cached module ${moduleGraphModule.id} has a missing dependency, re-transforming`)
moduleGraphModule.transformResult = null
return undefined
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea looks close but Vite defines moduleNode.file for any modules including virtual module, so this fs bail out should be excluded for those modules. Otherwise the module that imports virtual modules become not cacheable, which is likely going too far and such virtual module plugin can opt-out the strategy on their own.

The reasonable limiting condition would be likely of this form:

private async readFileContentToCache(
environment: DevEnvironment,
moduleGraphModule: EnvironmentModuleNode,
): Promise<string> {
if (
moduleGraphModule.file
// \x00 is a virtual file convention
&& !moduleGraphModule.file.startsWith('\x00')
&& !moduleGraphModule.file.startsWith('virtual:')
) {
const result = await this.readFileConcurrently(moduleGraphModule.file)
if (result != null) {
return result
}
}

@github-actions github-actions Bot locked and limited conversation to collaborators Oct 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fsModuleCache serves a stale transform after a dependency is renamed (Cannot find module)

2 participants