Skip to content

Commit b745cae

Browse files
docs: fix Module Federation documentation technical inaccuracies
- Fix Mermaid diagram syntax errors in architecture-overview.md - Correct loadRemote API signatures in advanced-topics files - Remove fictional configuration options (runtime, integrity) - Fix interface structures and duplicated type definitions - Ensure all APIs match actual Module Federation implementation - Verified technical accuracy against actual codebase implementation All documentation now provides accurate specifications for bundler implementers. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 423d87d commit b745cae

11 files changed

+6856
-270
lines changed

arch-doc/advanced-topics-original.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ await federationInstance.preloadRemote([
433433
}
434434
]);
435435
```
436-
```
437436

438437
### Preload Hook Integration
439438

@@ -561,7 +560,6 @@ const generatePreloadAssetsPlugin = (): ModuleFederationRuntimePlugin => {
561560
};
562561
};
563562
```
564-
```
565563

566564
### Performance Monitoring
567565

@@ -696,7 +694,6 @@ const loadEntryPlugin: ModuleFederationRuntimePlugin = {
696694
}
697695
};
698696
```
699-
```
700697

701698
### Module Inspection Utilities
702699

@@ -737,7 +734,6 @@ const inspectionPlugin: ModuleFederationRuntimePlugin = {
737734
}
738735
};
739736
```
740-
```
741737

742738
### Real Usage Patterns
743739

@@ -783,7 +779,6 @@ async function preloadCriticalModules() {
783779
]);
784780
}
785781
```
786-
```
787782

788783
## Best Practices
789784

@@ -872,7 +867,6 @@ const productionConfig = {
872867
]
873868
};
874869
```
875-
```
876870

877871
### 6. Security Considerations
878872

@@ -921,7 +915,6 @@ describe('Federation Integration', () => {
921915
});
922916
});
923917
```
924-
```
925918

926919
### 8. Debugging and Monitoring
927920

@@ -1032,6 +1025,5 @@ async function loadComponent(id: string) {
10321025
}
10331026
}
10341027
```
1035-
```
10361028

10371029
This document covers the real, implemented features of Module Federation. For any patterns marked as "PROPOSED", please verify their implementation status before using in production applications.

arch-doc/advanced-topics-production.md

Lines changed: 59 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
⚠️ **CRITICAL WARNING**: This document contains production-critical information about Module Federation. Failure to implement these patterns correctly WILL result in memory leaks, security vulnerabilities, and production crashes. Read every warning carefully.
44

5-
**PRODUCTION IMPACT**: Every feature described here has performance implications. Plugin overhead ranges from 30-50% (not "minimal"). Mobile devices experience 10x slower load times. Plan accordingly.
5+
**PRODUCTION IMPACT**: Every feature described here has performance implications. Plugins add overhead to module loading operations. Mobile devices may experience significantly slower performance due to resource constraints. Plan accordingly.
66

77
**SECURITY NOTICE**: Module Federation exposes your application to cross-origin security risks. Implement ALL security measures described or risk data breaches.
88

@@ -134,16 +134,17 @@ const securePlugin: ModuleFederationRuntimePlugin = {
134134
};
135135
```
136136

137-
### 🚨 CORS ERRORS BYPASS ERROR RECOVERY
137+
### 🚨 CORS ERRORS AND ERROR RECOVERY
138138

139139
```typescript
140-
//THIS WILL NOT WORK FOR CORS ERRORS
141-
const brokenErrorHandler: ModuleFederationRuntimePlugin = {
142-
name: 'BrokenErrorHandler',
140+
//Network-level errors may not trigger errorLoadRemote hook
141+
const limitedErrorHandler: ModuleFederationRuntimePlugin = {
142+
name: 'LimitedErrorHandler',
143143

144144
errorLoadRemote(args) {
145-
// CORS errors are network errors - this hook is NEVER called!
146-
return () => 'Fallback'; // Never executed for CORS
145+
// Note: Network-level errors (CORS, DNS, etc.) may not reach this hook
146+
// depending on browser implementation and network conditions
147+
return () => 'Fallback'; // May not execute for network errors
147148
}
148149
};
149150

@@ -305,28 +306,25 @@ await preloader.preloadStrategic([
305306

306307
## Runtime Plugin System
307308

308-
⚠️ **PERFORMANCE WARNING**: Each plugin adds 30-50% overhead to module loading. Mobile devices experience 10x slower performance. Use plugins sparingly in production.
309+
⚠️ **PERFORMANCE WARNING**: Each plugin adds overhead to module loading operations. Mobile devices may experience significantly degraded performance. Use plugins sparingly in production and measure their impact.
309310

310311
### Plugin Performance Impact
311312

312313
```typescript
313-
// MEASURED PERFORMANCE IMPACT (Real production data)
314-
const performanceImpact = {
315-
noPlugins: {
316-
desktop: '50ms average load time',
317-
mobile: '500ms average load time'
318-
},
319-
onePlugin: {
320-
desktop: '75ms average load time (+50%)',
321-
mobile: '750ms average load time (+50%)'
314+
// Plugin performance impact varies by implementation and environment
315+
// Benchmark in your specific environment to understand the overhead
316+
const performanceConsiderations = {
317+
desktop: {
318+
note: 'Generally handles plugin overhead better',
319+
recommendation: 'Monitor load times and optimize accordingly'
322320
},
323-
threePlugins: {
324-
desktop: '150ms average load time (+200%)',
325-
mobile: '1500ms average load time (+200%)'
321+
mobile: {
322+
note: 'More sensitive to plugin overhead due to resource constraints',
323+
recommendation: 'Minimize plugins and prioritize essential functionality'
326324
},
327-
fivePlugins: {
328-
desktop: '250ms average load time (+400%)',
329-
mobile: '5000ms average load time (+900%)' // 5 SECONDS!
325+
general: {
326+
note: 'Each plugin adds processing overhead',
327+
recommendation: 'Combine multiple concerns into fewer plugins when possible'
330328
}
331329
};
332330

@@ -504,17 +502,17 @@ registerGlobalPlugins([productionSafePlugin]);
504502

505503
## Error Handling and Recovery
506504

507-
⚠️ **CRITICAL WARNING**: The `errorLoadRemote` hook DOES NOT catch CORS errors, network timeouts, or CSP violations. These bypass the error recovery system entirely.
505+
⚠️ **IMPORTANT**: The `errorLoadRemote` hook may not catch all error types. Network-level errors like CORS issues, timeouts, or CSP violations can bypass Module Federation's error handling depending on browser implementation. Implement additional error handling at the application level.
508506

509507
### Error Types NOT Handled by errorLoadRemote
510508

511509
```typescript
512-
// These errors BYPASS errorLoadRemote:
513-
// 1. CORS errors (most common in production)
514-
// 2. Network timeouts
515-
// 3. CSP violations
516-
// 4. DNS failures
517-
// 5. SSL/TLS errors
510+
// These errors may bypass errorLoadRemote in some browser implementations:
511+
// 1. CORS errors (browser security policy)
512+
// 2. Network timeouts (browser-level timeout)
513+
// 3. CSP violations (browser security policy)
514+
// 4. DNS failures (network infrastructure)
515+
// 5. SSL/TLS errors (connection security)
518516

519517
// ❌ THIS WILL NOT WORK
520518
const brokenErrorHandler: ModuleFederationRuntimePlugin = {
@@ -643,13 +641,13 @@ async function fetchWithRetry({
643641

644642
## Share Scope Management
645643

646-
⚠️ **MEMORY LEAK WARNING**: Share scopes are NEVER garbage collected. Each shared module version remains in memory forever, causing unbounded memory growth.
644+
⚠️ **MEMORY MANAGEMENT**: Share scopes can accumulate module versions over time. Without proper cleanup strategies, this can lead to increased memory usage as different versions of shared modules are retained.
647645

648646
### Share Scope Memory Leaks
649647

650648
```typescript
651-
//DEFAULT BEHAVIOR - Memory leak
652-
// Every version of every shared module stays in memory FOREVER
649+
//Default behavior may accumulate module versions
650+
// Different versions of shared modules can accumulate without cleanup
653651
export type ShareScopeMap = {
654652
[scopeName: string]: {
655653
[packageName: string]: {
@@ -795,27 +793,24 @@ function initializeSharing(shareScopeName: string | string[]) {
795793

796794
## Module Preloading
797795

798-
⚠️ **PERFORMANCE WARNING**: Preloading can make your app SLOWER, not faster. Preloading blocks the main thread and can delay initial render by 2-10 seconds.
796+
⚠️ **PERFORMANCE WARNING**: Naive preloading can negatively impact performance. Preloading all modules upfront can block initial rendering and delay user interaction. Use strategic preloading based on user needs.
799797

800798
### Preloading Performance Impact
801799

802800
```typescript
803-
// REAL PRODUCTION MEASUREMENTS
804-
const preloadingImpact = {
801+
// Preloading strategy impact varies by application
802+
const preloadingStrategy = {
805803
withoutPreload: {
806-
firstPaint: '1.2s',
807-
interactive: '2.5s',
808-
fullyLoaded: '4.0s'
804+
pros: ['Faster initial load', 'Lower initial bandwidth usage'],
805+
cons: ['Module loading delays on first access']
809806
},
810807
naivePreload: {
811-
firstPaint: '3.5s', // 2.3s SLOWER!
812-
interactive: '5.0s', // 2.5s SLOWER!
813-
fullyLoaded: '6.0s' // 2.0s SLOWER!
808+
pros: ['All modules available immediately after preload'],
809+
cons: ['Blocks initial render', 'High bandwidth usage', 'Slower time to interactive']
814810
},
815811
strategicPreload: {
816-
firstPaint: '1.2s', // Same
817-
interactive: '2.3s', // 0.2s FASTER
818-
fullyLoaded: '3.5s' // 0.5s FASTER
812+
pros: ['Optimized loading based on priority', 'Better user experience'],
813+
cons: ['More complex implementation', 'Requires usage analysis']
819814
}
820815
};
821816

@@ -1037,27 +1032,24 @@ const preloadPlugin: ModuleFederationRuntimePlugin = {
10371032

10381033
## Performance Optimization
10391034

1040-
⚠️ **CRITICAL**: The default Module Federation setup has severe performance issues on mobile devices (10x slower) and causes memory leaks. You MUST implement these optimizations for production.
1035+
⚠️ **IMPORTANT**: Module Federation performance can vary significantly between desktop and mobile environments. Mobile devices may experience slower module loading due to resource constraints. Consider implementing optimizations for production deployments.
10411036

10421037
### Mobile Performance Crisis
10431038

10441039
```typescript
1045-
// REAL MOBILE PERFORMANCE DATA
1046-
const mobilePerformance = {
1047-
iPhone12: {
1048-
moduleLoad: '500ms-2000ms',
1049-
memoryUsage: '50-200MB',
1050-
crashRate: '5% after 30min usage'
1040+
// Mobile performance considerations
1041+
const mobileConsiderations = {
1042+
newDevices: {
1043+
performance: 'Generally good, but still slower than desktop',
1044+
considerations: ['Network conditions', 'Battery optimization', 'Memory constraints']
10511045
},
1052-
androidMidRange: {
1053-
moduleLoad: '2000ms-8000ms', // 8 SECONDS!
1054-
memoryUsage: '100-400MB',
1055-
crashRate: '15% after 20min usage'
1046+
midRangeDevices: {
1047+
performance: 'Noticeable performance impact',
1048+
considerations: ['Limited CPU/memory', 'Slower network', 'Background app limits']
10561049
},
1057-
older_devices: {
1058-
moduleLoad: '5000ms-15000ms', // 15 SECONDS!
1059-
memoryUsage: '200-500MB',
1060-
crashRate: '40% after 10min usage'
1050+
olderDevices: {
1051+
performance: 'Significant performance challenges',
1052+
considerations: ['Very limited resources', 'May require lite versions', 'Aggressive optimization needed']
10611053
}
10621054
};
10631055

@@ -1082,7 +1074,8 @@ class MobileOptimizedFederation {
10821074

10831075
try {
10841076
const module = await federationInstance.loadRemote(id, {
1085-
signal: controller.signal
1077+
loadFactory: true,
1078+
from: 'runtime'
10861079
});
10871080
clearTimeout(timeoutId);
10881081
return module;
@@ -1099,12 +1092,12 @@ class MobileOptimizedFederation {
10991092

11001093
### Module Caching
11011094

1102-
⚠️ **MEMORY LEAK**: The default module cache grows unbounded and NEVER releases memory!
1095+
⚠️ **MEMORY MANAGEMENT**: The default module cache can grow over time without automatic cleanup. Consider implementing cache size limits and eviction strategies for long-running applications.
11031096

11041097
```typescript
1105-
//DEFAULT IMPLEMENTATION - MEMORY LEAK
1098+
//Default implementation without cleanup
11061099
class ModuleFederation {
1107-
moduleCache: Map<string, Module> = new Map(); // NEVER CLEARED!
1100+
moduleCache: Map<string, Module> = new Map(); // Grows without bounds
11081101

11091102
// Real loadRemote with caching
11101103
async loadRemote<T = any>(
@@ -1378,9 +1371,7 @@ const productionConfig = {
13781371
remotes: [
13791372
{
13801373
name: 'remote-app',
1381-
entry: 'https://cdn.example.com/remote/remoteEntry.js',
1382-
// Subresource integrity
1383-
integrity: 'sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/ux5v3rwBx8t4EwRp3J3Zk2tm3mIF2A'
1374+
entry: 'https://cdn.example.com/remote/remoteEntry.js'
13841375
}
13851376
],
13861377

@@ -1444,27 +1435,7 @@ const productionConfig = {
14441435
return args;
14451436
}
14461437
}
1447-
],
1448-
1449-
// Runtime options
1450-
runtime: {
1451-
// Timeout for module loads
1452-
timeout: 10000,
1453-
1454-
// Retry configuration
1455-
retry: {
1456-
times: 3,
1457-
delay: 1000,
1458-
backoff: 1.5
1459-
},
1460-
1461-
// Memory limits
1462-
limits: {
1463-
maxCacheSize: 100,
1464-
maxCacheAge: 3600000,
1465-
maxShareScopes: 10
1466-
}
1467-
}
1438+
]
14681439
};
14691440
```
14701441

0 commit comments

Comments
 (0)