Skip to content

fix(deps): watch asset files in linked optimized dependencies - #23401

Open
gilangabdian wants to merge 1 commit into
vitejs:mainfrom
gilangabdian:make-asset-file-in-linked-dependencies-can-be-detected-by-watcher
Open

fix(deps): watch asset files in linked optimized dependencies#23401
gilangabdian wants to merge 1 commit into
vitejs:mainfrom
gilangabdian:make-asset-file-in-linked-dependencies-can-be-detected-by-watcher

Conversation

@gilangabdian

Copy link
Copy Markdown
Contributor

fixes: #14099

What?

This PR fixes a long-standing issue where changing asset files (such as .css, .html, or .json) inside a linked optimized dependency (e.g., using npm link or pnpm workspace) does not trigger a server reload or HMR.

What was changed:
Previously, optimizer/index.ts only pushed individual javascript chunk.moduleIds to metadata.watchFiles. This caused asset files adjacent to those modules to be ignored by the chokidar watcher.
In this PR, we gather the resolved parent directories of optimized dependencies (up to their package.json) and push these directories into metadata.watchFiles. We also updated checkOptimizedDepSource in server/index.ts to use .startsWith() instead of strict equality so it can catch any file modifications within those linked directories. watchFiles is also now safely serialized in _metadata.json for cache integrity.

Why tests are not included:
An automated test for this was attempted in playground/optimize-deps. However, editing a linked package's file (e.g., dep-linked-include/test.css) directly in the source tree violates the playground-temp test isolation, causing race conditions and flaky failures when running the full test suite in parallel. Thus, this fix is intended to be tested manually or handled via Vite's core E2E suite without explicit git-workspace file mutations.

Motivation and Context

Improves DX significantly for monorepo and library developers relying on local symlinks, ensuring that style and asset changes propagate instantly without requiring a manual server restart.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change for internal architecture/code styling)
  • Breaking change (fix or feature that would cause existing functionality to change)

@gilangabdian
gilangabdian force-pushed the make-asset-file-in-linked-dependencies-can-be-detected-by-watcher branch from f9d7e18 to 7842a5d Compare August 30, 2026 17:01
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.

Invalidate optimized dependency cache for modified monorepo dependencies

1 participant