fix(builder): watch the files the federation build actually tracked - #96
fix(builder): watch the files the federation build actually tracked#96arifsisman wants to merge 1 commit into
Conversation
syncNfFileWatcher derived its watch list from `bundlerCache.keys()`. That cache is Angular's SourceFileCache, which extends Map but keeps tracked files in `typeScriptFileCache` (.ts) and `referencedFiles` (templates and styles) rather than in the outer Map. Instrumented on a running dev server: outerMap.size 0, typeScriptFileCache.size 197, referencedFiles.length 3119. Reading only `keys()` therefore watched nothing, so shared-mapping and exposed sources never invalidated the cache and the dev server kept serving stale bundles until restart. Read the two properties that actually hold the tracked files, and wake the rebuild loop for them too — they are externals for the app build, so Angular's own rebuild iterator never emits for them. Fixes native-federation#94.
d59d16a to
c3cde70
Compare
|
Thanks for PR! Have a look at these feedback points though. 1. The root cause holds only on the parallel-TS path — please pin down which one you were on. Upstream (22.0.x) confirms both halves. With
Worth noting what's load-bearing regardless of path: 2. The widened wake-up doubles dev-feedback latency on common saves.
The second pass isn't a cold rebuild — Can we narrow the wake set to sources reachable from 3. Type it against Both files already import You can merge main to receive the fixes for the audit |
Fixes #94.
Problem
While the dev server runs, edits to shared-mapping libraries and exposed sources never reach the emitted federation bundles. The dev server keeps serving stale code until it is restarted; a hard browser reload does not help.
Root cause
syncNfFileWatcherdecides what to watch from the bundler cache:bundlerCacheis Angular'sSourceFileCache. That class extendsMap, but it does not keep tracked files in the outer Map — it keeps them in two separate properties:SourceFileCache.invalidate()itself consultsreferencedFilesviaextraWatchFiles. Sokeys()reads the one container that stays empty.Instrumented on a running dev server (Angular 22.0.8, Nx workspace, host + 3 remotes):
197
.tsfiles and 3119 referenced files (275 of them workspace sources) never enter the watcher. Nothing lands in the dirty buffer,SourceFileCacheis never invalidated, and the rebuild reuses stale TS output.There is a second gap on the same path: the rebuild loop is only woken for npm-linked dirs (
if (isUnderLinkedDir(p)) notifyChange()). Shared mappings and exposes are externals for the app build, so Angular's own rebuild iterator never emits for them — the "ride the next Angular-driven rebuild" fallback never arrives.Fix
syncNfFileWatchera key view overtypeScriptFileCache+referencedFiles. The outerkeys()is still included, so cache implementations that do populate it keep working.Applied to both
build/builder.tsandremote/builder.ts.Verification
Measured on a real Nx + Angular 22.0.8 workspace (host + 3 remotes) by writing a marker into a source file while the dev server is running, then checking whether it reaches the emitted bundle:
.tsedit.htmleditThe
.htmlcase is the variant described in the issue comment (triggered throughexposesrather thansharedMappings). Both go through the samemapping-or-exposedcontext, so a single fix closes both.Verification was also repeated with the built artifact dropped into the consuming workspace's
node_modules, not only against source.npm run typecheck,npm run lint(0 errors; warning count identical to the unmodified baseline) andvitest run(14 files / 100 tests) all pass.Note on tests
The changed code lives inside the builder generators and is not unit-testable as-is without extracting a helper module. Happy to pull
federationSourceFilesinto its own file with a spec if you would prefer that shape.