@module-federation/bridge-react 0.0.0-next-20240822063818 → 0.0.0-next-20240822101913

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,10 +1,17 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
- ## 0.0.0-next-20240822063818
3
+ ## 0.0.0-next-20240822101913
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - @module-federation/bridge-shared@0.0.0-next-20240822063818
7
+ - 3082116: feat: support module isolated reported
8
+ - @module-federation/bridge-shared@0.0.0-next-20240822101913
9
+
10
+ ## 0.5.1
11
+
12
+ ### Patch Changes
13
+
14
+ - @module-federation/bridge-shared@0.5.1
8
15
 
9
16
  ## 0.5.0
10
17
 
package/dist/index.cjs.js CHANGED
@@ -177,7 +177,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
177
177
  }
178
178
  );
179
179
  };
180
- RemoteApp2["__APP_VERSION__"] = "0.5.0";
180
+ RemoteApp2["__APP_VERSION__"] = "0.5.1";
181
181
  return /* @__PURE__ */ React.createElement(RemoteApp2, null);
182
182
  });
183
183
  function withRouterData(WrappedComponent) {
@@ -327,6 +327,7 @@ if (process.env.NODE_ENV === "production") {
327
327
  };
328
328
  }
329
329
  function createBridgeComponent(bridgeInfo) {
330
+ let provider;
330
331
  return () => {
331
332
  const rootMap = /* @__PURE__ */ new Map();
332
333
  const RawComponent = (info) => {
@@ -341,62 +342,65 @@ function createBridgeComponent(bridgeInfo) {
341
342
  }
342
343
  ));
343
344
  };
344
- return {
345
- async render(info) {
346
- context.LoggerInstance.log(`createBridgeComponent render Info`, info);
347
- const {
348
- moduleName,
349
- dom,
350
- basename,
351
- memoryRoute,
352
- fallback,
353
- ...propsInfo
354
- } = info;
355
- const rootComponentWithErrorBoundary = (
356
- // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
357
- /* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
358
- RawComponent,
359
- {
360
- appInfo: {
361
- moduleName,
362
- basename,
363
- memoryRoute
364
- },
365
- propsInfo
345
+ if (!provider) {
346
+ provider = {
347
+ async render(info) {
348
+ context.LoggerInstance.log(`createBridgeComponent render Info`, info);
349
+ const {
350
+ moduleName,
351
+ dom,
352
+ basename,
353
+ memoryRoute,
354
+ fallback,
355
+ ...propsInfo
356
+ } = info;
357
+ const rootComponentWithErrorBoundary = (
358
+ // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
359
+ /* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
360
+ RawComponent,
361
+ {
362
+ appInfo: {
363
+ moduleName,
364
+ basename,
365
+ memoryRoute
366
+ },
367
+ propsInfo
368
+ }
369
+ ))
370
+ );
371
+ if (context.atLeastReact18(React__namespace)) {
372
+ if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
373
+ Promise.resolve(
374
+ bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
375
+ ).then((root) => rootMap.set(info.dom, root));
376
+ } else {
377
+ const root = client.createRoot(info.dom);
378
+ root.render(rootComponentWithErrorBoundary);
379
+ rootMap.set(info.dom, root);
366
380
  }
367
- ))
368
- );
369
- if (context.atLeastReact18(React__namespace)) {
370
- if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
371
- Promise.resolve(
372
- bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
373
- ).then((root) => rootMap.set(info.dom, root));
374
381
  } else {
375
- const root = client.createRoot(info.dom);
376
- root.render(rootComponentWithErrorBoundary);
377
- rootMap.set(info.dom, root);
382
+ const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
383
+ renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
378
384
  }
379
- } else {
380
- const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
381
- renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
382
- }
383
- },
384
- async destroy(info) {
385
- context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
386
- dom: info.dom
387
- });
388
- if (context.atLeastReact18(React__namespace)) {
389
- const root = rootMap.get(info.dom);
390
- root == null ? void 0 : root.unmount();
391
- rootMap.delete(info.dom);
392
- } else {
393
- ReactDOM.unmountComponentAtNode(info.dom);
385
+ },
386
+ async destroy(info) {
387
+ context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
388
+ dom: info.dom
389
+ });
390
+ if (context.atLeastReact18(React__namespace)) {
391
+ const root = rootMap.get(info.dom);
392
+ root == null ? void 0 : root.unmount();
393
+ rootMap.delete(info.dom);
394
+ } else {
395
+ ReactDOM.unmountComponentAtNode(info.dom);
396
+ }
397
+ },
398
+ rawComponent: bridgeInfo.rootComponent,
399
+ __BRIDGE_FN__: (_args) => {
394
400
  }
395
- },
396
- rawComponent: bridgeInfo.rootComponent,
397
- __BRIDGE_FN__: (_args) => {
398
- }
399
- };
401
+ };
402
+ }
403
+ return provider;
400
404
  };
401
405
  }
402
406
  exports.createBridgeComponent = createBridgeComponent;
package/dist/index.d.ts CHANGED
@@ -5,14 +5,7 @@ import { ErrorInfo } from 'react';
5
5
  import { PropsWithChildren } from 'react';
6
6
  import * as React_2 from 'react';
7
7
 
8
- export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
9
- render(info: RenderFnParams & any): Promise<void>;
10
- destroy(info: {
11
- dom: HTMLElement;
12
- }): Promise<void>;
13
- rawComponent: React_2.ComponentType<T>;
14
- __BRIDGE_FN__: (_args: T) => void;
15
- };
8
+ export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => Provider<T>;
16
9
 
17
10
  export declare function createRemoteComponent<T, E extends keyof T>(info: {
18
11
  loader: () => Promise<T>;
@@ -45,6 +38,15 @@ declare type FallbackProps = {
45
38
  resetErrorBoundary: (...args: any[]) => void;
46
39
  };
47
40
 
41
+ declare type Provider<T> = {
42
+ render(info: any): Promise<void>;
43
+ destroy(info: {
44
+ dom: HTMLElement;
45
+ }): Promise<void>;
46
+ rawComponent: React_2.ComponentType<T>;
47
+ __BRIDGE_FN__: (_args: T) => void;
48
+ };
49
+
48
50
  declare type ProviderFnParams<T> = {
49
51
  rootComponent: React_2.ComponentType<T>;
50
52
  render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
package/dist/index.es.js CHANGED
@@ -158,7 +158,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
158
158
  }
159
159
  );
160
160
  };
161
- RemoteApp2["__APP_VERSION__"] = "0.5.0";
161
+ RemoteApp2["__APP_VERSION__"] = "0.5.1";
162
162
  return /* @__PURE__ */ React__default.createElement(RemoteApp2, null);
163
163
  });
164
164
  function withRouterData(WrappedComponent) {
@@ -308,6 +308,7 @@ if (process.env.NODE_ENV === "production") {
308
308
  };
309
309
  }
310
310
  function createBridgeComponent(bridgeInfo) {
311
+ let provider;
311
312
  return () => {
312
313
  const rootMap = /* @__PURE__ */ new Map();
313
314
  const RawComponent = (info) => {
@@ -322,62 +323,65 @@ function createBridgeComponent(bridgeInfo) {
322
323
  }
323
324
  ));
324
325
  };
325
- return {
326
- async render(info) {
327
- LoggerInstance.log(`createBridgeComponent render Info`, info);
328
- const {
329
- moduleName,
330
- dom,
331
- basename,
332
- memoryRoute,
333
- fallback,
334
- ...propsInfo
335
- } = info;
336
- const rootComponentWithErrorBoundary = (
337
- // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
338
- /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
339
- RawComponent,
340
- {
341
- appInfo: {
342
- moduleName,
343
- basename,
344
- memoryRoute
345
- },
346
- propsInfo
326
+ if (!provider) {
327
+ provider = {
328
+ async render(info) {
329
+ LoggerInstance.log(`createBridgeComponent render Info`, info);
330
+ const {
331
+ moduleName,
332
+ dom,
333
+ basename,
334
+ memoryRoute,
335
+ fallback,
336
+ ...propsInfo
337
+ } = info;
338
+ const rootComponentWithErrorBoundary = (
339
+ // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
340
+ /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
341
+ RawComponent,
342
+ {
343
+ appInfo: {
344
+ moduleName,
345
+ basename,
346
+ memoryRoute
347
+ },
348
+ propsInfo
349
+ }
350
+ ))
351
+ );
352
+ if (atLeastReact18(React)) {
353
+ if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
354
+ Promise.resolve(
355
+ bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
356
+ ).then((root) => rootMap.set(info.dom, root));
357
+ } else {
358
+ const root = client.createRoot(info.dom);
359
+ root.render(rootComponentWithErrorBoundary);
360
+ rootMap.set(info.dom, root);
347
361
  }
348
- ))
349
- );
350
- if (atLeastReact18(React)) {
351
- if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
352
- Promise.resolve(
353
- bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
354
- ).then((root) => rootMap.set(info.dom, root));
355
362
  } else {
356
- const root = client.createRoot(info.dom);
357
- root.render(rootComponentWithErrorBoundary);
358
- rootMap.set(info.dom, root);
363
+ const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
364
+ renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
359
365
  }
360
- } else {
361
- const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
362
- renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
363
- }
364
- },
365
- async destroy(info) {
366
- LoggerInstance.log(`createBridgeComponent destroy Info`, {
367
- dom: info.dom
368
- });
369
- if (atLeastReact18(React)) {
370
- const root = rootMap.get(info.dom);
371
- root == null ? void 0 : root.unmount();
372
- rootMap.delete(info.dom);
373
- } else {
374
- ReactDOM.unmountComponentAtNode(info.dom);
366
+ },
367
+ async destroy(info) {
368
+ LoggerInstance.log(`createBridgeComponent destroy Info`, {
369
+ dom: info.dom
370
+ });
371
+ if (atLeastReact18(React)) {
372
+ const root = rootMap.get(info.dom);
373
+ root == null ? void 0 : root.unmount();
374
+ rootMap.delete(info.dom);
375
+ } else {
376
+ ReactDOM.unmountComponentAtNode(info.dom);
377
+ }
378
+ },
379
+ rawComponent: bridgeInfo.rootComponent,
380
+ __BRIDGE_FN__: (_args) => {
375
381
  }
376
- },
377
- rawComponent: bridgeInfo.rootComponent,
378
- __BRIDGE_FN__: (_args) => {
379
- }
380
- };
382
+ };
383
+ }
384
+ return provider;
381
385
  };
382
386
  }
383
387
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/bridge-react",
3
- "version": "0.0.0-next-20240822063818",
3
+ "version": "0.0.0-next-20240822101913",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,7 +35,7 @@
35
35
  "dependencies": {
36
36
  "@loadable/component": "^5.16.4",
37
37
  "react-error-boundary": "^4.0.13",
38
- "@module-federation/bridge-shared": "0.0.0-next-20240822063818"
38
+ "@module-federation/bridge-shared": "0.0.0-next-20240822101913"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": ">=16.9.0",
package/src/provider.tsx CHANGED
@@ -18,8 +18,15 @@ type ProviderFnParams<T> = {
18
18
  id?: HTMLElement | string,
19
19
  ) => RootType | Promise<RootType>;
20
20
  };
21
+ type Provider<T> = {
22
+ render(info: any): Promise<void>;
23
+ destroy(info: { dom: HTMLElement }): Promise<void>;
24
+ rawComponent: React.ComponentType<T>;
25
+ __BRIDGE_FN__: (_args: T) => void;
26
+ };
21
27
 
22
28
  export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
29
+ let provider: Provider<T>;
23
30
  return () => {
24
31
  const rootMap = new Map<any, RootType>();
25
32
  const RawComponent = (info: { propsInfo: T; appInfo: ProviderParams }) => {
@@ -36,63 +43,66 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
36
43
  );
37
44
  };
38
45
 
39
- return {
40
- async render(info: RenderFnParams & any) {
41
- LoggerInstance.log(`createBridgeComponent render Info`, info);
42
- const {
43
- moduleName,
44
- dom,
45
- basename,
46
- memoryRoute,
47
- fallback,
48
- ...propsInfo
49
- } = info;
50
- const rootComponentWithErrorBoundary = (
51
- // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
52
- <ErrorBoundary FallbackComponent={fallback}>
53
- <RawComponent
54
- appInfo={{
55
- moduleName,
56
- basename,
57
- memoryRoute,
58
- }}
59
- propsInfo={propsInfo}
60
- />
61
- </ErrorBoundary>
62
- );
46
+ if (!provider) {
47
+ provider = {
48
+ async render(info: RenderFnParams & any) {
49
+ LoggerInstance.log(`createBridgeComponent render Info`, info);
50
+ const {
51
+ moduleName,
52
+ dom,
53
+ basename,
54
+ memoryRoute,
55
+ fallback,
56
+ ...propsInfo
57
+ } = info;
58
+ const rootComponentWithErrorBoundary = (
59
+ // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
60
+ <ErrorBoundary FallbackComponent={fallback}>
61
+ <RawComponent
62
+ appInfo={{
63
+ moduleName,
64
+ basename,
65
+ memoryRoute,
66
+ }}
67
+ propsInfo={propsInfo}
68
+ />
69
+ </ErrorBoundary>
70
+ );
63
71
 
64
- if (atLeastReact18(React)) {
65
- if (bridgeInfo?.render) {
66
- // in case bridgeInfo?.render is an async function, resolve this to promise
67
- Promise.resolve(
68
- bridgeInfo?.render(rootComponentWithErrorBoundary, dom),
69
- ).then((root: RootType) => rootMap.set(info.dom, root));
72
+ if (atLeastReact18(React)) {
73
+ if (bridgeInfo?.render) {
74
+ // in case bridgeInfo?.render is an async function, resolve this to promise
75
+ Promise.resolve(
76
+ bridgeInfo?.render(rootComponentWithErrorBoundary, dom),
77
+ ).then((root: RootType) => rootMap.set(info.dom, root));
78
+ } else {
79
+ const root: RootType = ReactDOMClient.createRoot(info.dom);
80
+ root.render(rootComponentWithErrorBoundary);
81
+ rootMap.set(info.dom, root);
82
+ }
70
83
  } else {
71
- const root: RootType = ReactDOMClient.createRoot(info.dom);
72
- root.render(rootComponentWithErrorBoundary);
73
- rootMap.set(info.dom, root);
84
+ // react 17 render
85
+ const renderFn = bridgeInfo?.render || ReactDOM.render;
86
+ renderFn?.(rootComponentWithErrorBoundary, info.dom);
74
87
  }
75
- } else {
76
- // react 17 render
77
- const renderFn = bridgeInfo?.render || ReactDOM.render;
78
- renderFn?.(rootComponentWithErrorBoundary, info.dom);
79
- }
80
- },
81
- async destroy(info: { dom: HTMLElement }) {
82
- LoggerInstance.log(`createBridgeComponent destroy Info`, {
83
- dom: info.dom,
84
- });
85
- if (atLeastReact18(React)) {
86
- const root = rootMap.get(info.dom);
87
- (root as ReactDOMClient.Root)?.unmount();
88
- rootMap.delete(info.dom);
89
- } else {
90
- ReactDOM.unmountComponentAtNode(info.dom);
91
- }
92
- },
93
- rawComponent: bridgeInfo.rootComponent,
94
- __BRIDGE_FN__: (_args: T) => {},
95
- };
88
+ },
89
+ async destroy(info: { dom: HTMLElement }) {
90
+ LoggerInstance.log(`createBridgeComponent destroy Info`, {
91
+ dom: info.dom,
92
+ });
93
+ if (atLeastReact18(React)) {
94
+ const root = rootMap.get(info.dom);
95
+ (root as ReactDOMClient.Root)?.unmount();
96
+ rootMap.delete(info.dom);
97
+ } else {
98
+ ReactDOM.unmountComponentAtNode(info.dom);
99
+ }
100
+ },
101
+ rawComponent: bridgeInfo.rootComponent,
102
+ __BRIDGE_FN__: (_args: T) => {},
103
+ };
104
+ }
105
+ return provider;
96
106
  };
97
107
  }
98
108