Micro-Frontend Error Isolation and Monitoring
On this page
One page, many owners
When a single-team app gets slower or starts throwing errors, the owner is obvious. On a composed page, a slow product page might be the catalog's code, the recommendations widget, a huge new dependency in the header, or the shell itself. Without attribution, every problem becomes a meeting.
The goal for production is simple: every error and every kilobyte has an owner.
Contain errors per micro-frontend
Three layers keep one team's bug from taking down the page:
- The shell's load guard. Loading or mounting a micro-frontend happens inside
try/catch, with a fallback message in that area only (Day 6). - Separate React roots. Each React micro-frontend has its own
createRoot. In React 19, an error thrown during rendering that no error boundary catches removes that whole root, and only that root. - Error boundaries inside each micro-frontend, so a team can replace a broken widget with a friendly message instead of a blank area.
The lab mounted a component that throws while rendering, next to the working catalog:
crashing micro-frontend: {"crashboxHTML":""} (its root was removed)
catalog: present, "Added Desk lamp" (unaffected)
page error reported: buggy: render failedThat blank area is better than a broken page, but each team should still wrap its tree in an error boundary:
import { Component, type ReactNode } from 'react';
class Boundary extends Component<{ children: ReactNode }, { failed: boolean }> {
state = { failed: false };
static getDerivedStateFromError() { return { failed: true }; }
componentDidCatch(error: Error) { reportError(error); } // hands it to the page's error handlers
render() { return this.state.failed ? <p role="alert">Reviews are unavailable.</p> : this.props.children; }
}
root.render(<Boundary><Reviews /></Boundary>);Attribute errors to the owning team
The shell can listen for every uncaught error on the page and work out which file it came from. Since the import map says which file belongs to which name, mapping a file to a team is a lookup:
const map = JSON.parse(document.querySelector('script[type=importmap]')!.textContent!).imports;
function owner(url: string) {
const path = new URL(url, location.href).pathname;
return Object.entries(map).find(([, file]) => file === path)?.[0] ?? 'shell-or-unknown';
}
window.addEventListener('error', (e) => {
report({ team: owner(e.filename), message: e.message, stack: e.error?.stack });
});
window.addEventListener('unhandledrejection', (e) => {
const file = String(e.reason?.stack ?? '').match(/https?:\/\/\S+?\.js/)?.[0];
report({ team: file ? owner(file) : 'unknown', message: String(e.reason) });
});In the lab, a micro-frontend threw once from a React click handler and once from a timer. Both were attributed correctly:
{"team":"@shop/buggy","message":"Uncaught Error: buggy: click handler failed"}
{"team":"@shop/buggy","message":"Uncaught Error: buggy: timer failed"}Send reports to your error tracker tagged with the team and the file's hash. Then each team gets alerts only for their own code, and the hash tells them which deploy introduced the error, which pairs naturally with Day 13's rollback.
Measure user experience per micro-frontend
Core Web Vitals measure the whole page: Largest Contentful Paint (loading), Interaction to Next Paint (responsiveness) and Cumulative Layout Shift (visual stability). For micro-frontends, add attribution:
- Collect vitals with the
web-vitalslibrary's attribution build, which reports the element behind LCP and the event target behind a slow interaction. Map those elements to the micro-frontend whose root contains them, using thedata-mfeattribute each mount area carries. - Have the shell add User Timing marks around each mount, like
performance.mark('mfe:cart:mounted'), so you can see how long each section took to appear. - Reserve space for each mount area with CSS (
min-height, oraspect-ratio), so a late micro-frontend doesn't push content down. Layout shift from late-loading sections is the classic micro-frontend vitals problem.
Give each team a budget
Performance degrades one reasonable-looking dependency at a time. A budget per micro-frontend makes the cost visible before it ships:
// in each team's pipeline, after the build
const LIMIT = 50 * 1024; // 50 KB gzipped, agreed per team
const size = zlib.gzipSync(fs.readFileSync(builtFile)).length;
if (size > LIMIT) {
console.error(`cart bundle is ${size} bytes gzipped, budget is ${LIMIT}`);
process.exit(1);
}Shared libraries don't count against a team's budget, which is another reason to share React (Day 9). The lab's own numbers show the difference: 772 bytes for a micro-frontend using the shared React, about 69 KB gzipped for the same one bundling its own copy. A budget catches the second case on the day it happens.
Keep the critical path short
- Load the shell and the current route's micro-frontend first. Everything else loads on demand or when idle.
- Preload the likely next micro-frontend with
<link rel="modulepreload">or on hover (Day 6). - Watch the waterfall. Shell, then map, then micro-frontend, then its data is four sequential steps. Inline the map in the HTML (as the lab does), and start the data request as soon as the micro-frontend mounts, not after its first render.
Check yourself
React removes that micro-frontend's whole root, and only that root. Other micro-frontends have their own roots and keep working. In the lab, the crashing area went blank while the catalog still added items. Wrap each micro-frontend in an error boundary so users see a message instead of a blank space.
From the error's file URL. The import map maps each file to a micro-frontend name, so the shell can look up the owner and tag the report.
Content appears after the page has laid out and pushes other content down. Reserve space for each mount area with CSS so nothing moves when it arrives.
The hash identifies exactly which deploy produced the error. If errors start right after a new cart file went live, the team knows which release to roll back, which pairs directly with one-line rollbacks in the import map.
A per-team budget enforced in CI: after the build, gzip the output and fail the build if it exceeds the agreed limit. A jump like that often means a large dependency or a second copy of React was bundled by accident, and catching it in the pull request is far cheaper than after release.