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

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,13 +1,26 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
- ## 0.0.0-next-20241111073908
3
+ ## 0.0.0-next-20241112074706
4
+
5
+ ### Patch Changes
6
+
7
+ - @module-federation/sdk@0.0.0-next-20241112074706
8
+ - @module-federation/bridge-shared@0.0.0-next-20241112074706
9
+
10
+ ## 0.7.2
11
+
12
+ ### Patch Changes
13
+
14
+ - @module-federation/sdk@0.7.2
15
+ - @module-federation/bridge-shared@0.7.2
16
+
17
+ ## 0.7.1
4
18
 
5
19
  ### Patch Changes
6
20
 
7
- - 3082116: feat: feat: support lifecycyle hooks in module-deferation bridge
8
21
  - Updated dependencies [6db4c5f]
9
- - @module-federation/sdk@0.0.0-next-20241111073908
10
- - @module-federation/bridge-shared@0.0.0-next-20241111073908
22
+ - @module-federation/sdk@0.7.1
23
+ - @module-federation/bridge-shared@0.7.1
11
24
 
12
25
  ## 0.7.0
13
26
 
@@ -329,27 +329,8 @@ function pathJoin(...args) {
329
329
  }, "");
330
330
  return res || "/";
331
331
  }
332
- const getModuleName = (id) => {
333
- if (!id) {
334
- return id;
335
- }
336
- const idArray = id.split("/");
337
- if (idArray.length < 2) {
338
- return id;
339
- }
340
- return idArray[0] + "/" + idArray[1];
341
- };
342
- const getRootDomDefaultClassName = (moduleName) => {
343
- if (!moduleName) {
344
- return "";
345
- }
346
- const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
347
- return `bridge-root-component-${name}`;
348
- };
349
332
  const RouterContext = React.createContext(null);
350
333
  exports.LoggerInstance = LoggerInstance;
351
334
  exports.RouterContext = RouterContext;
352
335
  exports.atLeastReact18 = atLeastReact18;
353
- exports.getModuleName = getModuleName;
354
- exports.getRootDomDefaultClassName = getRootDomDefaultClassName;
355
336
  exports.pathJoin = pathJoin;
@@ -328,29 +328,10 @@ function pathJoin(...args) {
328
328
  }, "");
329
329
  return res || "/";
330
330
  }
331
- const getModuleName = (id) => {
332
- if (!id) {
333
- return id;
334
- }
335
- const idArray = id.split("/");
336
- if (idArray.length < 2) {
337
- return id;
338
- }
339
- return idArray[0] + "/" + idArray[1];
340
- };
341
- const getRootDomDefaultClassName = (moduleName) => {
342
- if (!moduleName) {
343
- return "";
344
- }
345
- const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
346
- return `bridge-root-component-${name}`;
347
- };
348
331
  const RouterContext = React__default.createContext(null);
349
332
  export {
350
333
  LoggerInstance as L,
351
334
  RouterContext as R,
352
- getModuleName as a,
353
- atLeastReact18 as b,
354
- getRootDomDefaultClassName as g,
335
+ atLeastReact18 as a,
355
336
  pathJoin as p
356
337
  };
package/dist/index.cjs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
- const context = require("./context-DmzxwI_7.cjs");
4
+ const context = require("./context-BBLu8BlQ.cjs");
5
5
  const ReactRouterDOM = require("react-router-dom");
6
6
  const ReactDOM = require("react-dom");
7
7
  function _interopNamespaceDefault(e2) {
@@ -121,20 +121,6 @@ function e() {
121
121
  const t = new PopStateEvent("popstate", { state: window.history.state });
122
122
  window.dispatchEvent(t);
123
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
- };
138
124
  const RemoteAppWrapper = React.forwardRef(function(props, ref) {
139
125
  const RemoteApp2 = () => {
140
126
  context.LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
@@ -151,14 +137,11 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
151
137
  const rootRef = ref && "current" in ref ? ref : React.useRef(null);
152
138
  const renderDom = React.useRef(null);
153
139
  const providerInfoRef = React.useRef(null);
154
- const hostInstance = getHostInstance(moduleName);
155
- context.LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
156
140
  React.useEffect(() => {
157
141
  const renderTimeout = setTimeout(() => {
158
- var _a, _b, _c, _d, _e, _f;
159
142
  const providerReturn = providerInfo();
160
143
  providerInfoRef.current = providerReturn;
161
- let renderProps = {
144
+ const renderProps = {
162
145
  moduleName,
163
146
  dom: rootRef.current,
164
147
  basename,
@@ -171,63 +154,34 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
171
154
  `createRemoteComponent LazyComponent render >>>`,
172
155
  renderProps
173
156
  );
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
- )) || {};
181
- renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
182
157
  providerReturn.render(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
- );
186
158
  });
187
159
  return () => {
188
160
  clearTimeout(renderTimeout);
189
161
  setTimeout(() => {
190
- var _a, _b, _c, _d, _e, _f, _g, _h;
162
+ var _a, _b;
191
163
  if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
192
164
  context.LoggerInstance.log(
193
165
  `createRemoteComponent LazyComponent destroy >>>`,
194
166
  { moduleName, basename, dom: renderDom.current }
195
167
  );
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({
197
- moduleName,
198
- dom: renderDom.current,
199
- basename,
200
- memoryRoute,
201
- fallback,
202
- ...resProps
203
- });
204
- (_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
205
- moduleName,
168
+ (_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
206
169
  dom: renderDom.current
207
170
  });
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({
209
- moduleName,
210
- dom: renderDom.current,
211
- basename,
212
- memoryRoute,
213
- fallback,
214
- ...resProps
215
- });
216
171
  }
217
172
  });
218
173
  };
219
174
  }, []);
220
- const rootComponentClassName = `${context.getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
221
175
  return /* @__PURE__ */ React.createElement(
222
176
  "div",
223
177
  {
224
- className: rootComponentClassName,
178
+ className: props == null ? void 0 : props.className,
225
179
  style: props == null ? void 0 : props.style,
226
180
  ref: rootRef
227
181
  }
228
182
  );
229
183
  };
230
- RemoteApp2["__APP_VERSION__"] = "0.7.0";
184
+ RemoteApp2["__APP_VERSION__"] = "0.7.2";
231
185
  return /* @__PURE__ */ React.createElement(RemoteApp2, null);
232
186
  });
233
187
  function withRouterData(WrappedComponent) {
@@ -391,17 +345,8 @@ function createBridgeComponent(bridgeInfo) {
391
345
  }
392
346
  ));
393
347
  };
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
- };
402
348
  return {
403
349
  async render(info) {
404
- var _a, _b, _c, _d, _e, _f;
405
350
  context.LoggerInstance.log(`createBridgeComponent render Info`, info);
406
351
  const {
407
352
  moduleName,
@@ -411,9 +356,6 @@ function createBridgeComponent(bridgeInfo) {
411
356
  fallback,
412
357
  ...propsInfo
413
358
  } = info;
414
- const instance = getModuleInstance(moduleName);
415
- context.LoggerInstance.log(`createBridgeComponent remote instance`, instance);
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)) || {};
417
359
  const rootComponentWithErrorBoundary = (
418
360
  // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
419
361
  /* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
@@ -424,7 +366,7 @@ function createBridgeComponent(bridgeInfo) {
424
366
  basename,
425
367
  memoryRoute
426
368
  },
427
- propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
369
+ propsInfo
428
370
  }
429
371
  ))
430
372
  );
@@ -442,16 +384,11 @@ function createBridgeComponent(bridgeInfo) {
442
384
  const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
443
385
  renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
444
386
  }
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)) || {};
446
387
  },
447
388
  async destroy(info) {
448
- var _a, _b, _c, _d, _e, _f;
449
389
  context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
450
390
  dom: info.dom
451
391
  });
452
- const instance = getModuleInstance(info.moduleName);
453
- context.LoggerInstance.log(`createBridgeComponent remote instance`, instance);
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);
455
392
  if (context.atLeastReact18(React__namespace)) {
456
393
  const root = rootMap.get(info.dom);
457
394
  root == null ? void 0 : root.unmount();
@@ -459,7 +396,6 @@ function createBridgeComponent(bridgeInfo) {
459
396
  } else {
460
397
  ReactDOM.unmountComponentAtNode(info.dom);
461
398
  }
462
- (_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeDestroy) == null ? void 0 : _f.emit(info);
463
399
  },
464
400
  rawComponent: bridgeInfo.rootComponent,
465
401
  __BRIDGE_FN__: (_args) => {
package/dist/index.d.ts CHANGED
@@ -5,16 +5,11 @@ import { ErrorInfo } from 'react';
5
5
  import { PropsWithChildren } from 'react';
6
6
  import * as React_2 from 'react';
7
7
 
8
- declare type BridgeHooks = {
9
- beforeBridgeRender?: (params: RenderFnParams) => void | Record<string, any>;
10
- afterBridgeRender?: (params: RenderFnParams) => void | Record<string, any>;
11
- beforeBridgeDestroy?: (params: DestroyParams) => void | Record<string, any>;
12
- afterBridgeDestroy?: (params: DestroyParams) => void | Record<string, any>;
13
- };
14
-
15
8
  export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
16
- render(info: RenderParams): Promise<void>;
17
- destroy(info: DestroyParams): Promise<void>;
9
+ render(info: RenderFnParams & any): Promise<void>;
10
+ destroy(info: {
11
+ dom: HTMLElement;
12
+ }): Promise<void>;
18
13
  rawComponent: React_2.ComponentType<T>;
19
14
  __BRIDGE_FN__: (_args: T) => void;
20
15
  };
@@ -26,11 +21,6 @@ export declare function createRemoteComponent<T, E extends keyof T>(info: {
26
21
  export?: E;
27
22
  }): default_2.ForwardRefExoticComponent<default_2.PropsWithoutRef<ProviderParams & ("__BRIDGE_FN__" extends keyof (T[E] extends (...args: any) => any ? ReturnType<T[E]> : never) ? (T[E] extends (...args: any) => any ? ReturnType<T[E]> : never)["__BRIDGE_FN__"] extends (...args: any) => any ? Parameters<(T[E] extends (...args: any) => any ? ReturnType<T[E]> : never)["__BRIDGE_FN__"]>[0] : {} : {})> & default_2.RefAttributes<HTMLDivElement>>;
28
23
 
29
- declare type DestroyParams = {
30
- moduleName: string;
31
- dom: HTMLElement;
32
- };
33
-
34
24
  declare type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {
35
25
  fallback?: never;
36
26
  FallbackComponent: ComponentType<FallbackProps>;
@@ -58,7 +48,6 @@ declare type FallbackProps = {
58
48
  declare type ProviderFnParams<T> = {
59
49
  rootComponent: React_2.ComponentType<T>;
60
50
  render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
61
- hooks?: BridgeHooks;
62
51
  };
63
52
 
64
53
  export declare interface ProviderParams {
@@ -75,8 +64,6 @@ export declare interface RenderFnParams extends ProviderParams {
75
64
  dom: HTMLElement;
76
65
  }
77
66
 
78
- declare type RenderParams = RenderFnParams & any;
79
-
80
67
  declare type RootType = HTMLElement | default_3.Root;
81
68
 
82
69
  export { }
package/dist/index.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import React__default, { createContext, Component, createElement, isValidElement, forwardRef, useRef, useEffect, useContext, useState } from "react";
3
- import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin, a as getModuleName, b as atLeastReact18, R as RouterContext } from "./context-Dh6IUBWT.js";
3
+ import { L as LoggerInstance, p as pathJoin, a as atLeastReact18, R as RouterContext } from "./context-BcyT-d0V.js";
4
4
  import * as ReactRouterDOM from "react-router-dom";
5
5
  import ReactDOM from "react-dom";
6
6
  const ErrorBoundaryContext = createContext(null);
@@ -102,20 +102,6 @@ function e() {
102
102
  const t = new PopStateEvent("popstate", { state: window.history.state });
103
103
  window.dispatchEvent(t);
104
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
- };
119
105
  const RemoteAppWrapper = forwardRef(function(props, ref) {
120
106
  const RemoteApp2 = () => {
121
107
  LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
@@ -132,14 +118,11 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
132
118
  const rootRef = ref && "current" in ref ? ref : useRef(null);
133
119
  const renderDom = useRef(null);
134
120
  const providerInfoRef = useRef(null);
135
- const hostInstance = getHostInstance(moduleName);
136
- LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
137
121
  useEffect(() => {
138
122
  const renderTimeout = setTimeout(() => {
139
- var _a, _b, _c, _d, _e, _f;
140
123
  const providerReturn = providerInfo();
141
124
  providerInfoRef.current = providerReturn;
142
- let renderProps = {
125
+ const renderProps = {
143
126
  moduleName,
144
127
  dom: rootRef.current,
145
128
  basename,
@@ -152,63 +135,34 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
152
135
  `createRemoteComponent LazyComponent render >>>`,
153
136
  renderProps
154
137
  );
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
- )) || {};
162
- renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
163
138
  providerReturn.render(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
- );
167
139
  });
168
140
  return () => {
169
141
  clearTimeout(renderTimeout);
170
142
  setTimeout(() => {
171
- var _a, _b, _c, _d, _e, _f, _g, _h;
143
+ var _a, _b;
172
144
  if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
173
145
  LoggerInstance.log(
174
146
  `createRemoteComponent LazyComponent destroy >>>`,
175
147
  { moduleName, basename, dom: renderDom.current }
176
148
  );
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({
178
- moduleName,
179
- dom: renderDom.current,
180
- basename,
181
- memoryRoute,
182
- fallback,
183
- ...resProps
184
- });
185
- (_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
186
- moduleName,
149
+ (_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
187
150
  dom: renderDom.current
188
151
  });
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({
190
- moduleName,
191
- dom: renderDom.current,
192
- basename,
193
- memoryRoute,
194
- fallback,
195
- ...resProps
196
- });
197
152
  }
198
153
  });
199
154
  };
200
155
  }, []);
201
- const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
202
156
  return /* @__PURE__ */ React__default.createElement(
203
157
  "div",
204
158
  {
205
- className: rootComponentClassName,
159
+ className: props == null ? void 0 : props.className,
206
160
  style: props == null ? void 0 : props.style,
207
161
  ref: rootRef
208
162
  }
209
163
  );
210
164
  };
211
- RemoteApp2["__APP_VERSION__"] = "0.7.0";
165
+ RemoteApp2["__APP_VERSION__"] = "0.7.2";
212
166
  return /* @__PURE__ */ React__default.createElement(RemoteApp2, null);
213
167
  });
214
168
  function withRouterData(WrappedComponent) {
@@ -372,17 +326,8 @@ function createBridgeComponent(bridgeInfo) {
372
326
  }
373
327
  ));
374
328
  };
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
- };
383
329
  return {
384
330
  async render(info) {
385
- var _a, _b, _c, _d, _e, _f;
386
331
  LoggerInstance.log(`createBridgeComponent render Info`, info);
387
332
  const {
388
333
  moduleName,
@@ -392,9 +337,6 @@ function createBridgeComponent(bridgeInfo) {
392
337
  fallback,
393
338
  ...propsInfo
394
339
  } = info;
395
- const instance = getModuleInstance(moduleName);
396
- LoggerInstance.log(`createBridgeComponent remote instance`, instance);
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)) || {};
398
340
  const rootComponentWithErrorBoundary = (
399
341
  // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
400
342
  /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
@@ -405,7 +347,7 @@ function createBridgeComponent(bridgeInfo) {
405
347
  basename,
406
348
  memoryRoute
407
349
  },
408
- propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
350
+ propsInfo
409
351
  }
410
352
  ))
411
353
  );
@@ -423,16 +365,11 @@ function createBridgeComponent(bridgeInfo) {
423
365
  const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
424
366
  renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
425
367
  }
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)) || {};
427
368
  },
428
369
  async destroy(info) {
429
- var _a, _b, _c, _d, _e, _f;
430
370
  LoggerInstance.log(`createBridgeComponent destroy Info`, {
431
371
  dom: info.dom
432
372
  });
433
- const instance = getModuleInstance(info.moduleName);
434
- LoggerInstance.log(`createBridgeComponent remote instance`, instance);
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);
436
373
  if (atLeastReact18(React)) {
437
374
  const root = rootMap.get(info.dom);
438
375
  root == null ? void 0 : root.unmount();
@@ -440,7 +377,6 @@ function createBridgeComponent(bridgeInfo) {
440
377
  } else {
441
378
  ReactDOM.unmountComponentAtNode(info.dom);
442
379
  }
443
- (_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeDestroy) == null ? void 0 : _f.emit(info);
444
380
  },
445
381
  rawComponent: bridgeInfo.rootComponent,
446
382
  __BRIDGE_FN__: (_args) => {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
4
  const ReactRouterDom$1 = require("react-router-dom/index.js");
5
- const context = require("./context-DmzxwI_7.cjs");
5
+ const context = require("./context-BBLu8BlQ.cjs");
6
6
  const ReactRouterDom = require("react-router-dom/index.js");
7
7
  function _interopNamespaceDefault(e) {
8
8
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -1,6 +1,6 @@
1
1
  import React__default, { useContext } from "react";
2
2
  import * as ReactRouterDom$1 from "react-router-dom/index.js";
3
- import { R as RouterContext, L as LoggerInstance } from "./context-Dh6IUBWT.js";
3
+ import { R as RouterContext, L as LoggerInstance } from "./context-BcyT-d0V.js";
4
4
  export * from "react-router-dom/index.js";
5
5
  function WraperRouter(props) {
6
6
  const { basename, ...propsRes } = props;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
4
  const ReactRouterDom = require("react-router-dom/dist/index.js");
5
- const context = require("./context-DmzxwI_7.cjs");
5
+ const context = require("./context-BBLu8BlQ.cjs");
6
6
  function _interopNamespaceDefault(e) {
7
7
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
8
8
  if (e) {
@@ -1,7 +1,7 @@
1
1
  import React__default, { useContext } from "react";
2
2
  import * as ReactRouterDom from "react-router-dom/dist/index.js";
3
3
  export * from "react-router-dom/dist/index.js";
4
- import { R as RouterContext, L as LoggerInstance } from "./context-Dh6IUBWT.js";
4
+ import { R as RouterContext, L as LoggerInstance } from "./context-BcyT-d0V.js";
5
5
  function WraperRouter(props) {
6
6
  const { basename, ...propsRes } = props;
7
7
  const routerContextProps = useContext(RouterContext) || {};
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
4
  const ReactRouterDom = require("react-router-dom/");
5
- const context = require("./context-DmzxwI_7.cjs");
5
+ const context = require("./context-BBLu8BlQ.cjs");
6
6
  function _interopNamespaceDefault(e) {
7
7
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
8
8
  if (e) {
@@ -65,7 +65,7 @@ function WrapperRouterProvider(props) {
65
65
  return /* @__PURE__ */ React.createElement(RouterProvider, { router: MemeoryRouterInstance });
66
66
  } else {
67
67
  const BrowserRouterInstance = createBrowserRouter(routers, {
68
- basename: routerContextProps.basename || (router == null ? void 0 : router.basename),
68
+ basename: routerContextProps.basename,
69
69
  future: router.future,
70
70
  window: router.window
71
71
  });
package/dist/router.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import React__default, { useContext } from "react";
2
2
  import * as ReactRouterDom from "react-router-dom/";
3
3
  export * from "react-router-dom/";
4
- import { R as RouterContext, L as LoggerInstance } from "./context-Dh6IUBWT.js";
4
+ import { R as RouterContext, L as LoggerInstance } from "./context-BcyT-d0V.js";
5
5
  function WrapperRouter(props) {
6
6
  const { basename, ...propsRes } = props;
7
7
  const routerContextProps = useContext(RouterContext) || {};
@@ -47,7 +47,7 @@ function WrapperRouterProvider(props) {
47
47
  return /* @__PURE__ */ React__default.createElement(RouterProvider, { router: MemeoryRouterInstance });
48
48
  } else {
49
49
  const BrowserRouterInstance = createBrowserRouter(routers, {
50
- basename: routerContextProps.basename || (router == null ? void 0 : router.basename),
50
+ basename: routerContextProps.basename,
51
51
  future: router.future,
52
52
  window: router.window
53
53
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/bridge-react",
3
- "version": "0.0.0-next-20241111073908",
3
+ "version": "0.0.0-next-20241112074706",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -41,8 +41,8 @@
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-20241111073908",
45
- "@module-federation/sdk": "0.0.0-next-20241111073908"
44
+ "@module-federation/bridge-shared": "0.0.0-next-20241112074706",
45
+ "@module-federation/sdk": "0.0.0-next-20241112074706"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "react": ">=16.9.0",
@@ -62,8 +62,7 @@
62
62
  "react-router-dom": "6.22.3",
63
63
  "typescript": "^5.2.2",
64
64
  "vite": "^5.2.14",
65
- "vite-plugin-dts": "^3.9.1",
66
- "@module-federation/runtime": "0.0.0-next-20241111073908"
65
+ "vite-plugin-dts": "^3.9.1"
67
66
  },
68
67
  "scripts": {
69
68
  "dev": "vite",
package/src/create.tsx CHANGED
@@ -1,11 +1,11 @@
1
1
  import React, { forwardRef } from 'react';
2
+ import type { ProviderParams } from '@module-federation/bridge-shared';
3
+ import { LoggerInstance } from './utils';
2
4
  import {
3
5
  ErrorBoundary,
4
6
  ErrorBoundaryPropsWithComponent,
5
7
  } from 'react-error-boundary';
6
- import { LoggerInstance } from './utils';
7
8
  import RemoteApp from './remote';
8
- import type { ProviderParams } from '@module-federation/bridge-shared';
9
9
 
10
10
  export interface RenderFnParams extends ProviderParams {
11
11
  dom?: any;
package/src/provider.tsx CHANGED
@@ -2,35 +2,21 @@ import { useLayoutEffect, useRef, useState } from 'react';
2
2
  import * as React from 'react';
3
3
  import ReactDOM from 'react-dom';
4
4
  import ReactDOMClient from 'react-dom/client';
5
+ import { RouterContext } from './context';
5
6
  import type {
6
7
  ProviderParams,
7
8
  RenderFnParams,
8
9
  } from '@module-federation/bridge-shared';
10
+ import { LoggerInstance, atLeastReact18 } from './utils';
9
11
  import { ErrorBoundary } from 'react-error-boundary';
10
- import { RouterContext } from './context';
11
- import { LoggerInstance, atLeastReact18, getModuleName } from './utils';
12
12
 
13
- type RenderParams = RenderFnParams & any;
14
- type DestroyParams = {
15
- moduleName: string;
16
- dom: HTMLElement;
17
- };
18
13
  type RootType = HTMLElement | ReactDOMClient.Root;
19
-
20
- type BridgeHooks = {
21
- beforeBridgeRender?: (params: RenderFnParams) => void | Record<string, any>;
22
- afterBridgeRender?: (params: RenderFnParams) => void | Record<string, any>;
23
- beforeBridgeDestroy?: (params: DestroyParams) => void | Record<string, any>;
24
- afterBridgeDestroy?: (params: DestroyParams) => void | Record<string, any>;
25
- };
26
-
27
14
  type ProviderFnParams<T> = {
28
15
  rootComponent: React.ComponentType<T>;
29
16
  render?: (
30
17
  App: React.ReactElement,
31
18
  id?: HTMLElement | string,
32
19
  ) => RootType | Promise<RootType>;
33
- hooks?: BridgeHooks;
34
20
  };
35
21
 
36
22
  export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
@@ -50,16 +36,8 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
50
36
  );
51
37
  };
52
38
 
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
-
61
39
  return {
62
- async render(info: RenderParams) {
40
+ async render(info: RenderFnParams & any) {
63
41
  LoggerInstance.log(`createBridgeComponent render Info`, info);
64
42
  const {
65
43
  moduleName,
@@ -69,13 +47,6 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
69
47
  fallback,
70
48
  ...propsInfo
71
49
  } = info;
72
-
73
- const instance = getModuleInstance(moduleName);
74
- LoggerInstance.log(`createBridgeComponent remote instance`, instance);
75
-
76
- const beforeBridgeRenderRes =
77
- instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(info) || {};
78
-
79
50
  const rootComponentWithErrorBoundary = (
80
51
  // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
81
52
  <ErrorBoundary FallbackComponent={fallback}>
@@ -85,13 +56,11 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
85
56
  basename,
86
57
  memoryRoute,
87
58
  }}
88
- propsInfo={
89
- { ...propsInfo, ...beforeBridgeRenderRes?.extraProps } as T
90
- }
59
+ propsInfo={propsInfo}
91
60
  />
92
61
  </ErrorBoundary>
93
62
  );
94
- // call render function
63
+
95
64
  if (atLeastReact18(React)) {
96
65
  if (bridgeInfo?.render) {
97
66
  // in case bridgeInfo?.render is an async function, resolve this to promise
@@ -108,19 +77,11 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
108
77
  const renderFn = bridgeInfo?.render || ReactDOM.render;
109
78
  renderFn?.(rootComponentWithErrorBoundary, info.dom);
110
79
  }
111
-
112
- instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
113
80
  },
114
-
115
- async destroy(info: DestroyParams) {
81
+ async destroy(info: { dom: HTMLElement }) {
116
82
  LoggerInstance.log(`createBridgeComponent destroy Info`, {
117
83
  dom: info.dom,
118
84
  });
119
- const instance = getModuleInstance(info.moduleName);
120
- LoggerInstance.log(`createBridgeComponent remote instance`, instance);
121
- instance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit(info);
122
-
123
- // call destroy function
124
85
  if (atLeastReact18(React)) {
125
86
  const root = rootMap.get(info.dom);
126
87
  (root as ReactDOMClient.Root)?.unmount();
@@ -128,8 +89,6 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
128
89
  } else {
129
90
  ReactDOM.unmountComponentAtNode(info.dom);
130
91
  }
131
-
132
- instance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit(info);
133
92
  },
134
93
  rawComponent: bridgeInfo.rootComponent,
135
94
  __BRIDGE_FN__: (_args: T) => {},
@@ -7,15 +7,9 @@ import React, {
7
7
  } from 'react';
8
8
  import * as ReactRouterDOM from 'react-router-dom';
9
9
  import type { ProviderParams } from '@module-federation/bridge-shared';
10
+ import { LoggerInstance, pathJoin } from '../utils';
10
11
  import { dispatchPopstateEnv } from '@module-federation/bridge-shared';
11
12
  import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
12
- import {
13
- LoggerInstance,
14
- pathJoin,
15
- getModuleName,
16
- getRootDomDefaultClassName,
17
- } from '../utils';
18
- import { FederationHost } from '@module-federation/runtime';
19
13
 
20
14
  declare const __APP_VERSION__: string;
21
15
  export interface RenderFnParams extends ProviderParams {
@@ -41,23 +35,6 @@ interface RemoteAppParams {
41
35
  fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
42
36
  }
43
37
 
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
-
61
38
  const RemoteAppWrapper = forwardRef(function (
62
39
  props: RemoteAppParams & RenderFnParams,
63
40
  ref,
@@ -82,15 +59,13 @@ const RemoteAppWrapper = forwardRef(function (
82
59
 
83
60
  const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
84
61
  const providerInfoRef = useRef<any>(null);
85
- const hostInstance = getHostInstance(moduleName);
86
- LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
87
62
 
88
63
  useEffect(() => {
89
64
  const renderTimeout = setTimeout(() => {
90
65
  const providerReturn = providerInfo();
91
66
  providerInfoRef.current = providerReturn;
92
67
 
93
- let renderProps = {
68
+ const renderProps = {
94
69
  moduleName,
95
70
  dom: rootRef.current,
96
71
  basename,
@@ -103,21 +78,7 @@ const RemoteAppWrapper = forwardRef(function (
103
78
  `createRemoteComponent LazyComponent render >>>`,
104
79
  renderProps,
105
80
  );
106
-
107
- LoggerInstance.log(
108
- `createRemoteComponent LazyComponent hostInstance >>>`,
109
- hostInstance,
110
- );
111
- const beforeBridgeRenderRes =
112
- hostInstance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(
113
- renderProps,
114
- ) || {};
115
- // @ts-ignore
116
- renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
117
81
  providerReturn.render(renderProps);
118
- hostInstance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(
119
- renderProps,
120
- );
121
82
  });
122
83
 
123
84
  return () => {
@@ -128,39 +89,17 @@ const RemoteAppWrapper = forwardRef(function (
128
89
  `createRemoteComponent LazyComponent destroy >>>`,
129
90
  { moduleName, basename, dom: renderDom.current },
130
91
  );
131
-
132
- hostInstance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
133
- moduleName,
134
- dom: renderDom.current,
135
- basename,
136
- memoryRoute,
137
- fallback,
138
- ...resProps,
139
- });
140
-
141
92
  providerInfoRef.current?.destroy({
142
- moduleName,
143
- dom: renderDom.current,
144
- });
145
-
146
- hostInstance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
147
- moduleName,
148
93
  dom: renderDom.current,
149
- basename,
150
- memoryRoute,
151
- fallback,
152
- ...resProps,
153
94
  });
154
95
  }
155
96
  });
156
97
  };
157
98
  }, []);
158
99
 
159
- // bridge-remote-root
160
- const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props?.className}`;
161
100
  return (
162
101
  <div
163
- className={rootComponentClassName}
102
+ className={props?.className}
164
103
  style={props?.style}
165
104
  ref={rootRef}
166
105
  ></div>
package/src/router-v5.tsx CHANGED
@@ -2,6 +2,7 @@ import React, { useContext } from 'react';
2
2
  // The upper alias react-router-dom$ into this file avoids the loop
3
3
  // @ts-ignore
4
4
  import * as ReactRouterDom from 'react-router-dom/index.js';
5
+
5
6
  import { RouterContext } from './context';
6
7
  import { LoggerInstance } from './utils';
7
8
 
package/src/router.tsx CHANGED
@@ -59,7 +59,7 @@ function WrapperRouterProvider(
59
59
  return <RouterProvider router={MemeoryRouterInstance} />;
60
60
  } else {
61
61
  const BrowserRouterInstance = createBrowserRouter(routers, {
62
- basename: routerContextProps.basename || router?.basename,
62
+ basename: routerContextProps.basename,
63
63
  future: router.future,
64
64
  window: router.window,
65
65
  });
package/src/utils.ts CHANGED
@@ -41,24 +41,3 @@ export function pathJoin(...args: string[]) {
41
41
  }, '');
42
42
  return res || '/';
43
43
  }
44
-
45
- export const getModuleName = (id: string) => {
46
- if (!id) {
47
- return id;
48
- }
49
- // separate module name without detailed module path
50
- // @vmok-e2e/edenx-demo-app2/button -> @vmok-e2e/edenx-demo-app2
51
- const idArray = id.split('/');
52
- if (idArray.length < 2) {
53
- return id;
54
- }
55
- return idArray[0] + '/' + idArray[1];
56
- };
57
-
58
- export const getRootDomDefaultClassName = (moduleName: string) => {
59
- if (!moduleName) {
60
- return '';
61
- }
62
- const name = getModuleName(moduleName).replace(/\@/, '').replace(/\//, '-');
63
- return `bridge-root-component-${name}`;
64
- };