@module-federation/bridge-react 0.21.2 → 0.21.4

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,5 +1,21 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
+ ## 0.21.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 444db72: fix(bridge-react): hoist BridgeWrapper to prevent component recreation
8
+ - Updated dependencies [a50e068]
9
+ - @module-federation/sdk@0.21.4
10
+ - @module-federation/bridge-shared@0.21.4
11
+
12
+ ## 0.21.3
13
+
14
+ ### Patch Changes
15
+
16
+ - @module-federation/sdk@0.21.3
17
+ - @module-federation/bridge-shared@0.21.3
18
+
3
19
  ## 0.21.2
4
20
 
5
21
  ### Patch Changes
@@ -121,6 +121,24 @@ function createBaseBridgeComponent({
121
121
  }
122
122
  ));
123
123
  };
124
+ const DefaultFallback = ({ error }) => /* @__PURE__ */ React.createElement("div", { role: "alert" }, /* @__PURE__ */ React.createElement("p", null, "Something went wrong:"), /* @__PURE__ */ React.createElement("pre", { style: { color: "red" } }, error.message));
125
+ const BridgeWrapper = ({
126
+ basename,
127
+ moduleName,
128
+ memoryRoute,
129
+ propsInfo,
130
+ fallback
131
+ }) => /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback || DefaultFallback }, /* @__PURE__ */ React.createElement(
132
+ RawComponent,
133
+ {
134
+ appInfo: {
135
+ moduleName,
136
+ basename,
137
+ memoryRoute
138
+ },
139
+ propsInfo
140
+ }
141
+ ));
124
142
  return {
125
143
  async render(info) {
126
144
  var _a, _b, _c, _d, _e, _f;
@@ -139,28 +157,20 @@ function createBaseBridgeComponent({
139
157
  ...rootOptions
140
158
  };
141
159
  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)) || {};
142
- const BridgeWrapper = ({ basename: basename2 }) => /* @__PURE__ */ React.createElement(
143
- ErrorBoundary,
160
+ const rootComponentWithErrorBoundary = /* @__PURE__ */ React.createElement(
161
+ BridgeWrapper,
144
162
  {
145
- FallbackComponent: fallback
146
- },
147
- /* @__PURE__ */ React.createElement(
148
- RawComponent,
149
- {
150
- appInfo: {
151
- moduleName,
152
- basename: basename2,
153
- memoryRoute
154
- },
155
- propsInfo: {
156
- ...propsInfo,
157
- basename: basename2,
158
- ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
159
- }
163
+ basename,
164
+ moduleName,
165
+ memoryRoute,
166
+ fallback,
167
+ propsInfo: {
168
+ ...propsInfo,
169
+ basename,
170
+ ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
160
171
  }
161
- )
172
+ }
162
173
  );
163
- const rootComponentWithErrorBoundary = /* @__PURE__ */ React.createElement(BridgeWrapper, { basename });
164
174
  if (bridgeInfo.render) {
165
175
  await Promise.resolve(
166
176
  bridgeInfo.render(rootComponentWithErrorBoundary, dom)
@@ -138,6 +138,24 @@ function createBaseBridgeComponent({
138
138
  }
139
139
  ));
140
140
  };
141
+ const DefaultFallback = ({ error }) => /* @__PURE__ */ React__namespace.createElement("div", { role: "alert" }, /* @__PURE__ */ React__namespace.createElement("p", null, "Something went wrong:"), /* @__PURE__ */ React__namespace.createElement("pre", { style: { color: "red" } }, error.message));
142
+ const BridgeWrapper = ({
143
+ basename,
144
+ moduleName,
145
+ memoryRoute,
146
+ propsInfo,
147
+ fallback
148
+ }) => /* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback || DefaultFallback }, /* @__PURE__ */ React__namespace.createElement(
149
+ RawComponent,
150
+ {
151
+ appInfo: {
152
+ moduleName,
153
+ basename,
154
+ memoryRoute
155
+ },
156
+ propsInfo
157
+ }
158
+ ));
141
159
  return {
142
160
  async render(info) {
143
161
  var _a, _b, _c, _d, _e, _f;
@@ -156,28 +174,20 @@ function createBaseBridgeComponent({
156
174
  ...rootOptions
157
175
  };
158
176
  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)) || {};
159
- const BridgeWrapper = ({ basename: basename2 }) => /* @__PURE__ */ React__namespace.createElement(
160
- ErrorBoundary,
177
+ const rootComponentWithErrorBoundary = /* @__PURE__ */ React__namespace.createElement(
178
+ BridgeWrapper,
161
179
  {
162
- FallbackComponent: fallback
163
- },
164
- /* @__PURE__ */ React__namespace.createElement(
165
- RawComponent,
166
- {
167
- appInfo: {
168
- moduleName,
169
- basename: basename2,
170
- memoryRoute
171
- },
172
- propsInfo: {
173
- ...propsInfo,
174
- basename: basename2,
175
- ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
176
- }
180
+ basename,
181
+ moduleName,
182
+ memoryRoute,
183
+ fallback,
184
+ propsInfo: {
185
+ ...propsInfo,
186
+ basename,
187
+ ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
177
188
  }
178
- )
189
+ }
179
190
  );
180
- const rootComponentWithErrorBoundary = /* @__PURE__ */ React__namespace.createElement(BridgeWrapper, { basename });
181
191
  if (bridgeInfo.render) {
182
192
  await Promise.resolve(
183
193
  bridgeInfo.render(rootComponentWithErrorBoundary, dom)
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const lazyUtils = require("./utils-tM9yE73c.js");
4
- const prefetch = require("./prefetch-k61Qz1E-.js");
4
+ const prefetch = require("./prefetch-8digEyiB.js");
5
5
  async function callDataFetch() {
6
6
  const dataFetch = globalThis[lazyUtils.DATA_FETCH_FUNCTION];
7
7
  if (dataFetch) {
@@ -1,7 +1,7 @@
1
1
  import { x as DATA_FETCH_FUNCTION } from "./utils-Bx_8GGd-.mjs";
2
2
  import { C, b, e, h, c, d, r } from "./utils-Bx_8GGd-.mjs";
3
- import { d as dataFetchFunction } from "./prefetch-BWGWrW3l.mjs";
4
- import { i, p } from "./prefetch-BWGWrW3l.mjs";
3
+ import { d as dataFetchFunction } from "./prefetch-BB7FYVtC.mjs";
4
+ import { i, p } from "./prefetch-BB7FYVtC.mjs";
5
5
  async function callDataFetch() {
6
6
  const dataFetch = globalThis[DATA_FETCH_FUNCTION];
7
7
  if (dataFetch) {
package/dist/index.cjs.js CHANGED
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const bridgeBase = require("./bridge-base-B2malZDo.js");
3
+ const bridgeBase = require("./bridge-base-RStDxH71.js");
4
4
  const ReactDOM = require("react-dom");
5
5
  const index = require("./index-DRSBaSu3.js");
6
6
  const React = require("react");
7
7
  const ReactRouterDOM = require("react-router-dom");
8
8
  const plugin = require("./plugin.cjs.js");
9
- const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-CTOmHqqN.js");
9
+ const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-Cgim6ZGI.js");
10
10
  const lazyUtils = require("./utils-tM9yE73c.js");
11
11
  const dataFetchUtils = require("./data-fetch-utils.cjs.js");
12
- const prefetch = require("./prefetch-k61Qz1E-.js");
12
+ const prefetch = require("./prefetch-8digEyiB.js");
13
13
  function _interopNamespaceDefault(e2) {
14
14
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
15
15
  if (e2) {
package/dist/index.es.js CHANGED
@@ -1,13 +1,13 @@
1
- import { c as createBaseBridgeComponent, E as ErrorBoundary } from "./bridge-base-DRFFglgm.mjs";
1
+ import { c as createBaseBridgeComponent, E as ErrorBoundary } from "./bridge-base-CPSTBjEp.mjs";
2
2
  import ReactDOM from "react-dom";
3
3
  import { L as LoggerInstance, p as pathJoin, g as getRootDomDefaultClassName } from "./index-DyQNwY2M.mjs";
4
4
  import React__default, { forwardRef, useContext, useState, useEffect, useRef } from "react";
5
5
  import * as ReactRouterDOM from "react-router-dom";
6
6
  import { federationRuntime } from "./plugin.es.js";
7
- import { b, a, c, l } from "./lazy-load-component-plugin-Cd5_LHQf.mjs";
7
+ import { b, a, c, l } from "./lazy-load-component-plugin-fFox6KGt.mjs";
8
8
  import { C, b as b2, E, e, h, c as c2, d, r, s } from "./utils-Bx_8GGd-.mjs";
9
9
  import { callDataFetch } from "./data-fetch-utils.es.js";
10
- import { p } from "./prefetch-BWGWrW3l.mjs";
10
+ import { p } from "./prefetch-BB7FYVtC.mjs";
11
11
  function createReact16Or17Root(container) {
12
12
  return {
13
13
  render(children) {
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const prefetch = require("./prefetch-k61Qz1E-.js");
2
+ const prefetch = require("./prefetch-8digEyiB.js");
3
3
  const lazyUtils = require("./utils-tM9yE73c.js");
4
4
  const React = require("react");
5
5
  const autoFetchData = () => {
@@ -1,4 +1,4 @@
1
- import { i as injectDataFetch, p as prefetch } from "./prefetch-BWGWrW3l.mjs";
1
+ import { i as injectDataFetch, p as prefetch } from "./prefetch-BB7FYVtC.mjs";
2
2
  import { i as initDataFetchMap, j as isDataLoaderExpose, k as getDataFetchInfo, m as getDataFetchMapKey, l as logger, n as getDataFetchItem, o as DATA_FETCH_CLIENT_SUFFIX, p as MF_DATA_FETCH_TYPE, q as isCSROnly, a as loadDataFetchModule, M as MF_DATA_FETCH_STATUS, g as getDataFetchMap, t as isServerEnv, u as getDataFetchIdWithErrorMsgs, v as DATA_FETCH_ERROR_PREFIX, E as ERROR_TYPE, w as wrapDataFetchId, L as LOAD_REMOTE_ERROR_PREFIX, x as DATA_FETCH_FUNCTION, y as getLoadedRemoteInfos, f as fetchData$1, z as setDataFetchItemLoadedStatus, F as FS_HREF } from "./utils-Bx_8GGd-.mjs";
3
3
  import React__default, { useRef, useState, Suspense, useEffect } from "react";
4
4
  const autoFetchData = () => {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-CTOmHqqN.js");
4
- require("./prefetch-k61Qz1E-.js");
3
+ const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-Cgim6ZGI.js");
4
+ require("./prefetch-8digEyiB.js");
5
5
  exports.default = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
6
6
  exports.lazyLoadComponentPlugin = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
@@ -1,5 +1,5 @@
1
- import { l, l as l2 } from "./lazy-load-component-plugin-Cd5_LHQf.mjs";
2
- import "./prefetch-BWGWrW3l.mjs";
1
+ import { l, l as l2 } from "./lazy-load-component-plugin-fFox6KGt.mjs";
2
+ import "./prefetch-BB7FYVtC.mjs";
3
3
  export {
4
4
  l as default,
5
5
  l2 as lazyLoadComponentPlugin
@@ -211,7 +211,7 @@ function getGlobalFederationConstructor() {
211
211
  function setGlobalFederationConstructor(FederationConstructor, isDebug = index_esm.isDebugMode()) {
212
212
  if (isDebug) {
213
213
  CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
214
- CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.21.2";
214
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.21.4";
215
215
  }
216
216
  }
217
217
  function getInfoWithoutType(target, key) {
@@ -210,7 +210,7 @@ function getGlobalFederationConstructor() {
210
210
  function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
211
211
  if (isDebug) {
212
212
  CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
213
- CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.21.2";
213
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.21.4";
214
214
  }
215
215
  }
216
216
  function getInfoWithoutType(target, key) {
package/dist/v18.cjs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const client = require("react-dom/client");
4
- const bridgeBase = require("./bridge-base-B2malZDo.js");
4
+ const bridgeBase = require("./bridge-base-RStDxH71.js");
5
5
  function createReact18Root(container, options) {
6
6
  return client.createRoot(container, options);
7
7
  }
package/dist/v18.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRoot } from "react-dom/client";
2
- import { c as createBaseBridgeComponent } from "./bridge-base-DRFFglgm.mjs";
2
+ import { c as createBaseBridgeComponent } from "./bridge-base-CPSTBjEp.mjs";
3
3
  function createReact18Root(container, options) {
4
4
  return createRoot(container, options);
5
5
  }
package/dist/v19.cjs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const client = require("react-dom/client");
4
- const bridgeBase = require("./bridge-base-B2malZDo.js");
4
+ const bridgeBase = require("./bridge-base-RStDxH71.js");
5
5
  function createReact19Root(container, options) {
6
6
  return client.createRoot(container, options);
7
7
  }
package/dist/v19.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRoot } from "react-dom/client";
2
- import { c as createBaseBridgeComponent } from "./bridge-base-DRFFglgm.mjs";
2
+ import { c as createBaseBridgeComponent } from "./bridge-base-CPSTBjEp.mjs";
3
3
  function createReact19Root(container, options) {
4
4
  return createRoot(container, options);
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/bridge-react",
3
- "version": "0.21.2",
3
+ "version": "0.21.4",
4
4
  "sideEffects": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -121,8 +121,8 @@
121
121
  "dependencies": {
122
122
  "react-error-boundary": "^4.1.2",
123
123
  "lru-cache": "^10.4.3",
124
- "@module-federation/bridge-shared": "0.21.2",
125
- "@module-federation/sdk": "0.21.2"
124
+ "@module-federation/sdk": "0.21.4",
125
+ "@module-federation/bridge-shared": "0.21.4"
126
126
  },
127
127
  "peerDependencies": {
128
128
  "react": ">=16.9.0",
@@ -153,9 +153,9 @@
153
153
  "typescript": "^5.2.2",
154
154
  "vite": "^5.4.21",
155
155
  "vite-plugin-dts": "^4.3.0",
156
- "hono": "4.10.2",
157
- "@module-federation/runtime-core": "0.21.2",
158
- "@module-federation/runtime": "0.21.2"
156
+ "hono": "4.10.3",
157
+ "@module-federation/runtime-core": "0.21.4",
158
+ "@module-federation/runtime": "0.21.4"
159
159
  },
160
160
  "scripts": {
161
161
  "dev": "vite",
@@ -43,6 +43,38 @@ export function createBaseBridgeComponent<T>({
43
43
  );
44
44
  };
45
45
 
46
+ const DefaultFallback = ({ error }: FallbackProps) => (
47
+ <div role="alert">
48
+ <p>Something went wrong:</p>
49
+ <pre style={{ color: 'red' }}>{error.message}</pre>
50
+ </div>
51
+ );
52
+
53
+ const BridgeWrapper = ({
54
+ basename,
55
+ moduleName,
56
+ memoryRoute,
57
+ propsInfo,
58
+ fallback,
59
+ }: {
60
+ basename?: string;
61
+ moduleName?: string;
62
+ memoryRoute?: any;
63
+ propsInfo: T;
64
+ fallback?: React.ComponentType<FallbackProps>;
65
+ }) => (
66
+ <ErrorBoundary FallbackComponent={fallback || DefaultFallback}>
67
+ <RawComponent
68
+ appInfo={{
69
+ moduleName,
70
+ basename,
71
+ memoryRoute,
72
+ }}
73
+ propsInfo={propsInfo}
74
+ />
75
+ </ErrorBoundary>
76
+ );
77
+
46
78
  return {
47
79
  async render(info: RenderParams) {
48
80
  LoggerInstance.debug(`createBridgeComponent render Info`, info);
@@ -64,29 +96,20 @@ export function createBaseBridgeComponent<T>({
64
96
  const beforeBridgeRenderRes =
65
97
  instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(info) || {};
66
98
 
67
- const BridgeWrapper = ({ basename }: { basename?: string }) => (
68
- <ErrorBoundary
69
- FallbackComponent={fallback as React.ComponentType<FallbackProps>}
70
- >
71
- <RawComponent
72
- appInfo={{
73
- moduleName,
74
- basename,
75
- memoryRoute,
76
- }}
77
- propsInfo={
78
- {
79
- ...propsInfo,
80
- basename,
81
- ...(beforeBridgeRenderRes as any)?.extraProps,
82
- } as T
83
- }
84
- />
85
- </ErrorBoundary>
86
- );
87
-
88
99
  const rootComponentWithErrorBoundary = (
89
- <BridgeWrapper basename={basename} />
100
+ <BridgeWrapper
101
+ basename={basename}
102
+ moduleName={moduleName}
103
+ memoryRoute={memoryRoute}
104
+ fallback={fallback as React.ComponentType<FallbackProps>}
105
+ propsInfo={
106
+ {
107
+ ...propsInfo,
108
+ basename,
109
+ ...(beforeBridgeRenderRes as any)?.extraProps,
110
+ } as T
111
+ }
112
+ />
90
113
  );
91
114
 
92
115
  if (bridgeInfo.render) {