@module-federation/bridge-react 0.0.0-next-20241108091829 → 0.0.0-next-20241111073908

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,16 +1,13 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
- ## 0.0.0-next-20241108091829
3
+ ## 0.0.0-next-20241111073908
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - 3082116: feat: feat: support lifecycyle hooks in module-deferation bridge
8
- - Updated dependencies [8712967]
9
8
  - Updated dependencies [6db4c5f]
10
- - Updated dependencies [3082116]
11
- - @module-federation/runtime@0.0.0-next-20241108091829
12
- - @module-federation/sdk@0.0.0-next-20241108091829
13
- - @module-federation/bridge-shared@0.0.0-next-20241108091829
9
+ - @module-federation/sdk@0.0.0-next-20241111073908
10
+ - @module-federation/bridge-shared@0.0.0-next-20241111073908
14
11
 
15
12
  ## 0.7.0
16
13
 
package/dist/index.cjs.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
4
  const context = require("./context-DmzxwI_7.cjs");
5
5
  const ReactRouterDOM = require("react-router-dom");
6
- const runtime = require("@module-federation/runtime");
7
6
  const ReactDOM = require("react-dom");
8
7
  function _interopNamespaceDefault(e2) {
9
8
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -122,9 +121,21 @@ function e() {
122
121
  const t = new PopStateEvent("popstate", { state: window.history.state });
123
122
  window.dispatchEvent(t);
124
123
  }
124
+ const getHostInstance = (moduleName) => {
125
+ var _a, _b;
126
+ let hostInstance = void 0;
127
+ const currentName = context.getModuleName(moduleName);
128
+ const remoteInstance = (_b = (_a = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _a.__INSTANCES__) == null ? void 0 : _b.find(
129
+ (v) => v.name === currentName
130
+ );
131
+ if (remoteInstance && (remoteInstance == null ? void 0 : remoteInstance.hostName)) {
132
+ hostInstance = window.__VMOK__.__INSTANCES__.find(
133
+ (instance) => instance.name === (remoteInstance == null ? void 0 : remoteInstance.hostName)
134
+ );
135
+ }
136
+ return hostInstance;
137
+ };
125
138
  const RemoteAppWrapper = React.forwardRef(function(props, ref) {
126
- const host = runtime.getInstance();
127
- context.LoggerInstance.log(`RemoteAppWrapper host >>>`, host);
128
139
  const RemoteApp2 = () => {
129
140
  context.LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
130
141
  const {
@@ -140,6 +151,8 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
140
151
  const rootRef = ref && "current" in ref ? ref : React.useRef(null);
141
152
  const renderDom = React.useRef(null);
142
153
  const providerInfoRef = React.useRef(null);
154
+ const hostInstance = getHostInstance(moduleName);
155
+ context.LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
143
156
  React.useEffect(() => {
144
157
  const renderTimeout = setTimeout(() => {
145
158
  var _a, _b, _c, _d, _e, _f;
@@ -158,10 +171,18 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
158
171
  `createRemoteComponent LazyComponent render >>>`,
159
172
  renderProps
160
173
  );
161
- const beforeBridgeRenderRes = ((_c = (_b = (_a = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
174
+ context.LoggerInstance.log(
175
+ `createRemoteComponent LazyComponent hostInstance >>>`,
176
+ hostInstance
177
+ );
178
+ const beforeBridgeRenderRes = ((_c = (_b = (_a = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(
179
+ renderProps
180
+ )) || {};
162
181
  renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
163
182
  providerReturn.render(renderProps);
164
- (_f = (_e = (_d = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(renderProps);
183
+ (_f = (_e = (_d = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(
184
+ renderProps
185
+ );
165
186
  });
166
187
  return () => {
167
188
  clearTimeout(renderTimeout);
@@ -172,7 +193,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
172
193
  `createRemoteComponent LazyComponent destroy >>>`,
173
194
  { moduleName, basename, dom: renderDom.current }
174
195
  );
175
- (_d = (_c = (_b = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
196
+ (_d = (_c = (_b = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
176
197
  moduleName,
177
198
  dom: renderDom.current,
178
199
  basename,
@@ -184,7 +205,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
184
205
  moduleName,
185
206
  dom: renderDom.current
186
207
  });
187
- (_h = (_g = (_f = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
208
+ (_h = (_g = (_f = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
188
209
  moduleName,
189
210
  dom: renderDom.current,
190
211
  basename,
@@ -356,7 +377,7 @@ if (process.env.NODE_ENV === "production") {
356
377
  };
357
378
  }
358
379
  function createBridgeComponent(bridgeInfo) {
359
- return (params) => {
380
+ return () => {
360
381
  const rootMap = /* @__PURE__ */ new Map();
361
382
  const RawComponent = (info) => {
362
383
  const { appInfo, propsInfo, ...restProps } = info;
@@ -370,9 +391,17 @@ function createBridgeComponent(bridgeInfo) {
370
391
  }
371
392
  ));
372
393
  };
394
+ const getModuleInstance = (moduleName) => {
395
+ var _a, _b;
396
+ const moduleNameWithoutExpose = context.getModuleName(moduleName);
397
+ const instance = (_b = (_a = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _a.__INSTANCES__) == null ? void 0 : _b.find(
398
+ (v) => v.name === moduleNameWithoutExpose
399
+ );
400
+ return instance;
401
+ };
373
402
  return {
374
403
  async render(info) {
375
- var _a, _b, _c, _d;
404
+ var _a, _b, _c, _d, _e, _f;
376
405
  context.LoggerInstance.log(`createBridgeComponent render Info`, info);
377
406
  const {
378
407
  moduleName,
@@ -382,10 +411,7 @@ function createBridgeComponent(bridgeInfo) {
382
411
  fallback,
383
412
  ...propsInfo
384
413
  } = info;
385
- const moduleNameWithoutExpose = context.getModuleName(moduleName);
386
- const instance = __FEDERATION__.__INSTANCES__.find(
387
- (v) => v.name === moduleNameWithoutExpose
388
- );
414
+ const instance = getModuleInstance(moduleName);
389
415
  context.LoggerInstance.log(`createBridgeComponent remote instance`, instance);
390
416
  const beforeBridgeRenderRes = ((_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(info)) || {};
391
417
  const rootComponentWithErrorBoundary = (
@@ -416,22 +442,14 @@ function createBridgeComponent(bridgeInfo) {
416
442
  const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
417
443
  renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
418
444
  }
419
- const afterBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((_d = params == null ? void 0 : params.hooks) == null ? void 0 : _d.afterBridgeRender);
420
- afterBridgeRender && afterBridgeRender(info);
445
+ ((_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(info)) || {};
421
446
  },
422
447
  async destroy(info) {
423
448
  var _a, _b, _c, _d, _e, _f;
424
449
  context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
425
450
  dom: info.dom
426
451
  });
427
- const moduleNameWithoutExpose = context.getModuleName(info.moduleName);
428
- context.LoggerInstance.log(
429
- `createBridgeComponent remote module without expose name >>>`,
430
- moduleNameWithoutExpose
431
- );
432
- const instance = __FEDERATION__.__INSTANCES__.find(
433
- (v) => v.name === moduleNameWithoutExpose
434
- );
452
+ const instance = getModuleInstance(info.moduleName);
435
453
  context.LoggerInstance.log(`createBridgeComponent remote instance`, instance);
436
454
  (_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeDestroy) == null ? void 0 : _c.emit(info);
437
455
  if (context.atLeastReact18(React__namespace)) {
package/dist/index.d.ts CHANGED
@@ -12,9 +12,7 @@ declare type BridgeHooks = {
12
12
  afterBridgeDestroy?: (params: DestroyParams) => void | Record<string, any>;
13
13
  };
14
14
 
15
- export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): (params?: {
16
- hooks?: BridgeHooks;
17
- }) => {
15
+ export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
18
16
  render(info: RenderParams): Promise<void>;
19
17
  destroy(info: DestroyParams): Promise<void>;
20
18
  rawComponent: React_2.ComponentType<T>;
package/dist/index.es.js CHANGED
@@ -2,7 +2,6 @@ import * as React from "react";
2
2
  import React__default, { createContext, Component, createElement, isValidElement, forwardRef, useRef, useEffect, useContext, useState } from "react";
3
3
  import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin, a as getModuleName, b as atLeastReact18, R as RouterContext } from "./context-Dh6IUBWT.js";
4
4
  import * as ReactRouterDOM from "react-router-dom";
5
- import { getInstance } from "@module-federation/runtime";
6
5
  import ReactDOM from "react-dom";
7
6
  const ErrorBoundaryContext = createContext(null);
8
7
  const initialState = {
@@ -103,9 +102,21 @@ function e() {
103
102
  const t = new PopStateEvent("popstate", { state: window.history.state });
104
103
  window.dispatchEvent(t);
105
104
  }
105
+ const getHostInstance = (moduleName) => {
106
+ var _a, _b;
107
+ let hostInstance = void 0;
108
+ const currentName = getModuleName(moduleName);
109
+ const remoteInstance = (_b = (_a = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _a.__INSTANCES__) == null ? void 0 : _b.find(
110
+ (v) => v.name === currentName
111
+ );
112
+ if (remoteInstance && (remoteInstance == null ? void 0 : remoteInstance.hostName)) {
113
+ hostInstance = window.__VMOK__.__INSTANCES__.find(
114
+ (instance) => instance.name === (remoteInstance == null ? void 0 : remoteInstance.hostName)
115
+ );
116
+ }
117
+ return hostInstance;
118
+ };
106
119
  const RemoteAppWrapper = forwardRef(function(props, ref) {
107
- const host = getInstance();
108
- LoggerInstance.log(`RemoteAppWrapper host >>>`, host);
109
120
  const RemoteApp2 = () => {
110
121
  LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
111
122
  const {
@@ -121,6 +132,8 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
121
132
  const rootRef = ref && "current" in ref ? ref : useRef(null);
122
133
  const renderDom = useRef(null);
123
134
  const providerInfoRef = useRef(null);
135
+ const hostInstance = getHostInstance(moduleName);
136
+ LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
124
137
  useEffect(() => {
125
138
  const renderTimeout = setTimeout(() => {
126
139
  var _a, _b, _c, _d, _e, _f;
@@ -139,10 +152,18 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
139
152
  `createRemoteComponent LazyComponent render >>>`,
140
153
  renderProps
141
154
  );
142
- const beforeBridgeRenderRes = ((_c = (_b = (_a = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
155
+ LoggerInstance.log(
156
+ `createRemoteComponent LazyComponent hostInstance >>>`,
157
+ hostInstance
158
+ );
159
+ const beforeBridgeRenderRes = ((_c = (_b = (_a = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(
160
+ renderProps
161
+ )) || {};
143
162
  renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
144
163
  providerReturn.render(renderProps);
145
- (_f = (_e = (_d = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(renderProps);
164
+ (_f = (_e = (_d = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(
165
+ renderProps
166
+ );
146
167
  });
147
168
  return () => {
148
169
  clearTimeout(renderTimeout);
@@ -153,7 +174,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
153
174
  `createRemoteComponent LazyComponent destroy >>>`,
154
175
  { moduleName, basename, dom: renderDom.current }
155
176
  );
156
- (_d = (_c = (_b = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
177
+ (_d = (_c = (_b = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
157
178
  moduleName,
158
179
  dom: renderDom.current,
159
180
  basename,
@@ -165,7 +186,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
165
186
  moduleName,
166
187
  dom: renderDom.current
167
188
  });
168
- (_h = (_g = (_f = host == null ? void 0 : host.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
189
+ (_h = (_g = (_f = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
169
190
  moduleName,
170
191
  dom: renderDom.current,
171
192
  basename,
@@ -337,7 +358,7 @@ if (process.env.NODE_ENV === "production") {
337
358
  };
338
359
  }
339
360
  function createBridgeComponent(bridgeInfo) {
340
- return (params) => {
361
+ return () => {
341
362
  const rootMap = /* @__PURE__ */ new Map();
342
363
  const RawComponent = (info) => {
343
364
  const { appInfo, propsInfo, ...restProps } = info;
@@ -351,9 +372,17 @@ function createBridgeComponent(bridgeInfo) {
351
372
  }
352
373
  ));
353
374
  };
375
+ const getModuleInstance = (moduleName) => {
376
+ var _a, _b;
377
+ const moduleNameWithoutExpose = getModuleName(moduleName);
378
+ const instance = (_b = (_a = window == null ? void 0 : window.__FEDERATION__) == null ? void 0 : _a.__INSTANCES__) == null ? void 0 : _b.find(
379
+ (v) => v.name === moduleNameWithoutExpose
380
+ );
381
+ return instance;
382
+ };
354
383
  return {
355
384
  async render(info) {
356
- var _a, _b, _c, _d;
385
+ var _a, _b, _c, _d, _e, _f;
357
386
  LoggerInstance.log(`createBridgeComponent render Info`, info);
358
387
  const {
359
388
  moduleName,
@@ -363,10 +392,7 @@ function createBridgeComponent(bridgeInfo) {
363
392
  fallback,
364
393
  ...propsInfo
365
394
  } = info;
366
- const moduleNameWithoutExpose = getModuleName(moduleName);
367
- const instance = __FEDERATION__.__INSTANCES__.find(
368
- (v) => v.name === moduleNameWithoutExpose
369
- );
395
+ const instance = getModuleInstance(moduleName);
370
396
  LoggerInstance.log(`createBridgeComponent remote instance`, instance);
371
397
  const beforeBridgeRenderRes = ((_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(info)) || {};
372
398
  const rootComponentWithErrorBoundary = (
@@ -397,22 +423,14 @@ function createBridgeComponent(bridgeInfo) {
397
423
  const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
398
424
  renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
399
425
  }
400
- const afterBridgeRender = (bridgeInfo == null ? void 0 : bridgeInfo.hooks) && (bridgeInfo == null ? void 0 : bridgeInfo.hooks.afterBridgeDestroy) || ((_d = params == null ? void 0 : params.hooks) == null ? void 0 : _d.afterBridgeRender);
401
- afterBridgeRender && afterBridgeRender(info);
426
+ ((_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(info)) || {};
402
427
  },
403
428
  async destroy(info) {
404
429
  var _a, _b, _c, _d, _e, _f;
405
430
  LoggerInstance.log(`createBridgeComponent destroy Info`, {
406
431
  dom: info.dom
407
432
  });
408
- const moduleNameWithoutExpose = getModuleName(info.moduleName);
409
- LoggerInstance.log(
410
- `createBridgeComponent remote module without expose name >>>`,
411
- moduleNameWithoutExpose
412
- );
413
- const instance = __FEDERATION__.__INSTANCES__.find(
414
- (v) => v.name === moduleNameWithoutExpose
415
- );
433
+ const instance = getModuleInstance(info.moduleName);
416
434
  LoggerInstance.log(`createBridgeComponent remote instance`, instance);
417
435
  (_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeDestroy) == null ? void 0 : _c.emit(info);
418
436
  if (atLeastReact18(React)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/bridge-react",
3
- "version": "0.0.0-next-20241108091829",
3
+ "version": "0.0.0-next-20241111073908",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -41,14 +41,13 @@
41
41
  "dependencies": {
42
42
  "@loadable/component": "^5.16.4",
43
43
  "react-error-boundary": "^4.0.13",
44
- "@module-federation/bridge-shared": "0.0.0-next-20241108091829",
45
- "@module-federation/sdk": "0.0.0-next-20241108091829"
44
+ "@module-federation/bridge-shared": "0.0.0-next-20241111073908",
45
+ "@module-federation/sdk": "0.0.0-next-20241111073908"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "react": ">=16.9.0",
49
49
  "react-dom": ">=16.9.0",
50
- "react-router-dom": ">=4",
51
- "@module-federation/runtime": "0.0.0-next-20241108091829"
50
+ "react-router-dom": ">=4"
52
51
  },
53
52
  "devDependencies": {
54
53
  "@testing-library/react": "15.0.7",
@@ -63,7 +62,8 @@
63
62
  "react-router-dom": "6.22.3",
64
63
  "typescript": "^5.2.2",
65
64
  "vite": "^5.2.14",
66
- "vite-plugin-dts": "^3.9.1"
65
+ "vite-plugin-dts": "^3.9.1",
66
+ "@module-federation/runtime": "0.0.0-next-20241111073908"
67
67
  },
68
68
  "scripts": {
69
69
  "dev": "vite",
package/src/provider.tsx CHANGED
@@ -32,8 +32,9 @@ type ProviderFnParams<T> = {
32
32
  ) => RootType | Promise<RootType>;
33
33
  hooks?: BridgeHooks;
34
34
  };
35
+
35
36
  export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
36
- return (params?: { hooks?: BridgeHooks }) => {
37
+ return () => {
37
38
  const rootMap = new Map<any, RootType>();
38
39
  const RawComponent = (info: { propsInfo: T; appInfo: ProviderParams }) => {
39
40
  const { appInfo, propsInfo, ...restProps } = info;
@@ -49,6 +50,14 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
49
50
  );
50
51
  };
51
52
 
53
+ const getModuleInstance = (moduleName: string) => {
54
+ const moduleNameWithoutExpose = getModuleName(moduleName);
55
+ const instance = window?.__FEDERATION__?.__INSTANCES__?.find(
56
+ (v) => v.name === moduleNameWithoutExpose,
57
+ );
58
+ return instance;
59
+ };
60
+
52
61
  return {
53
62
  async render(info: RenderParams) {
54
63
  LoggerInstance.log(`createBridgeComponent render Info`, info);
@@ -61,10 +70,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
61
70
  ...propsInfo
62
71
  } = info;
63
72
 
64
- const moduleNameWithoutExpose = getModuleName(moduleName);
65
- const instance = __FEDERATION__.__INSTANCES__.find(
66
- (v) => v.name === moduleNameWithoutExpose,
67
- );
73
+ const instance = getModuleInstance(moduleName);
68
74
  LoggerInstance.log(`createBridgeComponent remote instance`, instance);
69
75
 
70
76
  const beforeBridgeRenderRes =
@@ -103,27 +109,17 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
103
109
  renderFn?.(rootComponentWithErrorBoundary, info.dom);
104
110
  }
105
111
 
106
- const afterBridgeRender =
107
- (bridgeInfo?.hooks && bridgeInfo?.hooks.afterBridgeDestroy) ||
108
- params?.hooks?.afterBridgeRender;
109
- afterBridgeRender && afterBridgeRender(info);
112
+ instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
110
113
  },
111
114
 
112
115
  async destroy(info: DestroyParams) {
113
116
  LoggerInstance.log(`createBridgeComponent destroy Info`, {
114
117
  dom: info.dom,
115
118
  });
116
- const moduleNameWithoutExpose = getModuleName(info.moduleName);
117
- LoggerInstance.log(
118
- `createBridgeComponent remote module without expose name >>>`,
119
- moduleNameWithoutExpose,
120
- );
121
- const instance = __FEDERATION__.__INSTANCES__.find(
122
- (v) => v.name === moduleNameWithoutExpose,
123
- );
119
+ const instance = getModuleInstance(info.moduleName);
124
120
  LoggerInstance.log(`createBridgeComponent remote instance`, instance);
125
-
126
121
  instance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit(info);
122
+
127
123
  // call destroy function
128
124
  if (atLeastReact18(React)) {
129
125
  const root = rootMap.get(info.dom);
@@ -9,8 +9,13 @@ import * as ReactRouterDOM from 'react-router-dom';
9
9
  import type { ProviderParams } from '@module-federation/bridge-shared';
10
10
  import { dispatchPopstateEnv } from '@module-federation/bridge-shared';
11
11
  import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
12
- import { LoggerInstance, pathJoin, getRootDomDefaultClassName } from '../utils';
13
- import { getInstance } from '@module-federation/runtime';
12
+ import {
13
+ LoggerInstance,
14
+ pathJoin,
15
+ getModuleName,
16
+ getRootDomDefaultClassName,
17
+ } from '../utils';
18
+ import { FederationHost } from '@module-federation/runtime';
14
19
 
15
20
  declare const __APP_VERSION__: string;
16
21
  export interface RenderFnParams extends ProviderParams {
@@ -36,12 +41,27 @@ interface RemoteAppParams {
36
41
  fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
37
42
  }
38
43
 
44
+ const getHostInstance = (moduleName: string) => {
45
+ let hostInstance: FederationHost | undefined = undefined;
46
+ const currentName = getModuleName(moduleName);
47
+ const remoteInstance = window?.__FEDERATION__?.__INSTANCES__?.find(
48
+ (v) => v.name === currentName,
49
+ );
50
+
51
+ // @ts-ignore
52
+ if (remoteInstance && remoteInstance?.hostName) {
53
+ // @ts-ignore
54
+ hostInstance = window.__VMOK__.__INSTANCES__.find(
55
+ (instance) => instance.name === remoteInstance?.hostName,
56
+ );
57
+ }
58
+ return hostInstance;
59
+ };
60
+
39
61
  const RemoteAppWrapper = forwardRef(function (
40
62
  props: RemoteAppParams & RenderFnParams,
41
63
  ref,
42
64
  ) {
43
- const host = getInstance();
44
- LoggerInstance.log(`RemoteAppWrapper host >>>`, host);
45
65
  const RemoteApp = () => {
46
66
  LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
47
67
  const {
@@ -62,6 +82,8 @@ const RemoteAppWrapper = forwardRef(function (
62
82
 
63
83
  const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
64
84
  const providerInfoRef = useRef<any>(null);
85
+ const hostInstance = getHostInstance(moduleName);
86
+ LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
65
87
 
66
88
  useEffect(() => {
67
89
  const renderTimeout = setTimeout(() => {
@@ -82,13 +104,20 @@ const RemoteAppWrapper = forwardRef(function (
82
104
  renderProps,
83
105
  );
84
106
 
85
- // TODO: 寻找当前 remote 实例上的 hostName, 找到 host instance
107
+ LoggerInstance.log(
108
+ `createRemoteComponent LazyComponent hostInstance >>>`,
109
+ hostInstance,
110
+ );
86
111
  const beforeBridgeRenderRes =
87
- host?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(renderProps) ||
88
- {};
112
+ hostInstance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(
113
+ renderProps,
114
+ ) || {};
115
+ // @ts-ignore
89
116
  renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
90
117
  providerReturn.render(renderProps);
91
- host?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(renderProps);
118
+ hostInstance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(
119
+ renderProps,
120
+ );
92
121
  });
93
122
 
94
123
  return () => {
@@ -99,7 +128,8 @@ const RemoteAppWrapper = forwardRef(function (
99
128
  `createRemoteComponent LazyComponent destroy >>>`,
100
129
  { moduleName, basename, dom: renderDom.current },
101
130
  );
102
- host?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
131
+
132
+ hostInstance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
103
133
  moduleName,
104
134
  dom: renderDom.current,
105
135
  basename,
@@ -107,12 +137,13 @@ const RemoteAppWrapper = forwardRef(function (
107
137
  fallback,
108
138
  ...resProps,
109
139
  });
140
+
110
141
  providerInfoRef.current?.destroy({
111
142
  moduleName,
112
143
  dom: renderDom.current,
113
144
  });
114
145
 
115
- host?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
146
+ hostInstance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
116
147
  moduleName,
117
148
  dom: renderDom.current,
118
149
  basename,