Skip to content

Commit 444e069

Browse files
committed
fix: invalidate cross-module fact caches in Rspack loader and Vite watchChange
The Rspack loader's process-scoped fact cache was never cleared, so after a defining module changed from stable to unstable the old proof persisted and importers kept omitting live captures from inferred dependency arrays. Similarly, the Vite plugin only invalidated facts in the hotUpdate hook (dev server). In vite build --watch, watchChange fires instead of hotUpdate, leaving the cache stale across rebuilds. - Import and call invalidateFactCache in the Rspack loader on every run, keyed to the current module, so rebuilds read fresh facts. - Call invalidateFactCache from watchChange when crossModuleHookFacts is on, matching the hotUpdate path for build-watch parity. - Add the missing invalidateFactCache stub to the loader test mock.
1 parent 188c8aa commit 444e069

3 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎packages/octane/src/compiler/vite.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ export function octane(options = {}) {
340340
},
341341
watchChange(id) {
342342
compiler.invalidate(id);
343+
if (crossModuleHookFacts) invalidateFactCache(factCache, id);
343344
},
344345
generateBundle(_outputOptions, bundle) {
345346
if (!emitClientReferenceManifest) return;

‎packages/rspack-plugin-octane/src/loader.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
createOctaneCompiler,
88
createFactCache,
99
findFactCandidates,
10+
invalidateFactCache,
1011
resolveHookStability,
1112
} from 'octane/compiler/bundler';
1213
import {
@@ -135,6 +136,7 @@ function hookStabilityFor(context, candidates, id) {
135136
export default function octaneLoader(source, inputSourceMap) {
136137
this.cacheable?.(true);
137138
clearBuildInfo(this._module);
139+
invalidateFactCache(rspackFactCache, cleanModuleId(this.resource ?? this.resourcePath));
138140

139141
try {
140142
const options = normalizeLoaderOptions(this.getOptions?.() ?? {});

‎packages/rspack-plugin-octane/tests/loader.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ vi.mock('octane/compiler/bundler', () => ({
1515
// exist because the module is imported at load time.
1616
createFactCache: () => ({ files: new Map(), resolved: new Map() }),
1717
findFactCandidates: () => [],
18+
invalidateFactCache: () => {},
1819
resolveHookStability: async () => null,
1920
}));
2021

0 commit comments

Comments
 (0)