@module-federation/bridge-react 0.0.0-next-20240923034121 → 0.0.0-next-20240923065315

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,13 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
- ## 0.0.0-next-20240923034121
3
+ ## 0.0.0-next-20240923065315
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - 3082116: feat: support module isolated reported
8
8
  - Updated dependencies [3082116]
9
- - @module-federation/runtime@0.0.0-next-20240923034121
10
- - @module-federation/bridge-shared@0.0.0-next-20240923034121
9
+ - @module-federation/runtime@0.0.0-next-20240923065315
10
+ - @module-federation/bridge-shared@0.0.0-next-20240923065315
11
11
 
12
12
  ## 0.6.6
13
13
 
package/dist/index.cjs.js CHANGED
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
3
  const React = require("react");
5
4
  const context = require("./context--mtFt3tp.cjs");
@@ -1071,7 +1070,7 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
1071
1070
  function getGlobalShareScope() {
1072
1071
  return Global.__FEDERATION__.__SHARE__;
1073
1072
  }
1074
- var pluginHelper$1 = /* @__PURE__ */ Object.freeze({
1073
+ var pluginHelper = /* @__PURE__ */ Object.freeze({
1075
1074
  __proto__: null,
1076
1075
  SyncHook,
1077
1076
  AsyncHook,
@@ -1103,24 +1102,31 @@ const GlobalUtils = {
1103
1102
  getPreloaded,
1104
1103
  setPreloaded,
1105
1104
  registerPlugins,
1106
- pluginHelper: pluginHelper$1
1105
+ pluginHelper
1107
1106
  };
1108
1107
  var helpers = {
1109
1108
  global: GlobalUtils,
1110
1109
  share: ShareUtils
1111
1110
  };
1112
- const registerPlugin = helpers.global.registerPlugins;
1113
- const pluginHelper = helpers.global.pluginHelper;
1114
- const host = runtime.getInstance();
1115
- const pluginSystem = new pluginHelper.PluginSystem({
1116
- beforeBridgeRender: new pluginHelper.SyncHook(),
1117
- beforeBridgeDestroy: new pluginHelper.SyncHook()
1118
- });
1119
- registerPlugin(
1120
- (_a = host == null ? void 0 : host.options) == null ? void 0 : _a.plugins,
1121
- [pluginSystem]
1122
- );
1111
+ function registerBridgeLifeCycle() {
1112
+ var _a;
1113
+ const { registerPlugins: registerPlugins2, pluginHelper: pluginHelper2 } = helpers.global;
1114
+ const host = runtime.getInstance();
1115
+ const pluginSystem = new pluginHelper2.PluginSystem({
1116
+ beforeBridgeRender: new pluginHelper2.SyncHook(),
1117
+ beforeBridgeDestroy: new pluginHelper2.SyncHook()
1118
+ });
1119
+ if (host) {
1120
+ registerPlugins2(
1121
+ (_a = host == null ? void 0 : host.options) == null ? void 0 : _a.plugins,
1122
+ [pluginSystem]
1123
+ );
1124
+ return pluginSystem;
1125
+ }
1126
+ return null;
1127
+ }
1123
1128
  const RemoteAppWrapper = React.forwardRef(function(props, ref) {
1129
+ const bridgeHook = registerBridgeLifeCycle();
1124
1130
  const RemoteApp2 = () => {
1125
1131
  context.LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
1126
1132
  const {
@@ -1138,6 +1144,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
1138
1144
  const providerInfoRef = React.useRef(null);
1139
1145
  React.useEffect(() => {
1140
1146
  const renderTimeout = setTimeout(() => {
1147
+ var _a, _b;
1141
1148
  const providerReturn = providerInfo();
1142
1149
  providerInfoRef.current = providerReturn;
1143
1150
  const renderProps = {
@@ -1153,29 +1160,33 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
1153
1160
  `createRemoteComponent LazyComponent render >>>`,
1154
1161
  renderProps
1155
1162
  );
1156
- pluginSystem.lifecycle.beforeBridgeRender.emit({
1157
- ...renderProps
1158
- });
1163
+ if (bridgeHook && ((_a = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _a.beforeBridgeRender)) {
1164
+ (_b = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _b.beforeBridgeRender.emit({
1165
+ ...renderProps
1166
+ });
1167
+ }
1159
1168
  providerReturn.render(renderProps);
1160
1169
  });
1161
1170
  return () => {
1162
1171
  clearTimeout(renderTimeout);
1163
1172
  setTimeout(() => {
1164
- var _a2, _b;
1165
- if ((_a2 = providerInfoRef.current) == null ? void 0 : _a2.destroy) {
1173
+ var _a, _b, _c, _d;
1174
+ if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
1166
1175
  context.LoggerInstance.log(
1167
1176
  `createRemoteComponent LazyComponent destroy >>>`,
1168
1177
  { moduleName, basename, dom: renderDom.current }
1169
1178
  );
1170
- pluginSystem.lifecycle.beforeBridgeDestroy.emit({
1171
- moduleName,
1172
- dom: renderDom.current,
1173
- basename,
1174
- memoryRoute,
1175
- fallback,
1176
- ...resProps
1177
- });
1178
- (_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
1179
+ if (bridgeHook && ((_b = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _b.beforeBridgeDestroy)) {
1180
+ (_c = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy.emit({
1181
+ moduleName,
1182
+ dom: renderDom.current,
1183
+ basename,
1184
+ memoryRoute,
1185
+ fallback,
1186
+ ...resProps
1187
+ });
1188
+ }
1189
+ (_d = providerInfoRef.current) == null ? void 0 : _d.destroy({
1179
1190
  dom: renderDom.current
1180
1191
  });
1181
1192
  }
@@ -1196,7 +1207,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
1196
1207
  });
1197
1208
  function withRouterData(WrappedComponent) {
1198
1209
  const Component = React.forwardRef(function(props, ref) {
1199
- var _a2;
1210
+ var _a;
1200
1211
  let enableDispathPopstate = false;
1201
1212
  let routerContextVal;
1202
1213
  try {
@@ -1226,7 +1237,7 @@ function withRouterData(WrappedComponent) {
1226
1237
  const match = useRouteMatch == null ? void 0 : useRouteMatch();
1227
1238
  if (useHistory) {
1228
1239
  const history = useHistory == null ? void 0 : useHistory();
1229
- basename = (_a2 = history == null ? void 0 : history.createHref) == null ? void 0 : _a2.call(history, { pathname: "/" });
1240
+ basename = (_a = history == null ? void 0 : history.createHref) == null ? void 0 : _a.call(history, { pathname: "/" });
1230
1241
  }
1231
1242
  if (match) {
1232
1243
  basename = context.pathJoin(basename, (match == null ? void 0 : match.path) || "/");
package/dist/index.d.ts CHANGED
@@ -2,12 +2,8 @@ import { ComponentType } from 'react';
2
2
  import { default as default_2 } from 'react';
3
3
  import { default as default_3 } from 'react-dom/client';
4
4
  import { ErrorInfo } from 'react';
5
- import { PluginSystem } from '@module-federation/runtime/dist/src/utils/hooks';
6
5
  import { PropsWithChildren } from 'react';
7
6
  import * as React_2 from 'react';
8
- import { SyncHook } from '@module-federation/runtime/dist/src/utils/hooks';
9
-
10
- export declare type BridgeRuntimePlugin = typeof pluginSystem;
11
7
 
12
8
  export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
13
9
  render(info: RenderParams): Promise<void>;
@@ -51,11 +47,6 @@ declare type FallbackProps = {
51
47
  resetErrorBoundary: (...args: any[]) => void;
52
48
  };
53
49
 
54
- declare const pluginSystem: PluginSystem< {
55
- beforeBridgeRender: SyncHook<[Record<string, any>], void>;
56
- beforeBridgeDestroy: SyncHook<[Record<string, any>], void>;
57
- }>;
58
-
59
50
  declare type ProviderFnParams<T> = {
60
51
  rootComponent: React_2.ComponentType<T>;
61
52
  render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
package/dist/index.es.js CHANGED
@@ -1,4 +1,3 @@
1
- var _a;
2
1
  import * as React from "react";
3
2
  import React__default, { createContext, Component, createElement, isValidElement, forwardRef, useRef, useEffect, useContext, useState } from "react";
4
3
  import { L as LoggerInstance, p as pathJoin, f, a as atLeastReact18, R as RouterContext } from "./context-Bw2PEwa6.js";
@@ -1052,7 +1051,7 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
1052
1051
  function getGlobalShareScope() {
1053
1052
  return Global.__FEDERATION__.__SHARE__;
1054
1053
  }
1055
- var pluginHelper$1 = /* @__PURE__ */ Object.freeze({
1054
+ var pluginHelper = /* @__PURE__ */ Object.freeze({
1056
1055
  __proto__: null,
1057
1056
  SyncHook,
1058
1057
  AsyncHook,
@@ -1084,24 +1083,31 @@ const GlobalUtils = {
1084
1083
  getPreloaded,
1085
1084
  setPreloaded,
1086
1085
  registerPlugins,
1087
- pluginHelper: pluginHelper$1
1086
+ pluginHelper
1088
1087
  };
1089
1088
  var helpers = {
1090
1089
  global: GlobalUtils,
1091
1090
  share: ShareUtils
1092
1091
  };
1093
- const registerPlugin = helpers.global.registerPlugins;
1094
- const pluginHelper = helpers.global.pluginHelper;
1095
- const host = getInstance();
1096
- const pluginSystem = new pluginHelper.PluginSystem({
1097
- beforeBridgeRender: new pluginHelper.SyncHook(),
1098
- beforeBridgeDestroy: new pluginHelper.SyncHook()
1099
- });
1100
- registerPlugin(
1101
- (_a = host == null ? void 0 : host.options) == null ? void 0 : _a.plugins,
1102
- [pluginSystem]
1103
- );
1092
+ function registerBridgeLifeCycle() {
1093
+ var _a;
1094
+ const { registerPlugins: registerPlugins2, pluginHelper: pluginHelper2 } = helpers.global;
1095
+ const host = getInstance();
1096
+ const pluginSystem = new pluginHelper2.PluginSystem({
1097
+ beforeBridgeRender: new pluginHelper2.SyncHook(),
1098
+ beforeBridgeDestroy: new pluginHelper2.SyncHook()
1099
+ });
1100
+ if (host) {
1101
+ registerPlugins2(
1102
+ (_a = host == null ? void 0 : host.options) == null ? void 0 : _a.plugins,
1103
+ [pluginSystem]
1104
+ );
1105
+ return pluginSystem;
1106
+ }
1107
+ return null;
1108
+ }
1104
1109
  const RemoteAppWrapper = forwardRef(function(props, ref) {
1110
+ const bridgeHook = registerBridgeLifeCycle();
1105
1111
  const RemoteApp2 = () => {
1106
1112
  LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
1107
1113
  const {
@@ -1119,6 +1125,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
1119
1125
  const providerInfoRef = useRef(null);
1120
1126
  useEffect(() => {
1121
1127
  const renderTimeout = setTimeout(() => {
1128
+ var _a, _b;
1122
1129
  const providerReturn = providerInfo();
1123
1130
  providerInfoRef.current = providerReturn;
1124
1131
  const renderProps = {
@@ -1134,29 +1141,33 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
1134
1141
  `createRemoteComponent LazyComponent render >>>`,
1135
1142
  renderProps
1136
1143
  );
1137
- pluginSystem.lifecycle.beforeBridgeRender.emit({
1138
- ...renderProps
1139
- });
1144
+ if (bridgeHook && ((_a = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _a.beforeBridgeRender)) {
1145
+ (_b = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _b.beforeBridgeRender.emit({
1146
+ ...renderProps
1147
+ });
1148
+ }
1140
1149
  providerReturn.render(renderProps);
1141
1150
  });
1142
1151
  return () => {
1143
1152
  clearTimeout(renderTimeout);
1144
1153
  setTimeout(() => {
1145
- var _a2, _b;
1146
- if ((_a2 = providerInfoRef.current) == null ? void 0 : _a2.destroy) {
1154
+ var _a, _b, _c, _d;
1155
+ if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
1147
1156
  LoggerInstance.log(
1148
1157
  `createRemoteComponent LazyComponent destroy >>>`,
1149
1158
  { moduleName, basename, dom: renderDom.current }
1150
1159
  );
1151
- pluginSystem.lifecycle.beforeBridgeDestroy.emit({
1152
- moduleName,
1153
- dom: renderDom.current,
1154
- basename,
1155
- memoryRoute,
1156
- fallback,
1157
- ...resProps
1158
- });
1159
- (_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
1160
+ if (bridgeHook && ((_b = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _b.beforeBridgeDestroy)) {
1161
+ (_c = bridgeHook == null ? void 0 : bridgeHook.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy.emit({
1162
+ moduleName,
1163
+ dom: renderDom.current,
1164
+ basename,
1165
+ memoryRoute,
1166
+ fallback,
1167
+ ...resProps
1168
+ });
1169
+ }
1170
+ (_d = providerInfoRef.current) == null ? void 0 : _d.destroy({
1160
1171
  dom: renderDom.current
1161
1172
  });
1162
1173
  }
@@ -1177,7 +1188,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
1177
1188
  });
1178
1189
  function withRouterData(WrappedComponent) {
1179
1190
  const Component2 = forwardRef(function(props, ref) {
1180
- var _a2;
1191
+ var _a;
1181
1192
  let enableDispathPopstate = false;
1182
1193
  let routerContextVal;
1183
1194
  try {
@@ -1207,7 +1218,7 @@ function withRouterData(WrappedComponent) {
1207
1218
  const match = useRouteMatch == null ? void 0 : useRouteMatch();
1208
1219
  if (useHistory) {
1209
1220
  const history = useHistory == null ? void 0 : useHistory();
1210
- basename = (_a2 = history == null ? void 0 : history.createHref) == null ? void 0 : _a2.call(history, { pathname: "/" });
1221
+ basename = (_a = history == null ? void 0 : history.createHref) == null ? void 0 : _a.call(history, { pathname: "/" });
1211
1222
  }
1212
1223
  if (match) {
1213
1224
  basename = pathJoin(basename, (match == null ? void 0 : match.path) || "/");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/bridge-react",
3
- "version": "0.0.0-next-20240923034121",
3
+ "version": "0.0.0-next-20240923065315",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,13 +35,13 @@
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-20240923034121"
38
+ "@module-federation/bridge-shared": "0.0.0-next-20240923065315"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": ">=16.9.0",
42
42
  "react-dom": ">=16.9.0",
43
43
  "react-router-dom": ">=4",
44
- "@module-federation/runtime": "0.0.0-next-20240923034121"
44
+ "@module-federation/runtime": "0.0.0-next-20240923065315"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@testing-library/react": "15.0.7",
package/src/create.tsx CHANGED
@@ -3,10 +3,8 @@ import {
3
3
  ErrorBoundary,
4
4
  ErrorBoundaryPropsWithComponent,
5
5
  } from 'react-error-boundary';
6
-
7
6
  import { LoggerInstance } from './utils';
8
7
  import RemoteApp from './remote';
9
-
10
8
  import type { ProviderParams } from '@module-federation/bridge-shared';
11
9
 
12
10
  export interface RenderFnParams extends ProviderParams {
package/src/index.ts CHANGED
@@ -4,4 +4,3 @@ export type {
4
4
  ProviderParams,
5
5
  RenderFnParams,
6
6
  } from '@module-federation/bridge-shared';
7
- export type { BridgeRuntimePlugin } from './lifecycle';
package/src/lifecycle.ts CHANGED
@@ -1,18 +1,29 @@
1
1
  import { getInstance } from '@module-federation/runtime';
2
2
  import helper from '@module-federation/runtime/helpers';
3
3
 
4
- const registerPlugin = helper.global.registerPlugins;
5
- const pluginHelper = helper.global.pluginHelper;
6
- const host = getInstance()!;
7
- const pluginSystem = new pluginHelper.PluginSystem({
8
- beforeBridgeRender: new pluginHelper.SyncHook<[Record<string, any>], void>(),
9
- beforeBridgeDestroy: new pluginHelper.SyncHook<[Record<string, any>], void>(),
10
- });
4
+ function registerBridgeLifeCycle() {
5
+ const { registerPlugins, pluginHelper } = helper.global;
6
+ const host = getInstance();
7
+ const pluginSystem = new pluginHelper.PluginSystem({
8
+ beforeBridgeRender: new pluginHelper.SyncHook<
9
+ [Record<string, any>],
10
+ void
11
+ >(),
12
+ beforeBridgeDestroy: new pluginHelper.SyncHook<
13
+ [Record<string, any>],
14
+ void
15
+ >(),
16
+ });
11
17
 
12
- registerPlugin<typeof pluginSystem.lifecycle, typeof pluginSystem>(
13
- host?.options?.plugins,
14
- [pluginSystem],
15
- );
18
+ if (host) {
19
+ registerPlugins<typeof pluginSystem.lifecycle, typeof pluginSystem>(
20
+ host?.options?.plugins,
21
+ [pluginSystem],
22
+ );
23
+ return pluginSystem;
24
+ }
16
25
 
17
- export default pluginSystem;
18
- export type BridgeRuntimePlugin = typeof pluginSystem;
26
+ return null;
27
+ }
28
+
29
+ export { registerBridgeLifeCycle };
package/src/provider.tsx CHANGED
@@ -7,7 +7,6 @@ import type {
7
7
  RenderFnParams,
8
8
  } from '@module-federation/bridge-shared';
9
9
  import { ErrorBoundary } from 'react-error-boundary';
10
-
11
10
  import { RouterContext } from './context';
12
11
  import { LoggerInstance, atLeastReact18 } from './utils';
13
12
 
@@ -9,7 +9,7 @@ import * as ReactRouterDOM from 'react-router-dom';
9
9
  import type { ProviderParams } from '@module-federation/bridge-shared';
10
10
  import { dispatchPopstateEnv } from '@module-federation/bridge-shared';
11
11
  import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
12
- import bridgeHook from '../lifecycle';
12
+ import { registerBridgeLifeCycle } from '../lifecycle';
13
13
  import { LoggerInstance, pathJoin } from '../utils';
14
14
 
15
15
  declare const __APP_VERSION__: string;
@@ -40,6 +40,7 @@ const RemoteAppWrapper = forwardRef(function (
40
40
  props: RemoteAppParams & RenderFnParams,
41
41
  ref,
42
42
  ) {
43
+ const bridgeHook = registerBridgeLifeCycle();
43
44
  const RemoteApp = () => {
44
45
  LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
45
46
  const {
@@ -79,9 +80,13 @@ const RemoteAppWrapper = forwardRef(function (
79
80
  `createRemoteComponent LazyComponent render >>>`,
80
81
  renderProps,
81
82
  );
82
- bridgeHook.lifecycle.beforeBridgeRender.emit({
83
- ...renderProps,
84
- });
83
+
84
+ if (bridgeHook && bridgeHook?.lifecycle?.beforeBridgeRender) {
85
+ bridgeHook?.lifecycle?.beforeBridgeRender.emit({
86
+ ...renderProps,
87
+ });
88
+ }
89
+
85
90
  providerReturn.render(renderProps);
86
91
  });
87
92
 
@@ -93,14 +98,16 @@ const RemoteAppWrapper = forwardRef(function (
93
98
  `createRemoteComponent LazyComponent destroy >>>`,
94
99
  { moduleName, basename, dom: renderDom.current },
95
100
  );
96
- bridgeHook.lifecycle.beforeBridgeDestroy.emit({
97
- moduleName,
98
- dom: renderDom.current,
99
- basename,
100
- memoryRoute,
101
- fallback,
102
- ...resProps,
103
- });
101
+ if (bridgeHook && bridgeHook?.lifecycle?.beforeBridgeDestroy) {
102
+ bridgeHook?.lifecycle?.beforeBridgeDestroy.emit({
103
+ moduleName,
104
+ dom: renderDom.current,
105
+ basename,
106
+ memoryRoute,
107
+ fallback,
108
+ ...resProps,
109
+ });
110
+ }
104
111
  providerInfoRef.current?.destroy({
105
112
  dom: renderDom.current,
106
113
  });