@module-federation/bridge-react 0.0.0-next-20241114041727 → 0.0.0-next-20241114065146

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,22 +1,12 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
- ## 0.0.0-next-20241114041727
4
-
5
- ### Patch Changes
6
-
7
- - 3082116: feat: feat: support lifecycyle hooks in module-deferation bridge
8
- - Updated dependencies [3082116]
9
- - @module-federation/runtime@0.0.0-next-20241114041727
10
- - @module-federation/sdk@0.0.0-next-20241114041727
11
- - @module-federation/bridge-shared@0.0.0-next-20241114041727
12
-
13
- ## 0.7.3
3
+ ## 0.0.0-next-20241114065146
14
4
 
15
5
  ### Patch Changes
16
6
 
17
7
  - Updated dependencies [4ab9295]
18
- - @module-federation/sdk@0.7.3
19
- - @module-federation/bridge-shared@0.7.3
8
+ - @module-federation/sdk@0.0.0-next-20241114065146
9
+ - @module-federation/bridge-shared@0.0.0-next-20241114065146
20
10
 
21
11
  ## 0.7.2
22
12
 
@@ -329,26 +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.getRootDomDefaultClassName = getRootDomDefaultClassName;
354
336
  exports.pathJoin = pathJoin;
@@ -328,28 +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
335
  atLeastReact18 as a,
353
- getRootDomDefaultClassName as g,
354
336
  pathJoin as p
355
337
  };
package/dist/index.cjs.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
- const context = require("./context-BcJ-YlNr.cjs");
4
+ const context = require("./context-BBLu8BlQ.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" } });
@@ -138,14 +137,11 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
138
137
  const rootRef = ref && "current" in ref ? ref : React.useRef(null);
139
138
  const renderDom = React.useRef(null);
140
139
  const providerInfoRef = React.useRef(null);
141
- const hostInstance = runtime.getInstance();
142
- context.LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
143
140
  React.useEffect(() => {
144
141
  const renderTimeout = setTimeout(() => {
145
- var _a, _b, _c, _d, _e, _f;
146
142
  const providerReturn = providerInfo();
147
143
  providerInfoRef.current = providerReturn;
148
- let renderProps = {
144
+ const renderProps = {
149
145
  moduleName,
150
146
  dom: rootRef.current,
151
147
  basename,
@@ -158,63 +154,34 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
158
154
  `createRemoteComponent LazyComponent render >>>`,
159
155
  renderProps
160
156
  );
161
- context.LoggerInstance.log(
162
- `createRemoteComponent LazyComponent hostInstance >>>`,
163
- hostInstance
164
- );
165
- 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(
166
- renderProps
167
- )) || {};
168
- renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
169
157
  providerReturn.render(renderProps);
170
- (_f = (_e = (_d = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(
171
- renderProps
172
- );
173
158
  });
174
159
  return () => {
175
160
  clearTimeout(renderTimeout);
176
161
  setTimeout(() => {
177
- var _a, _b, _c, _d, _e, _f, _g, _h;
162
+ var _a, _b;
178
163
  if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
179
164
  context.LoggerInstance.log(
180
165
  `createRemoteComponent LazyComponent destroy >>>`,
181
166
  { moduleName, basename, dom: renderDom.current }
182
167
  );
183
- (_d = (_c = (_b = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
184
- moduleName,
185
- dom: renderDom.current,
186
- basename,
187
- memoryRoute,
188
- fallback,
189
- ...resProps
190
- });
191
- (_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
192
- moduleName,
168
+ (_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
193
169
  dom: renderDom.current
194
170
  });
195
- (_h = (_g = (_f = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
196
- moduleName,
197
- dom: renderDom.current,
198
- basename,
199
- memoryRoute,
200
- fallback,
201
- ...resProps
202
- });
203
171
  }
204
172
  });
205
173
  };
206
174
  }, []);
207
- const rootComponentClassName = `${context.getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
208
175
  return /* @__PURE__ */ React.createElement(
209
176
  "div",
210
177
  {
211
- className: rootComponentClassName,
178
+ className: props == null ? void 0 : props.className,
212
179
  style: props == null ? void 0 : props.style,
213
180
  ref: rootRef
214
181
  }
215
182
  );
216
183
  };
217
- RemoteApp2["__APP_VERSION__"] = "0.7.3";
184
+ RemoteApp2["__APP_VERSION__"] = "0.7.2";
218
185
  return /* @__PURE__ */ React.createElement(RemoteApp2, null);
219
186
  });
220
187
  function withRouterData(WrappedComponent) {
@@ -366,8 +333,6 @@ if (process.env.NODE_ENV === "production") {
366
333
  function createBridgeComponent(bridgeInfo) {
367
334
  return () => {
368
335
  const rootMap = /* @__PURE__ */ new Map();
369
- const instance = runtime.getInstance();
370
- context.LoggerInstance.log(`createBridgeComponent remote instance`, instance);
371
336
  const RawComponent = (info) => {
372
337
  const { appInfo, propsInfo, ...restProps } = info;
373
338
  const { moduleName, memoryRoute, basename = "/" } = appInfo;
@@ -382,7 +347,6 @@ function createBridgeComponent(bridgeInfo) {
382
347
  };
383
348
  return {
384
349
  async render(info) {
385
- var _a, _b, _c, _d, _e, _f;
386
350
  context.LoggerInstance.log(`createBridgeComponent render Info`, info);
387
351
  const {
388
352
  moduleName,
@@ -392,7 +356,6 @@ function createBridgeComponent(bridgeInfo) {
392
356
  fallback,
393
357
  ...propsInfo
394
358
  } = info;
395
- 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)) || {};
396
359
  const rootComponentWithErrorBoundary = (
397
360
  // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
398
361
  /* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
@@ -403,7 +366,7 @@ function createBridgeComponent(bridgeInfo) {
403
366
  basename,
404
367
  memoryRoute
405
368
  },
406
- propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
369
+ propsInfo
407
370
  }
408
371
  ))
409
372
  );
@@ -421,14 +384,11 @@ function createBridgeComponent(bridgeInfo) {
421
384
  const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
422
385
  renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
423
386
  }
424
- ((_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)) || {};
425
387
  },
426
388
  async destroy(info) {
427
- var _a, _b, _c, _d, _e, _f;
428
389
  context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
429
390
  dom: info.dom
430
391
  });
431
- (_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);
432
392
  if (context.atLeastReact18(React__namespace)) {
433
393
  const root = rootMap.get(info.dom);
434
394
  root == null ? void 0 : root.unmount();
@@ -436,7 +396,6 @@ function createBridgeComponent(bridgeInfo) {
436
396
  } else {
437
397
  ReactDOM.unmountComponentAtNode(info.dom);
438
398
  }
439
- (_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);
440
399
  },
441
400
  rawComponent: bridgeInfo.rootComponent,
442
401
  __BRIDGE_FN__: (_args) => {
package/dist/index.d.ts CHANGED
@@ -6,8 +6,10 @@ import { PropsWithChildren } from 'react';
6
6
  import * as React_2 from 'react';
7
7
 
8
8
  export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
9
- render(info: RenderParams): Promise<void>;
10
- destroy(info: DestroyParams): Promise<void>;
9
+ render(info: RenderFnParams & any): Promise<void>;
10
+ destroy(info: {
11
+ dom: HTMLElement;
12
+ }): Promise<void>;
11
13
  rawComponent: React_2.ComponentType<T>;
12
14
  __BRIDGE_FN__: (_args: T) => void;
13
15
  };
@@ -19,11 +21,6 @@ export declare function createRemoteComponent<T, E extends keyof T>(info: {
19
21
  export?: E;
20
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>>;
21
23
 
22
- declare type DestroyParams = {
23
- moduleName: string;
24
- dom: HTMLElement;
25
- };
26
-
27
24
  declare type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {
28
25
  fallback?: never;
29
26
  FallbackComponent: ComponentType<FallbackProps>;
@@ -67,10 +64,6 @@ export declare interface RenderFnParams extends ProviderParams {
67
64
  dom: HTMLElement;
68
65
  }
69
66
 
70
- declare type RenderParams = RenderFnParams & {
71
- [key: string]: unknown;
72
- };
73
-
74
67
  declare type RootType = HTMLElement | default_3.Root;
75
68
 
76
69
  export { }
package/dist/index.es.js CHANGED
@@ -1,8 +1,7 @@
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 atLeastReact18, R as RouterContext } from "./context-CUbFnlO5.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
- import { getInstance } from "@module-federation/runtime";
6
5
  import ReactDOM from "react-dom";
7
6
  const ErrorBoundaryContext = createContext(null);
8
7
  const initialState = {
@@ -119,14 +118,11 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
119
118
  const rootRef = ref && "current" in ref ? ref : useRef(null);
120
119
  const renderDom = useRef(null);
121
120
  const providerInfoRef = useRef(null);
122
- const hostInstance = getInstance();
123
- LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
124
121
  useEffect(() => {
125
122
  const renderTimeout = setTimeout(() => {
126
- var _a, _b, _c, _d, _e, _f;
127
123
  const providerReturn = providerInfo();
128
124
  providerInfoRef.current = providerReturn;
129
- let renderProps = {
125
+ const renderProps = {
130
126
  moduleName,
131
127
  dom: rootRef.current,
132
128
  basename,
@@ -139,63 +135,34 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
139
135
  `createRemoteComponent LazyComponent render >>>`,
140
136
  renderProps
141
137
  );
142
- LoggerInstance.log(
143
- `createRemoteComponent LazyComponent hostInstance >>>`,
144
- hostInstance
145
- );
146
- 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(
147
- renderProps
148
- )) || {};
149
- renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
150
138
  providerReturn.render(renderProps);
151
- (_f = (_e = (_d = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(
152
- renderProps
153
- );
154
139
  });
155
140
  return () => {
156
141
  clearTimeout(renderTimeout);
157
142
  setTimeout(() => {
158
- var _a, _b, _c, _d, _e, _f, _g, _h;
143
+ var _a, _b;
159
144
  if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
160
145
  LoggerInstance.log(
161
146
  `createRemoteComponent LazyComponent destroy >>>`,
162
147
  { moduleName, basename, dom: renderDom.current }
163
148
  );
164
- (_d = (_c = (_b = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
165
- moduleName,
166
- dom: renderDom.current,
167
- basename,
168
- memoryRoute,
169
- fallback,
170
- ...resProps
171
- });
172
- (_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
173
- moduleName,
149
+ (_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
174
150
  dom: renderDom.current
175
151
  });
176
- (_h = (_g = (_f = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
177
- moduleName,
178
- dom: renderDom.current,
179
- basename,
180
- memoryRoute,
181
- fallback,
182
- ...resProps
183
- });
184
152
  }
185
153
  });
186
154
  };
187
155
  }, []);
188
- const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
189
156
  return /* @__PURE__ */ React__default.createElement(
190
157
  "div",
191
158
  {
192
- className: rootComponentClassName,
159
+ className: props == null ? void 0 : props.className,
193
160
  style: props == null ? void 0 : props.style,
194
161
  ref: rootRef
195
162
  }
196
163
  );
197
164
  };
198
- RemoteApp2["__APP_VERSION__"] = "0.7.3";
165
+ RemoteApp2["__APP_VERSION__"] = "0.7.2";
199
166
  return /* @__PURE__ */ React__default.createElement(RemoteApp2, null);
200
167
  });
201
168
  function withRouterData(WrappedComponent) {
@@ -347,8 +314,6 @@ if (process.env.NODE_ENV === "production") {
347
314
  function createBridgeComponent(bridgeInfo) {
348
315
  return () => {
349
316
  const rootMap = /* @__PURE__ */ new Map();
350
- const instance = getInstance();
351
- LoggerInstance.log(`createBridgeComponent remote instance`, instance);
352
317
  const RawComponent = (info) => {
353
318
  const { appInfo, propsInfo, ...restProps } = info;
354
319
  const { moduleName, memoryRoute, basename = "/" } = appInfo;
@@ -363,7 +328,6 @@ function createBridgeComponent(bridgeInfo) {
363
328
  };
364
329
  return {
365
330
  async render(info) {
366
- var _a, _b, _c, _d, _e, _f;
367
331
  LoggerInstance.log(`createBridgeComponent render Info`, info);
368
332
  const {
369
333
  moduleName,
@@ -373,7 +337,6 @@ function createBridgeComponent(bridgeInfo) {
373
337
  fallback,
374
338
  ...propsInfo
375
339
  } = info;
376
- 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)) || {};
377
340
  const rootComponentWithErrorBoundary = (
378
341
  // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
379
342
  /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
@@ -384,7 +347,7 @@ function createBridgeComponent(bridgeInfo) {
384
347
  basename,
385
348
  memoryRoute
386
349
  },
387
- propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
350
+ propsInfo
388
351
  }
389
352
  ))
390
353
  );
@@ -402,14 +365,11 @@ function createBridgeComponent(bridgeInfo) {
402
365
  const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
403
366
  renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
404
367
  }
405
- ((_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)) || {};
406
368
  },
407
369
  async destroy(info) {
408
- var _a, _b, _c, _d, _e, _f;
409
370
  LoggerInstance.log(`createBridgeComponent destroy Info`, {
410
371
  dom: info.dom
411
372
  });
412
- (_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);
413
373
  if (atLeastReact18(React)) {
414
374
  const root = rootMap.get(info.dom);
415
375
  root == null ? void 0 : root.unmount();
@@ -417,7 +377,6 @@ function createBridgeComponent(bridgeInfo) {
417
377
  } else {
418
378
  ReactDOM.unmountComponentAtNode(info.dom);
419
379
  }
420
- (_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);
421
380
  },
422
381
  rawComponent: bridgeInfo.rootComponent,
423
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-BcJ-YlNr.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-CUbFnlO5.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-BcJ-YlNr.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-CUbFnlO5.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-BcJ-YlNr.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-CUbFnlO5.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-20241114041727",
3
+ "version": "0.0.0-next-20241114065146",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -41,9 +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-20241114041727",
45
- "@module-federation/sdk": "0.0.0-next-20241114041727",
46
- "@module-federation/runtime": "0.0.0-next-20241114041727"
44
+ "@module-federation/bridge-shared": "0.0.0-next-20241114065146",
45
+ "@module-federation/sdk": "0.0.0-next-20241114065146"
47
46
  },
48
47
  "peerDependencies": {
49
48
  "react": ">=16.9.0",
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,24 +2,15 @@ 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';
9
- import { ErrorBoundary } from 'react-error-boundary';
10
- import { RouterContext } from './context';
11
10
  import { LoggerInstance, atLeastReact18 } from './utils';
12
- import { getInstance } from '@module-federation/runtime';
11
+ import { ErrorBoundary } from 'react-error-boundary';
13
12
 
14
- type RenderParams = RenderFnParams & {
15
- [key: string]: unknown;
16
- };
17
- type DestroyParams = {
18
- moduleName: string;
19
- dom: HTMLElement;
20
- };
21
13
  type RootType = HTMLElement | ReactDOMClient.Root;
22
-
23
14
  type ProviderFnParams<T> = {
24
15
  rootComponent: React.ComponentType<T>;
25
16
  render?: (
@@ -31,9 +22,6 @@ type ProviderFnParams<T> = {
31
22
  export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
32
23
  return () => {
33
24
  const rootMap = new Map<any, RootType>();
34
- const instance = getInstance();
35
- LoggerInstance.log(`createBridgeComponent remote instance`, instance);
36
-
37
25
  const RawComponent = (info: { propsInfo: T; appInfo: ProviderParams }) => {
38
26
  const { appInfo, propsInfo, ...restProps } = info;
39
27
  const { moduleName, memoryRoute, basename = '/' } = appInfo;
@@ -49,7 +37,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
49
37
  };
50
38
 
51
39
  return {
52
- async render(info: RenderParams) {
40
+ async render(info: RenderFnParams & any) {
53
41
  LoggerInstance.log(`createBridgeComponent render Info`, info);
54
42
  const {
55
43
  moduleName,
@@ -59,10 +47,6 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
59
47
  fallback,
60
48
  ...propsInfo
61
49
  } = info;
62
-
63
- const beforeBridgeRenderRes =
64
- instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(info) || {};
65
-
66
50
  const rootComponentWithErrorBoundary = (
67
51
  // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
68
52
  <ErrorBoundary FallbackComponent={fallback}>
@@ -72,13 +56,11 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
72
56
  basename,
73
57
  memoryRoute,
74
58
  }}
75
- propsInfo={
76
- { ...propsInfo, ...beforeBridgeRenderRes?.extraProps } as T
77
- }
59
+ propsInfo={propsInfo}
78
60
  />
79
61
  </ErrorBoundary>
80
62
  );
81
- // call render function
63
+
82
64
  if (atLeastReact18(React)) {
83
65
  if (bridgeInfo?.render) {
84
66
  // in case bridgeInfo?.render is an async function, resolve this to promise
@@ -95,18 +77,11 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
95
77
  const renderFn = bridgeInfo?.render || ReactDOM.render;
96
78
  renderFn?.(rootComponentWithErrorBoundary, info.dom);
97
79
  }
98
-
99
- instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
100
80
  },
101
-
102
- async destroy(info: DestroyParams) {
81
+ async destroy(info: { dom: HTMLElement }) {
103
82
  LoggerInstance.log(`createBridgeComponent destroy Info`, {
104
83
  dom: info.dom,
105
84
  });
106
-
107
- instance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit(info);
108
-
109
- // call destroy function
110
85
  if (atLeastReact18(React)) {
111
86
  const root = rootMap.get(info.dom);
112
87
  (root as ReactDOMClient.Root)?.unmount();
@@ -114,8 +89,6 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
114
89
  } else {
115
90
  ReactDOM.unmountComponentAtNode(info.dom);
116
91
  }
117
-
118
- instance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit(info);
119
92
  },
120
93
  rawComponent: bridgeInfo.rootComponent,
121
94
  __BRIDGE_FN__: (_args: T) => {},
@@ -7,10 +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 { LoggerInstance, pathJoin, getRootDomDefaultClassName } from '../utils';
13
- import { getInstance } from '@module-federation/runtime';
14
13
 
15
14
  declare const __APP_VERSION__: string;
16
15
  export interface RenderFnParams extends ProviderParams {
@@ -60,15 +59,13 @@ const RemoteAppWrapper = forwardRef(function (
60
59
 
61
60
  const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
62
61
  const providerInfoRef = useRef<any>(null);
63
- const hostInstance = getInstance();
64
- LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
65
62
 
66
63
  useEffect(() => {
67
64
  const renderTimeout = setTimeout(() => {
68
65
  const providerReturn = providerInfo();
69
66
  providerInfoRef.current = providerReturn;
70
67
 
71
- let renderProps = {
68
+ const renderProps = {
72
69
  moduleName,
73
70
  dom: rootRef.current,
74
71
  basename,
@@ -81,21 +78,7 @@ const RemoteAppWrapper = forwardRef(function (
81
78
  `createRemoteComponent LazyComponent render >>>`,
82
79
  renderProps,
83
80
  );
84
-
85
- LoggerInstance.log(
86
- `createRemoteComponent LazyComponent hostInstance >>>`,
87
- hostInstance,
88
- );
89
- const beforeBridgeRenderRes =
90
- hostInstance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(
91
- renderProps,
92
- ) || {};
93
- // @ts-ignore
94
- renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
95
81
  providerReturn.render(renderProps);
96
- hostInstance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(
97
- renderProps,
98
- );
99
82
  });
100
83
 
101
84
  return () => {
@@ -106,39 +89,17 @@ const RemoteAppWrapper = forwardRef(function (
106
89
  `createRemoteComponent LazyComponent destroy >>>`,
107
90
  { moduleName, basename, dom: renderDom.current },
108
91
  );
109
-
110
- hostInstance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
111
- moduleName,
112
- dom: renderDom.current,
113
- basename,
114
- memoryRoute,
115
- fallback,
116
- ...resProps,
117
- });
118
-
119
92
  providerInfoRef.current?.destroy({
120
- moduleName,
121
- dom: renderDom.current,
122
- });
123
-
124
- hostInstance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
125
- moduleName,
126
93
  dom: renderDom.current,
127
- basename,
128
- memoryRoute,
129
- fallback,
130
- ...resProps,
131
94
  });
132
95
  }
133
96
  });
134
97
  };
135
98
  }, []);
136
99
 
137
- // bridge-remote-root
138
- const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props?.className}`;
139
100
  return (
140
101
  <div
141
- className={rootComponentClassName}
102
+ className={props?.className}
142
103
  style={props?.style}
143
104
  ref={rootRef}
144
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
@@ -1,5 +1,4 @@
1
1
  import React from 'react';
2
- import { FederationHost } from '@module-federation/runtime';
3
2
  import { createLogger } from '@module-federation/sdk';
4
3
 
5
4
  export const LoggerInstance = createLogger(
@@ -42,24 +41,3 @@ export function pathJoin(...args: string[]) {
42
41
  }, '');
43
42
  return res || '/';
44
43
  }
45
-
46
- export const getModuleName = (id: string) => {
47
- if (!id) {
48
- return id;
49
- }
50
- // separate module name without detailed module path
51
- // @vmok-e2e/edenx-demo-app2/button -> @vmok-e2e/edenx-demo-app2
52
- const idArray = id.split('/');
53
- if (idArray.length < 2) {
54
- return id;
55
- }
56
- return idArray[0] + '/' + idArray[1];
57
- };
58
-
59
- export const getRootDomDefaultClassName = (moduleName: string) => {
60
- if (!moduleName) {
61
- return '';
62
- }
63
- const name = getModuleName(moduleName).replace(/\@/, '').replace(/\//, '-');
64
- return `bridge-root-component-${name}`;
65
- };
package/vite.config.ts CHANGED
@@ -36,7 +36,6 @@ export default defineConfig({
36
36
  'react-router-dom/',
37
37
  'react-router-dom/index.js',
38
38
  'react-router-dom/dist/index.js',
39
- '@module-federation/runtime',
40
39
  ],
41
40
  plugins: [
42
41
  {