@module-federation/bridge-react 0.0.0-next-20240903075658 → 0.0.0-next-20240903212627

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/bridge-react",
3
- "version": "0.0.0-next-20240903075658",
3
+ "version": "0.0.0-next-20240903212627",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,13 +35,12 @@
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-20240903075658"
38
+ "@module-federation/bridge-shared": "0.0.0-next-20240903212627"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": ">=16.9.0",
42
42
  "react-dom": ">=16.9.0",
43
- "react-router-dom": ">=4",
44
- "@module-federation/runtime": "0.0.0-next-20240903075658"
43
+ "react-router-dom": ">=4"
45
44
  },
46
45
  "devDependencies": {
47
46
  "@testing-library/react": "15.0.7",
package/src/create.tsx CHANGED
@@ -1,14 +1,12 @@
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
-
7
- import { LoggerInstance } from './utils';
8
8
  import RemoteApp from './remote';
9
9
 
10
- import type { ProviderParams } from '@module-federation/bridge-shared';
11
-
12
10
  export interface RenderFnParams extends ProviderParams {
13
11
  dom?: any;
14
12
  }
package/src/provider.tsx CHANGED
@@ -2,19 +2,14 @@ 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
-
11
- import { RouterContext } from './context';
12
10
  import { LoggerInstance, atLeastReact18 } from './utils';
11
+ import { ErrorBoundary } from 'react-error-boundary';
13
12
 
14
- type RenderParams = RenderFnParams & any;
15
- type DestroyParams = {
16
- dom: HTMLElement;
17
- };
18
13
  type RootType = HTMLElement | ReactDOMClient.Root;
19
14
  type ProviderFnParams<T> = {
20
15
  rootComponent: React.ComponentType<T>;
@@ -22,9 +17,8 @@ type ProviderFnParams<T> = {
22
17
  App: React.ReactElement,
23
18
  id?: HTMLElement | string,
24
19
  ) => RootType | Promise<RootType>;
25
- renderLifecycle?: (params: RenderFnParams) => void;
26
- destroyLifecycle?: (params: DestroyParams) => void;
27
20
  };
21
+
28
22
  export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
29
23
  return () => {
30
24
  const rootMap = new Map<any, RootType>();
@@ -43,7 +37,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
43
37
  };
44
38
 
45
39
  return {
46
- async render(info: RenderParams) {
40
+ async render(info: RenderFnParams & any) {
47
41
  LoggerInstance.log(`createBridgeComponent render Info`, info);
48
42
  const {
49
43
  moduleName,
@@ -67,7 +61,6 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
67
61
  </ErrorBoundary>
68
62
  );
69
63
 
70
- bridgeInfo?.renderLifecycle?.(info);
71
64
  if (atLeastReact18(React)) {
72
65
  if (bridgeInfo?.render) {
73
66
  // in case bridgeInfo?.render is an async function, resolve this to promise
@@ -85,7 +78,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
85
78
  renderFn?.(rootComponentWithErrorBoundary, info.dom);
86
79
  }
87
80
  },
88
- async destroy(info: DestroyParams) {
81
+ async destroy(info: { dom: HTMLElement }) {
89
82
  LoggerInstance.log(`createBridgeComponent destroy Info`, {
90
83
  dom: info.dom,
91
84
  });
@@ -96,7 +89,6 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
96
89
  } else {
97
90
  ReactDOM.unmountComponentAtNode(info.dom);
98
91
  }
99
- bridgeInfo?.destroyLifecycle?.(info);
100
92
  },
101
93
  rawComponent: bridgeInfo.rootComponent,
102
94
  __BRIDGE_FN__: (_args: T) => {},
@@ -7,12 +7,10 @@ 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
13
 
13
- import hook from '../lifecycle';
14
- import { LoggerInstance, pathJoin } from '../utils';
15
-
16
14
  declare const __APP_VERSION__: string;
17
15
  export interface RenderFnParams extends ProviderParams {
18
16
  dom?: any;
@@ -80,9 +78,6 @@ const RemoteAppWrapper = forwardRef(function (
80
78
  `createRemoteComponent LazyComponent render >>>`,
81
79
  renderProps,
82
80
  );
83
- hook.lifecycle.bridgeRender.emit({
84
- ...renderProps,
85
- });
86
81
  providerReturn.render(renderProps);
87
82
  });
88
83
 
@@ -94,14 +89,6 @@ const RemoteAppWrapper = forwardRef(function (
94
89
  `createRemoteComponent LazyComponent destroy >>>`,
95
90
  { moduleName, basename, dom: renderDom.current },
96
91
  );
97
- hook.lifecycle.bridgeDestroy.emit({
98
- moduleName,
99
- dom: renderDom.current,
100
- basename,
101
- memoryRoute,
102
- fallback,
103
- ...resProps,
104
- });
105
92
  providerInfoRef.current?.destroy({
106
93
  dom: renderDom.current,
107
94
  });
package/src/lifecycle.ts DELETED
@@ -1,17 +0,0 @@
1
- import { getInstance } from '@module-federation/runtime';
2
- import helper from '@module-federation/runtime/helpers';
3
-
4
- const registerPlugin = helper.global.registerPlugins;
5
- const pluginHelper = helper.global.pluginHelper;
6
- const host = getInstance()!;
7
- const pluginSystem = new pluginHelper.PluginSystem({
8
- bridgeRender: new pluginHelper.SyncHook<[Record<string, any>], void>(),
9
- bridgeDestroy: new pluginHelper.SyncHook<[Record<string, any>], void>(),
10
- });
11
-
12
- registerPlugin<typeof pluginSystem.lifecycle, typeof pluginSystem>(
13
- host.options.plugins,
14
- [pluginSystem],
15
- );
16
-
17
- export default pluginSystem;