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:

  1. Self-host Angular packages as ESM bundles (chosen)
  2. Use esm.sh ?external= parameter (doesn't work in blob URL context)
  3. Use WebContainers for full Node.js in-browser (overkill, heavy)
  4. Bundle @angular/compiler into main.js (large bundle, still needs JIT)
  5. 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


🔗 Related


Auto-generated by MCP Smart Consolidation