feat: add clear_cache_without_tsconfig for HMR optimization #152
+23
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
clear_cache_without_tsconfig()method that clears path cache while preserving tsconfig cacheProblem
When using tsconfig path aliases (especially wildcard patterns like
"*": ["./src/*"]), HMR intermittently fails with "Module not found" errors. This happens because:clear_cache()which clears both the path cache AND tsconfig cachetsconfig.jsonon every HMR update is wastefulRelated issue: web-infra-dev/rspack#12753
Solution
Add two new methods:
Cache::clear_without_tsconfig()- clears only the path cacheResolverGeneric::clear_cache_without_tsconfig()- public API that clears path cache but preserves tsconfig cacheThis allows rspack to preserve tsconfig state during HMR while still invalidating file system caches.
Test plan
Next steps
Once this PR is merged, a second PR is needed in
rspackto use the new method during HMR:crates/rspack_core/src/compiler/rebuild.rs:58to callclear_cache_without_tsconfig()instead ofclear_cache()🤖 Generated with Claude Code