@module-federation/bridge-react 0.0.0-next-20250416061914 → 0.0.0-next-20250421062338

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,16 +1,20 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
- ## 0.0.0-next-20250416061914
3
+ ## 0.0.0-next-20250421062338
4
4
 
5
5
  ### Minor Changes
6
6
 
7
- - d802e00: feat(react-bridge): Add native support for React 19 in bridge-react with enhanced createRoot options
7
+ - 88a018d: feat(react-bridge): Add native support for React 19 in bridge-react with enhanced createRoot options
8
8
 
9
9
  ### Patch Changes
10
10
 
11
- - d0a11ff: feat(bridge-react): support react v19 in react compat file.
12
- - @module-federation/sdk@0.0.0-next-20250416061914
13
- - @module-federation/bridge-shared@0.0.0-next-20250416061914
11
+ - 88a018d: feat(bridge-react): support react v19 in react compat file.
12
+ - 4db1b0e: feat: add error detection for react v19 under the default export createBaseBridgeComponent
13
+ - 38f324f: Disable live bindings on cjs builds of the runtime packages
14
+ - 0eb6d1b: refactor(bridge-react): modify the default mode of the bridge to legacy mode to reduce redundant code
15
+ - Updated dependencies [38f324f]
16
+ - @module-federation/bridge-shared@0.0.0-next-20250421062338
17
+ - @module-federation/sdk@0.0.0-next-20250421062338
14
18
 
15
19
  ## 0.12.0
16
20
 
@@ -1,7 +1,102 @@
1
1
  import * as React from "react";
2
- import { E as ErrorBoundary } from "./react-error-boundary.esm-CMdlkNPP.js";
3
- import { L as LoggerInstance, R as RouterContext } from "./context-Dbqf0szX.js";
2
+ import { Component, createElement, createContext } from "react";
3
+ import { L as LoggerInstance, R as RouterContext } from "./index-BlBMQSoq.js";
4
4
  import { federationRuntime } from "./plugin.es.js";
5
+ const ErrorBoundaryContext = createContext(null);
6
+ const initialState = {
7
+ didCatch: false,
8
+ error: null
9
+ };
10
+ class ErrorBoundary extends Component {
11
+ constructor(props) {
12
+ super(props);
13
+ this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
14
+ this.state = initialState;
15
+ }
16
+ static getDerivedStateFromError(error) {
17
+ return {
18
+ didCatch: true,
19
+ error
20
+ };
21
+ }
22
+ resetErrorBoundary() {
23
+ const {
24
+ error
25
+ } = this.state;
26
+ if (error !== null) {
27
+ var _this$props$onReset, _this$props;
28
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
29
+ args[_key] = arguments[_key];
30
+ }
31
+ (_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
32
+ args,
33
+ reason: "imperative-api"
34
+ });
35
+ this.setState(initialState);
36
+ }
37
+ }
38
+ componentDidCatch(error, info) {
39
+ var _this$props$onError, _this$props2;
40
+ (_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
41
+ }
42
+ componentDidUpdate(prevProps, prevState) {
43
+ const {
44
+ didCatch
45
+ } = this.state;
46
+ const {
47
+ resetKeys
48
+ } = this.props;
49
+ if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
50
+ var _this$props$onReset2, _this$props3;
51
+ (_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
52
+ next: resetKeys,
53
+ prev: prevProps.resetKeys,
54
+ reason: "keys"
55
+ });
56
+ this.setState(initialState);
57
+ }
58
+ }
59
+ render() {
60
+ const {
61
+ children,
62
+ fallbackRender,
63
+ FallbackComponent,
64
+ fallback
65
+ } = this.props;
66
+ const {
67
+ didCatch,
68
+ error
69
+ } = this.state;
70
+ let childToRender = children;
71
+ if (didCatch) {
72
+ const props = {
73
+ error,
74
+ resetErrorBoundary: this.resetErrorBoundary
75
+ };
76
+ if (typeof fallbackRender === "function") {
77
+ childToRender = fallbackRender(props);
78
+ } else if (FallbackComponent) {
79
+ childToRender = createElement(FallbackComponent, props);
80
+ } else if (fallback !== void 0) {
81
+ childToRender = fallback;
82
+ } else {
83
+ throw error;
84
+ }
85
+ }
86
+ return createElement(ErrorBoundaryContext.Provider, {
87
+ value: {
88
+ didCatch,
89
+ error,
90
+ resetErrorBoundary: this.resetErrorBoundary
91
+ }
92
+ }, childToRender);
93
+ }
94
+ }
95
+ function hasArrayChanged() {
96
+ let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
97
+ let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
98
+ return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
99
+ }
5
100
  function createBaseBridgeComponent({
6
101
  createRoot,
7
102
  defaultRootOptions,
@@ -99,5 +194,6 @@ function createBaseBridgeComponent({
99
194
  };
100
195
  }
101
196
  export {
197
+ ErrorBoundary as E,
102
198
  createBaseBridgeComponent as c
103
199
  };
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  const React = require("react");
3
- const reactErrorBoundary_esm = require("./react-error-boundary.esm-D8nxmvmv.cjs");
4
- const context = require("./context-C79iMWYD.cjs");
3
+ const index = require("./index-BYDWxFmi.cjs");
5
4
  const plugin = require("./plugin.cjs.js");
6
5
  function _interopNamespaceDefault(e) {
7
6
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -20,6 +19,101 @@ function _interopNamespaceDefault(e) {
20
19
  return Object.freeze(n);
21
20
  }
22
21
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
22
+ const ErrorBoundaryContext = React.createContext(null);
23
+ const initialState = {
24
+ didCatch: false,
25
+ error: null
26
+ };
27
+ class ErrorBoundary extends React.Component {
28
+ constructor(props) {
29
+ super(props);
30
+ this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
31
+ this.state = initialState;
32
+ }
33
+ static getDerivedStateFromError(error) {
34
+ return {
35
+ didCatch: true,
36
+ error
37
+ };
38
+ }
39
+ resetErrorBoundary() {
40
+ const {
41
+ error
42
+ } = this.state;
43
+ if (error !== null) {
44
+ var _this$props$onReset, _this$props;
45
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
46
+ args[_key] = arguments[_key];
47
+ }
48
+ (_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
49
+ args,
50
+ reason: "imperative-api"
51
+ });
52
+ this.setState(initialState);
53
+ }
54
+ }
55
+ componentDidCatch(error, info) {
56
+ var _this$props$onError, _this$props2;
57
+ (_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
58
+ }
59
+ componentDidUpdate(prevProps, prevState) {
60
+ const {
61
+ didCatch
62
+ } = this.state;
63
+ const {
64
+ resetKeys
65
+ } = this.props;
66
+ if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
67
+ var _this$props$onReset2, _this$props3;
68
+ (_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
69
+ next: resetKeys,
70
+ prev: prevProps.resetKeys,
71
+ reason: "keys"
72
+ });
73
+ this.setState(initialState);
74
+ }
75
+ }
76
+ render() {
77
+ const {
78
+ children,
79
+ fallbackRender,
80
+ FallbackComponent,
81
+ fallback
82
+ } = this.props;
83
+ const {
84
+ didCatch,
85
+ error
86
+ } = this.state;
87
+ let childToRender = children;
88
+ if (didCatch) {
89
+ const props = {
90
+ error,
91
+ resetErrorBoundary: this.resetErrorBoundary
92
+ };
93
+ if (typeof fallbackRender === "function") {
94
+ childToRender = fallbackRender(props);
95
+ } else if (FallbackComponent) {
96
+ childToRender = React.createElement(FallbackComponent, props);
97
+ } else if (fallback !== void 0) {
98
+ childToRender = fallback;
99
+ } else {
100
+ throw error;
101
+ }
102
+ }
103
+ return React.createElement(ErrorBoundaryContext.Provider, {
104
+ value: {
105
+ didCatch,
106
+ error,
107
+ resetErrorBoundary: this.resetErrorBoundary
108
+ }
109
+ }, childToRender);
110
+ }
111
+ }
112
+ function hasArrayChanged() {
113
+ let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
114
+ let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
115
+ return a.length !== b.length || a.some((item, index2) => !Object.is(item, b[index2]));
116
+ }
23
117
  function createBaseBridgeComponent({
24
118
  createRoot,
25
119
  defaultRootOptions,
@@ -28,14 +122,14 @@ function createBaseBridgeComponent({
28
122
  return () => {
29
123
  const rootMap = /* @__PURE__ */ new Map();
30
124
  const instance = plugin.federationRuntime.instance;
31
- context.LoggerInstance.debug(
125
+ index.LoggerInstance.debug(
32
126
  `createBridgeComponent instance from props >>>`,
33
127
  instance
34
128
  );
35
129
  const RawComponent = (info) => {
36
130
  const { appInfo, propsInfo, ...restProps } = info;
37
131
  const { moduleName, memoryRoute, basename = "/" } = appInfo;
38
- return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { moduleName, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(
132
+ return /* @__PURE__ */ React__namespace.createElement(index.RouterContext.Provider, { value: { moduleName, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(
39
133
  bridgeInfo.rootComponent,
40
134
  {
41
135
  ...propsInfo,
@@ -47,7 +141,7 @@ function createBaseBridgeComponent({
47
141
  return {
48
142
  async render(info) {
49
143
  var _a, _b, _c, _d, _e, _f;
50
- context.LoggerInstance.debug(`createBridgeComponent render Info`, info);
144
+ index.LoggerInstance.debug(`createBridgeComponent render Info`, info);
51
145
  const {
52
146
  moduleName,
53
147
  dom,
@@ -63,7 +157,7 @@ function createBaseBridgeComponent({
63
157
  };
64
158
  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)) || {};
65
159
  const rootComponentWithErrorBoundary = /* @__PURE__ */ React__namespace.createElement(
66
- reactErrorBoundary_esm.ErrorBoundary,
160
+ ErrorBoundary,
67
161
  {
68
162
  FallbackComponent: fallback
69
163
  },
@@ -101,7 +195,7 @@ function createBaseBridgeComponent({
101
195
  destroy(info) {
102
196
  var _a, _b, _c;
103
197
  const { dom } = info;
104
- context.LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
198
+ index.LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
105
199
  const root = rootMap.get(dom);
106
200
  if (root) {
107
201
  if ("unmount" in root) {
@@ -116,4 +210,5 @@ function createBaseBridgeComponent({
116
210
  };
117
211
  };
118
212
  }
213
+ exports.ErrorBoundary = ErrorBoundary;
119
214
  exports.createBaseBridgeComponent = createBaseBridgeComponent;
package/dist/index.cjs.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const bridgeBase = require("./bridge-base-DIOcSEVT.cjs");
4
+ const ReactDOM = require("react-dom");
3
5
  const React = require("react");
4
- const reactErrorBoundary_esm = require("./react-error-boundary.esm-D8nxmvmv.cjs");
5
- const context = require("./context-C79iMWYD.cjs");
6
+ const index = require("./index-BYDWxFmi.cjs");
6
7
  const ReactRouterDOM = require("react-router-dom");
7
8
  const plugin = require("./plugin.cjs.js");
8
- const ReactDOM = require("react-dom");
9
9
  function _interopNamespaceDefault(e2) {
10
10
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
11
11
  if (e2) {
@@ -22,8 +22,37 @@ function _interopNamespaceDefault(e2) {
22
22
  n.default = e2;
23
23
  return Object.freeze(n);
24
24
  }
25
- const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
26
25
  const ReactRouterDOM__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactRouterDOM);
26
+ function createReact16Or17Root(container) {
27
+ return {
28
+ render(children) {
29
+ const reactVersion = ReactDOM.version || "";
30
+ const isReact18 = reactVersion.startsWith("18");
31
+ const isReact19 = reactVersion.startsWith("19");
32
+ if (isReact19) {
33
+ throw new Error(
34
+ `React 19 detected in legacy mode. This is not supported. Please use the version-specific import: import { createBridgeComponent } from '@module-federation/bridge-react/v19'`
35
+ );
36
+ }
37
+ if (isReact18) {
38
+ console.warn(
39
+ `[Bridge-React] React 18 detected in legacy mode. For better compatibility, please use the version-specific import: import { createBridgeComponent } from '@module-federation/bridge-react/v18'`
40
+ );
41
+ }
42
+ ReactDOM.render(children, container);
43
+ },
44
+ unmount() {
45
+ ReactDOM.unmountComponentAtNode(container);
46
+ }
47
+ };
48
+ }
49
+ function createBridgeComponent(bridgeInfo) {
50
+ const fullBridgeInfo = {
51
+ createRoot: createReact16Or17Root,
52
+ ...bridgeInfo
53
+ };
54
+ return bridgeBase.createBaseBridgeComponent(fullBridgeInfo);
55
+ }
27
56
  function e() {
28
57
  const t = new PopStateEvent("popstate", { state: window.history.state });
29
58
  window.dispatchEvent(t);
@@ -44,7 +73,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
44
73
  const renderDom = React.useRef(null);
45
74
  const providerInfoRef = React.useRef(null);
46
75
  const [initialized, setInitialized] = React.useState(false);
47
- context.LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
76
+ index.LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
48
77
  React.useEffect(() => {
49
78
  if (initialized) return;
50
79
  const providerReturn = providerInfo();
@@ -53,7 +82,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
53
82
  return () => {
54
83
  var _a, _b, _c, _d, _e, _f, _g, _h;
55
84
  if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
56
- context.LoggerInstance.debug(
85
+ index.LoggerInstance.debug(
57
86
  `createRemoteComponent LazyComponent destroy >>>`,
58
87
  { moduleName, basename, dom: renderDom.current }
59
88
  );
@@ -97,7 +126,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
97
126
  providerInfoRef.current.render(renderProps);
98
127
  (_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(renderProps);
99
128
  }, [initialized, ...Object.values(props)]);
100
- const rootComponentClassName = `${context.getRootDomDefaultClassName(moduleName)} ${className || ""}`;
129
+ const rootComponentClassName = `${index.getRootDomDefaultClassName(moduleName)} ${className || ""}`;
101
130
  return /* @__PURE__ */ React.createElement("div", { className: rootComponentClassName, style, ref: rootRef });
102
131
  });
103
132
  function withRouterData(WrappedComponent) {
@@ -129,7 +158,7 @@ function withRouterData(WrappedComponent) {
129
158
  if (routerContextVal && routerContextVal.matches && routerContextVal.matches.length > 0) {
130
159
  const matchIndex = routerContextVal.matches.length - 1;
131
160
  const pathnameBase = routerContextVal.matches[matchIndex].pathnameBase;
132
- basename = context.pathJoin(basename, pathnameBase || "/");
161
+ basename = index.pathJoin(basename, pathnameBase || "/");
133
162
  }
134
163
  } else {
135
164
  const match = useRouteMatch == null ? void 0 : useRouteMatch();
@@ -138,11 +167,11 @@ function withRouterData(WrappedComponent) {
138
167
  basename = (_a = history == null ? void 0 : history.createHref) == null ? void 0 : _a.call(history, { pathname: "/" });
139
168
  }
140
169
  if (match) {
141
- basename = context.pathJoin(basename, (match == null ? void 0 : match.path) || "/");
170
+ basename = index.pathJoin(basename, (match == null ? void 0 : match.path) || "/");
142
171
  }
143
172
  }
144
173
  }
145
- context.LoggerInstance.debug(`createRemoteComponent withRouterData >>>`, {
174
+ index.LoggerInstance.debug(`createRemoteComponent withRouterData >>>`, {
146
175
  ...props,
147
176
  basename,
148
177
  routerContextVal,
@@ -153,7 +182,7 @@ function withRouterData(WrappedComponent) {
153
182
  const [pathname, setPathname] = React.useState(location.pathname);
154
183
  React.useEffect(() => {
155
184
  if (pathname !== "" && pathname !== location.pathname) {
156
- context.LoggerInstance.debug(
185
+ index.LoggerInstance.debug(
157
186
  `createRemoteComponent dispatchPopstateEnv >>>`,
158
187
  {
159
188
  name: props.name,
@@ -175,14 +204,14 @@ const RemoteApp = withRouterData(RemoteAppWrapper);
175
204
  function createLazyRemoteComponent(info) {
176
205
  const exportName = (info == null ? void 0 : info.export) || "default";
177
206
  return React.lazy(async () => {
178
- context.LoggerInstance.debug(`createRemoteComponent LazyComponent create >>>`, {
207
+ index.LoggerInstance.debug(`createRemoteComponent LazyComponent create >>>`, {
179
208
  lazyComponent: info.loader,
180
209
  exportName
181
210
  });
182
211
  try {
183
212
  const m = await info.loader();
184
213
  const moduleName = m && m[Symbol.for("mf_module_id")];
185
- context.LoggerInstance.debug(
214
+ index.LoggerInstance.debug(
186
215
  `createRemoteComponent LazyComponent loadRemote info >>>`,
187
216
  { name: moduleName, module: m, exportName }
188
217
  );
@@ -205,7 +234,7 @@ function createLazyRemoteComponent(info) {
205
234
  default: RemoteAppComponent
206
235
  };
207
236
  } else {
208
- context.LoggerInstance.debug(
237
+ index.LoggerInstance.debug(
209
238
  `createRemoteComponent LazyComponent module not found >>>`,
210
239
  { name: moduleName, module: m, exportName }
211
240
  );
@@ -224,7 +253,7 @@ function createRemoteComponent(info) {
224
253
  const LazyComponent = createLazyRemoteComponent(info);
225
254
  return React.forwardRef((props, ref) => {
226
255
  return /* @__PURE__ */ React.createElement(
227
- reactErrorBoundary_esm.ErrorBoundary,
256
+ bridgeBase.ErrorBoundary,
228
257
  {
229
258
  FallbackComponent: info.fallback
230
259
  },
@@ -232,117 +261,5 @@ function createRemoteComponent(info) {
232
261
  );
233
262
  });
234
263
  }
235
- function defaultCreateRoot(container, options) {
236
- const reactVersion = ReactDOM.version || "";
237
- const isReact18 = reactVersion.startsWith("18");
238
- if (isReact18) {
239
- try {
240
- return ReactDOM.createRoot(container, options);
241
- } catch (e2) {
242
- console.warn(
243
- "Failed to use React 18 createRoot API, falling back to legacy API",
244
- e2
245
- );
246
- }
247
- }
248
- return {
249
- render(children) {
250
- ReactDOM.render(children, container);
251
- },
252
- unmount() {
253
- ReactDOM.unmountComponentAtNode(container);
254
- }
255
- };
256
- }
257
- function createBridgeComponent({
258
- createRoot = defaultCreateRoot,
259
- defaultRootOptions,
260
- ...bridgeInfo
261
- }) {
262
- return () => {
263
- const rootMap = /* @__PURE__ */ new Map();
264
- const instance = plugin.federationRuntime.instance;
265
- context.LoggerInstance.debug(
266
- `createBridgeComponent instance from props >>>`,
267
- instance
268
- );
269
- const RawComponent = (info) => {
270
- const { appInfo, propsInfo, ...restProps } = info;
271
- const { moduleName, memoryRoute, basename = "/" } = appInfo;
272
- return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { moduleName, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(
273
- bridgeInfo.rootComponent,
274
- {
275
- ...propsInfo,
276
- basename,
277
- ...restProps
278
- }
279
- ));
280
- };
281
- return {
282
- async render(info) {
283
- var _a, _b, _c, _d, _e, _f;
284
- context.LoggerInstance.debug(`createBridgeComponent render Info`, info);
285
- const {
286
- moduleName,
287
- dom,
288
- basename,
289
- memoryRoute,
290
- fallback,
291
- rootOptions,
292
- ...propsInfo
293
- } = info;
294
- const mergedRootOptions = {
295
- ...defaultRootOptions,
296
- ...rootOptions
297
- };
298
- 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)) || {};
299
- const rootComponentWithErrorBoundary = /* @__PURE__ */ React__namespace.createElement(
300
- reactErrorBoundary_esm.ErrorBoundary,
301
- {
302
- FallbackComponent: fallback
303
- },
304
- /* @__PURE__ */ React__namespace.createElement(
305
- RawComponent,
306
- {
307
- appInfo: {
308
- moduleName,
309
- basename,
310
- memoryRoute
311
- },
312
- propsInfo: {
313
- ...propsInfo,
314
- ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
315
- }
316
- }
317
- )
318
- );
319
- let root = rootMap.get(dom);
320
- if (!root) {
321
- root = createRoot(dom, mergedRootOptions);
322
- rootMap.set(dom, root);
323
- }
324
- if ("render" in root) {
325
- root.render(rootComponentWithErrorBoundary);
326
- }
327
- ((_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)) || {};
328
- },
329
- destroy(info) {
330
- var _a, _b, _c;
331
- const { dom } = info;
332
- context.LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
333
- const root = rootMap.get(dom);
334
- if (root) {
335
- if ("unmount" in root) {
336
- root.unmount();
337
- } else {
338
- ReactDOM.unmountComponentAtNode(dom);
339
- }
340
- rootMap.delete(dom);
341
- }
342
- (_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.afterBridgeDestroy) == null ? void 0 : _c.emit(info);
343
- }
344
- };
345
- };
346
- }
347
264
  exports.createBridgeComponent = createBridgeComponent;
348
265
  exports.createRemoteComponent = createRemoteComponent;
package/dist/index.d.ts CHANGED
@@ -1,21 +1,22 @@
1
1
  import { default as default_2 } from 'react';
2
2
  import * as React_2 from 'react';
3
3
 
4
- /**
5
- * Creates a bridge component factory that automatically detects and uses
6
- * the appropriate React version (16/17, 18, or 19)
7
- */
8
- export declare function createBridgeComponent<T>({ createRoot, defaultRootOptions, ...bridgeInfo }: ProviderFnParams<T>): () => {
4
+ export declare function createBridgeComponent<T = any>(bridgeInfo: Omit<ProviderFnParams<T>, 'createRoot'>): () => {
9
5
  render(info: RenderParams): Promise<void>;
10
6
  destroy(info: DestroyParams): void;
11
7
  };
12
8
 
13
9
  export declare function createRemoteComponent<T = Record<string, unknown>, E extends keyof T = keyof T>(info: LazyRemoteComponentInfo<T, E>): default_2.ForwardRefExoticComponent<Omit<RemoteComponentProps<Record<string, unknown>>, "ref"> & default_2.RefAttributes<HTMLDivElement>>;
14
10
 
11
+ export declare interface CreateRootOptions {
12
+ identifierPrefix?: string;
13
+ onRecoverableError?: (error: unknown, errorInfo: unknown) => void;
14
+ }
15
+
15
16
  /**
16
17
  * Options for creating a React root
17
18
  */
18
- declare interface CreateRootOptions {
19
+ declare interface CreateRootOptions_2 {
19
20
  identifierPrefix?: string;
20
21
  onRecoverableError?: (error: unknown) => void;
21
22
  transitionCallbacks?: unknown;
@@ -34,10 +35,10 @@ declare type LazyRemoteComponentInfo<T, E extends keyof T> = RemoteComponentPara
34
35
  /**
35
36
  * Parameters for the provider function
36
37
  */
37
- declare interface ProviderFnParams<T> {
38
+ export declare interface ProviderFnParams<T> {
38
39
  rootComponent: React_2.ComponentType<T>;
39
40
  render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
40
- createRoot?: (container: Element | DocumentFragment, options?: CreateRootOptions) => Root;
41
+ createRoot?: (container: Element | DocumentFragment, options?: CreateRootOptions_2) => Root_2;
41
42
  /**
42
43
  * Default options to pass to createRoot for React 18 and 19
43
44
  * These options will be used when creating a root unless overridden by rootOptions in render params
@@ -47,7 +48,7 @@ declare interface ProviderFnParams<T> {
47
48
  * onRecoverableError: (err) => console.error(err)
48
49
  * }
49
50
  */
50
- defaultRootOptions?: CreateRootOptions;
51
+ defaultRootOptions?: CreateRootOptions_2;
51
52
  }
52
53
 
53
54
  /**
@@ -89,17 +90,6 @@ declare interface RemoteComponentProps<T = Record<string, unknown>> {
89
90
  [key: string]: unknown;
90
91
  }
91
92
 
92
- /**
93
- * Parameters for the render function, extending ProviderParams
94
- */
95
- export declare interface RenderFnParams extends ProviderParams {
96
- dom: HTMLElement;
97
- fallback?: React_2.ComponentType<{
98
- error: Error;
99
- }>;
100
- [key: string]: unknown;
101
- }
102
-
103
93
  /**
104
94
  * Parameters for the render function
105
95
  */
@@ -119,14 +109,19 @@ export declare interface RenderParams {
119
109
  * onRecoverableError: (err) => console.error(err)
120
110
  * }
121
111
  */
122
- rootOptions?: CreateRootOptions;
112
+ rootOptions?: CreateRootOptions_2;
123
113
  [key: string]: unknown;
124
114
  }
125
115
 
116
+ export declare interface Root {
117
+ render(children: React.ReactNode): void;
118
+ unmount(): void;
119
+ }
120
+
126
121
  /**
127
122
  * Interface for a React root object
128
123
  */
129
- declare interface Root {
124
+ declare interface Root_2 {
130
125
  render(children: React_2.ReactNode): void;
131
126
  unmount(): void;
132
127
  }
@@ -134,6 +129,6 @@ declare interface Root {
134
129
  /**
135
130
  * Type for a root element, which can be either an HTMLElement or a React root
136
131
  */
137
- declare type RootType = HTMLElement | Root;
132
+ export declare type RootType = HTMLElement | Root_2;
138
133
 
139
134
  export { }