Skip to content

Commit 29b14d9

Browse files
docs: enhance Module Federation offline remote handling documentation (#3932)
## Summary - Enhanced documentation for handling offline remotes in Module Federation applications - Added missing lifecycle parameter to errorLoadRemote hook documentation - Fixed shareStrategy documentation to clarify version-first eager loading behavior - Updated troubleshooting guide with advanced errorLoadRemote solutions - Added comprehensive "Building Custom Retry Plugin" guide with production example ## Changes Made - **Runtime Hooks**: Added missing `lifecycle` parameter to `errorLoadRemote` hook signature and examples - **ShareStrategy**: Corrected documentation to show only `version-first` eagerly loads remotes, with warning about offline remote considerations - **Troubleshooting**: Enhanced RUNTIME-003 guide with lifecycle-aware error handling and retry plugin integration - **New Guide**: Added "Building Custom Retry Plugin" documentation with complete implementation example - **Retry Plugin**: Updated existing retry plugin documentation with better examples ## Test plan - [x] Verified all documentation links are valid (error-load-remote blog exists) - [x] Confirmed hook signatures match source code in packages/runtime-core - [x] Validated shareStrategy behavior matches implementation in shared/index.ts - [x] Added production-ready plugin example based on real implementation 🤖 Generated with [Claude Code](https://claude.ai/code)
1 parent 41ee332 commit 29b14d9

File tree

14 files changed

+1708
-406
lines changed

14 files changed

+1708
-406
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@ vitest.config.*.timestamp*
8888
.rsbuild
8989
ssg
9090
.claude
91+
__mocks__/

INCREMENTAL_PR_PLAN_REVISED.md

Lines changed: 0 additions & 297 deletions
This file was deleted.

apps/website-new/docs/en/configure/shareStrategy.mdx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,48 @@
22

33
- Type: `'version-first' | 'loaded-first'`
44
- Required: No
5-
- Default: `'version-first'`
5+
- Default: `'version-first'` (set by webpack plugin/bundler runtime)
66

77
Control the loading strategy of shared dependencies:
88

9-
- `'version-first'`: Version priority, ensuring that the highest version of shared dependencies is used. After setting, all *remotes* entry files will be automatically loaded and **register** the corresponding shared dependencies to ensure that all shared dependency versions can be obtained. This strategy is recommended when there are strict version requirements.
9+
- `'version-first'`: Version priority, ensuring that the highest version of shared dependencies is used. **All remotes entry files will be automatically loaded during initialization** to register shared dependencies and ensure version compatibility. This strategy is recommended when there are strict version requirements.
1010

11-
- `'loaded-first'`: Prioritize reuse, greatly reducing redundant dependency requests. After setting, the *remotes* entry file will not be automatically loaded (it will only be loaded when needed), and the loaded shared dependencies will be reused first. This strategy is recommended when there are no strict requirements on the version and performance is required.
11+
- `'loaded-first'`: Prioritize reuse of already loaded shared dependencies. Remotes are loaded on-demand rather than during initialization. This strategy is recommended when you want to reuse loaded dependencies for performance.
12+
13+
:::warning Offline Remote Considerations
14+
15+
The `'version-first'` strategy automatically loads remote entry files during application startup to initialize shared dependencies. If any remote is offline or unreachable, this will trigger the `errorLoadRemote` hook with `lifecycle: 'beforeLoadShare'` during startup. Without proper error handling, this can cause application initialization failures.
16+
17+
The `'loaded-first'` strategy defers remote loading until modules are actually requested, which means offline remotes only cause failures when those specific remotes are accessed, not during application startup.
18+
19+
**What happens with version-first and offline remotes:**
20+
1. During initialization, remotes are loaded via `initializeSharing()`
21+
2. If remote manifest/entry is offline, `module.getEntry()` fails
22+
3. `errorLoadRemote` hook is called with `lifecycle: 'beforeLoadShare'`
23+
4. If no fallback is provided, the initialization may hang or fail
24+
25+
**Required error handling for version-first:**
26+
```ts
27+
const plugin = {
28+
name: 'offline-resilient-plugin',
29+
errorLoadRemote(args) {
30+
if (args.lifecycle === 'beforeLoadShare') {
31+
// Handle version-first offline remote during startup
32+
return {
33+
init: () => Promise.resolve(),
34+
get: (module) => () => Promise.resolve(() => 'Offline Fallback')
35+
};
36+
}
37+
}
38+
};
39+
```
40+
41+
For production applications with potential network issues, consider:
42+
- Using `'loaded-first'` strategy for better resilience
43+
- Implementing comprehensive error handling for `'beforeLoadShare'` lifecycle
44+
- Adding retry mechanisms via plugins
45+
- Using proper error boundaries and fallback components
46+
47+
See [Error Load Remote Solutions](../blog/error-load-remote) for detailed offline handling strategies.
48+
49+
:::

0 commit comments

Comments
 (0)