Skip to content

[native-federation] Dev server serves stale shared-mapping bundles until restart (workspace lib edits never trigger federation rebuild) #94

Description

@arifsisman

Version: @angular-architects/native-federation 22.0.6, Angular 22.0.7, Nx workspace, esbuild builder (native-federation:build with vite dev server).

Symptom: When a workspace library that is a shared mapping (tsconfig path, e.g. @apex/shell → libs/shell/src/index.ts) is edited while ng serve/nx serve is running, the emitted shared bundle (_apex_shell.js) keeps serving the old code until the dev server is restarted. A hard browser reload does not help.

Root cause (two gaps in src/builders/build/builder.js):

The shared-mapping source directories are never added to the NF file watcher. syncNfFileWatcher relies on bundlerCache.keys(), but in this setup the cache map stays empty (verified by instrumenting syncNfFileWatcher: total 0, watched 0), so the sync is a silent no-op. Since mappings are externals for the app build, Angular's own watcher doesn't cover them either — nothing ever lands in the dirty buffer, so SourceFileCache is never invalidated and ctx.rebuild() reuses the stale TS output.
Even when a watched file changes, the rebuild loop is only woken for npm-linked dirs (if (isUnderLinkedDir(p)) notifyChange()); workspace-mapping edits are expected to "ride the next Angular-driven rebuild", which never comes for external sources.
Fix (patch below): add the mapping entry-point directories to the NF watcher, and wake the rebuild loop for every watched change. With the patch, a lib edit lands in the shared bundle in ~4s (verified by appending/removing a probe export to the mapping entry while the dev server runs).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions