Micro-Frontend Isolation: Shadow DOM, Iframes & Module Graphs
Mental Model
Micro-frontends trade isolation strength against memory and UX friction. Shadow DOM scopes CSS inside one browsing context, ES Modules import maps deduplicate shared runtimes, and <iframe> enforces full origin and JS heap boundaries.
Interactive Simulator
Micro-Frontend Isolation Boundaries
Compare shared module graphs, Shadow DOM scoping, and iframe process isolation.
Host Shell
Shared Module Map
Billing Remote
Step 1 / 3: 1. Shared ES Module Graph
Import map resolves 'react' to a single cached module URL across both host and remote.
import React from 'react';
// 1 shared module instanceInternal State / Memory
- cssIsolated
- false
- jsHeapShared
- true
- duplicateFrameworks
- 0
Under the Hood
Each isolation primitive enforces a different boundary inside the browser's renderer process.
- Module Federation & Import Maps: Shares a single
window,document, and JS heap; a central dependency resolver negotiates singleton versions (e.g.,react@19) so remotes do not download duplicate 45 KB runtimes. - Shadow DOM + Proxy Sandbox:
attachShadow({ mode: 'open' })blocks outer CSS selectors from bleeding inward, while aProxy(window)sandbox intercepts global property writes per sub-app. - Cross-Origin
<iframe>: Allocates an isolated browsing context (and often a separate OS site-isolation process via COOP/COEP), communicating strictly overpostMessage()structured clones.
HTML
<script type="importmap">
{
"imports": {
"react": "https://cdn.example.com/react@19/index.js",
"@billing/widget": "https://billing.example.com/widget.js"
}
}
</script>
<billing-shell></billing-shell>Problem Genealogy
- 2016 (Iframes & Portal Shells): Guaranteed fault and CSS isolation, but broke URL deep-linking, accessibility focus, and modal overlays at iframe viewport edges.
- 2020 (Webpack Module Federation): Shared singletons dynamically across independently deployed builds, risking runtime crashes when teams drifted on incompatible peer dependencies.
- 2024 (Import Maps + Shadow DOM): Native browser module resolution paired with declarative Shadow DOM eliminated bundler-specific runtime loaders.
Production Pitfalls
Production Pitfall
- Dual-Framework Heap Bloat: Loading both React 18 and React 19 remotes without singleton version negotiation duplicates event delegation listeners on
documentand doubles baseline JS memory. - Portal Escape Through Shadow Boundaries: Rendering a modal via
document.body.appendChildbreaks out of the Shadow DOM root and loses all scoped component styles.
When Not to Use
- When not to use micro-frontends: Never split an application owned by fewer than 3 independent teams into runtime micro-frontends; cross-team version skew, duplicate shared chunks, and
postMessageserialization latency cost more than a modular monorepo.
Connections & Logical Next Steps
Useful Prerequisites
Micro-Frontend Isolation: Shadow DOM, Iframes & Module Graphs
What This Unlocks
Leaf concept
Useful PrerequisitesBaseline · Widely
Shadow DOM Encapsulation and Event Retargeting
DOM & Events
Shadow DOM provides style and DOM tree scoping without allocating a separate browsing context.
Useful PrerequisitesBaseline · Widely
ES Modules and Live Bindings
JS Runtime
Import maps and Module Federation share singleton framework runtimes across micro-frontends via ES module bindings.