|
2 | 2 |
|
3 | 3 | - Type: `'version-first' | 'loaded-first'`
|
4 | 4 | - Required: No
|
5 |
| -- Default: `'version-first'` |
| 5 | +- Default: `'version-first'` (set by webpack plugin/bundler runtime) |
6 | 6 |
|
7 | 7 | Control the loading strategy of shared dependencies:
|
8 | 8 |
|
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. |
10 | 10 |
|
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