fix(builder): watch the files the federation build actually tracked - #96
Open
arifsisman wants to merge 1 commit into
Open
fix(builder): watch the files the federation build actually tracked#96arifsisman wants to merge 1 commit into
arifsisman 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.
arifsisman
force-pushed
the
fix/watch-federation-tracked-sources
branch
from
July 28, 2026 22:07
d59d16a to
c3cde70
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.