You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/website-new/docs/en/guide/runtime/runtime-api.mdx
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ Used to create ModuleFederation instance.
20
20
- Multiple ModuleFederation instances need to be created with different configurations for each instance
21
21
- You want to use ModuleFederation's partitioning feature to encapsulate corresponding APIs for use in other projects
22
22
23
-
*`createInstance`will not overwrite an existing instance. Each call will create a new instance.
23
+
*`createInstance`always creates a fresh `ModuleFederation` instance and registers it in the global instance registry. It does not look up an existing instance by `name` / `version`, and it does not merge options into an existing instance.
## init <Badgetype='warning'>Use with caution</Badge>
42
42
43
43
:::warning Warning
44
44
45
-
This API will be deprecated. If you need to get an existing instance, you can use [getInstance](#getinstance)to retrieve the created instance.
45
+
`init` is still supported, but choose it based on how you want instances to be managed.
46
46
47
-
If you need to create a new instance, please use the [createInstance](#createinstance).
47
+
Unlike [createInstance](#createinstance), `init` does not always create a fresh instance. It first looks up an existing instance by `name` and `version`. If a matching instance is found, it reuses that instance and merges the new options by calling `instance.initOptions(options)`. If no matching instance exists, it falls back to creating one.
48
+
49
+
Use `init` when you want repeated calls for the same host to reuse and extend a single runtime instance. Use [createInstance](#createinstance) when you need guaranteed isolation and a brand-new instance every time. If you only need the instance created by the build plugin, use [getInstance](#getinstance).
- Used for dynamically registering `Vmok` modules at runtime.
53
55
- InitOptions:
54
56
@@ -137,7 +139,7 @@ init({
137
139
```
138
140
</Collapse>
139
141
140
-
### How to Migrate
142
+
### Recommended alternatives
141
143
142
144
#### Build Plugin(Use build plugin)
143
145
@@ -226,7 +228,7 @@ plugins: [mfRuntimePlugin()]
226
228
});
227
229
```
228
230
229
-
If you are not using the build plugin, you can replace `init`with[createInstance](#createinstance), which has exactly the same parameters.
231
+
If you are not using the build plugin, you can switch from `init`to[createInstance](#createinstance) because the option shape is the same. However, the instance semantics are different: `createInstance` always creates a fresh instance, while `init` may reuse an existing one with the same `name` / `version` and merge the new options into it.
Copy file name to clipboardExpand all lines: apps/website-new/docs/en/guide/runtime/runtime-hooks.mdx
+141-3Lines changed: 141 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -130,7 +130,7 @@ interface RemoteInfo {
130
130
131
131
`AsyncWaterfallHook`
132
132
133
-
Triggered before the host calls `remoteEntry.init(...)`. Useful for dynamically rewriting the share-scope alignment for this initialization (shareScopeKeys/shareScopeMap) and the `remoteEntryInitOptions` passed to the remote.
133
+
Triggered before the host calls `remoteEntry.init(...)`. Useful for dynamically rewriting the `shareScope` / `initScope` used in this initialization and the `remoteEntryInitOptions` passed to the remote.
134
134
135
135
* type
136
136
@@ -146,6 +146,29 @@ type BeforeInitContainerOptions ={
146
146
}
147
147
```
148
148
149
+
## initContainer
150
+
151
+
`AsyncWaterfallHook`
152
+
153
+
Triggered after `remoteEntry.init(...)` completes successfully. Useful for metrics, observability, or post-initialization customization.
The `loadEntry` function allows for full customization of remotes, enabling you to extend and create new remote types. The following two simple examples demonstrate loading JSON data and module delegation.
503
589
@@ -631,3 +717,55 @@ import test2 from "delegateModulesA/test2"
631
717
test1// "test1 value"
632
718
test2// "test2 value"
633
719
```
720
+
721
+
## bridgeHook
722
+
723
+
`bridgeHook` is defined in `runtime-core/src/core.ts` and is used to extend context across bridge render/destroy stages (for example, React/Vue bridge).
724
+
725
+
## beforeBridgeRender
726
+
727
+
`SyncHook`
728
+
729
+
Triggered before bridge rendering. You can return an object to augment render arguments (for example, `extraProps`).
730
+
731
+
* type
732
+
733
+
```ts
734
+
function beforeBridgeRender(args:Record<string, any>):void|Record<string, any>
735
+
```
736
+
737
+
## afterBridgeRender
738
+
739
+
`SyncHook`
740
+
741
+
Triggeredafterbridgerendering.
742
+
743
+
*type
744
+
745
+
```ts
746
+
function afterBridgeRender(args: Record<string, any>): void | Record<string, any>
747
+
```
748
+
749
+
## beforeBridgeDestroy
750
+
751
+
`SyncHook`
752
+
753
+
Triggeredbeforebridgeteardown.
754
+
755
+
*type
756
+
757
+
```ts
758
+
function beforeBridgeDestroy(args: Record<string, any>): void | Record<string, any>
759
+
```
760
+
761
+
## afterBridgeDestroy
762
+
763
+
`SyncHook`
764
+
765
+
Triggeredafterbridgeteardown.
766
+
767
+
*type
768
+
769
+
```ts
770
+
function afterBridgeDestroy(args: Record<string, any>): void | Record<string, any>
0 commit comments