Architecture: How to fix the Angular compiler CDN singleton isolation bug ...
Documentation for Sessions
🏗️ Architecture: How to fix the Angular compiler CDN singleton isolation bug ...
Date: 2026-03-24
Time: 16:10:12 UTC
Session: gspace1-264.2
Agent: angular
Confidence: 92%
Status: ✅ Documented
📋 Decision Context
Question:
How to fix the Angular compiler CDN singleton isolation bug and future-proof the preview compilation pipeline against JIT deprecation?
Task: S264: Fix rspack/wasm live preview Angular compiler CDN error and improve platform building
🎯 Decision Made
Chosen:
Three-phase approach: (1) Self-host Angular ESM runtime at /angular-runtime/ with shared singletons via relative imports, (2) Compilation Strategy pattern abstracting JIT vs AOT, (3) Lightweight template compiler that generates Ivy instructions directly, eliminating @angular/compiler dependency
Options Considered:
- Self-host Angular packages as ESM bundles (chosen)
- Use esm.sh ?external= parameter (doesn't work in blob URL context)
- Use WebContainers for full Node.js in-browser (overkill, heavy)
- Bundle @angular/compiler into main.js (large bundle, still needs JIT)
- Use jsDelivr/unpkg CDN instead of esm.sh (same singleton problem)
💭 Reasoning
Root cause: esm.sh re-bundles Angular packages, inlining separate copies of @angular/core into each. When @angular/compiler calls publishFacade(), it registers with its bundled copy of core — a different module instance than what the app uses. Self-hosting with relative imports (./core.mjs) guarantees singleton sharing because the browser caches ESM modules by URL. Phase 2 strategy pattern future-proofs against JIT removal. Phase 3 template compiler is genuinely novel — generating Ivy instructions directly eliminates the runtime compiler entirely, saving ~2MB and making the pipeline immune to Angular compilation mode changes.
📁 Files Involved
tools/scripts/build/bundle-angular-runtime.tslibs/libs-structural/platform-preview/src/lib/config/esm-cdn-map.tslibs/libs-structural/platform-preview/src/lib/services/preview-server.service.tslibs/libs-structural/platform-preview/src/lib/services/bundler.service.tsapps/gograb-space/project.jsonlibs/libs-structural/platform-preview/src/lib/strategies/compilation-strategy.tslibs/libs-structural/platform-preview/src/lib/strategies/jit-compilation.strategy.tslibs/libs-structural/platform-preview/src/lib/strategies/aot-compilation.strategy.tslibs/libs-structural/platform-preview/src/lib/compiler/template-parser.tslibs/libs-structural/platform-preview/src/lib/compiler/ivy-codegen.tslibs/libs-structural/platform-preview/src/lib/compiler/decorator-transformer.ts
🔗 Related
- Decision ID:
dev_1774368612370_2stl6wu - Session: 264
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation