@module-federation/bridge-react 0.0.0-next-20250408084324 → 0.0.0-next-20250410121036

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +9 -3
  2. package/dist/index.cjs.js +64 -136
  3. package/dist/index.d.ts +24 -1
  4. package/dist/index.es.js +67 -139
  5. package/dist/internal/bridge-base-CW88-1Be.es.js +103 -0
  6. package/dist/internal/bridge-base-DBiwuddQ.cjs.js +119 -0
  7. package/dist/internal/react-error-boundary.esm-CMdlkNPP.es.js +99 -0
  8. package/dist/internal/react-error-boundary.esm-D8nxmvmv.cjs.js +98 -0
  9. package/dist/legacy.cjs.js +4 -0
  10. package/dist/legacy.d.ts +104 -0
  11. package/dist/legacy.es.js +4 -0
  12. package/dist/router-v5.cjs.js +1 -1
  13. package/dist/router-v5.es.js +1 -1
  14. package/dist/router-v6.cjs.js +1 -1
  15. package/dist/router-v6.es.js +1 -1
  16. package/dist/router.cjs.js +1 -1
  17. package/dist/router.es.js +1 -1
  18. package/dist/v16.cjs.js +22 -0
  19. package/dist/v16.d.ts +104 -0
  20. package/dist/v16.es.js +22 -0
  21. package/dist/v18.cjs.js +15 -0
  22. package/dist/v18.d.ts +105 -0
  23. package/dist/v18.es.js +15 -0
  24. package/dist/v19.cjs.js +15 -0
  25. package/dist/v19.d.ts +106 -0
  26. package/dist/v19.es.js +15 -0
  27. package/package.json +19 -4
  28. package/src/index.ts +6 -0
  29. package/src/legacy.ts +13 -0
  30. package/src/provider/create.tsx +73 -20
  31. package/src/provider/versions/bridge-base.tsx +122 -0
  32. package/src/provider/versions/legacy.ts +42 -0
  33. package/src/provider/versions/v18.ts +47 -0
  34. package/src/provider/versions/v19.ts +48 -0
  35. package/src/remote/create.tsx +4 -2
  36. package/src/types.ts +19 -0
  37. package/src/utils/index.ts +0 -20
  38. package/src/v18.ts +9 -0
  39. package/src/v19.ts +9 -0
  40. package/vite.config.ts +54 -0
  41. package/src/provider/compat.ts +0 -60
  42. /package/dist/{context-C79iMWYD.cjs → internal/context.cjs.js} +0 -0
  43. /package/dist/{context-Dbqf0szX.js → internal/context.es.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,11 +1,17 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
- ## 0.0.0-next-20250408084324
3
+ ## 0.0.0-next-20250410121036
4
+
5
+ ### Minor Changes
6
+
7
+ - d802e00: feat(react-bridge): Add native support for React 19 in bridge-react with enhanced createRoot options
4
8
 
5
9
  ### Patch Changes
6
10
 
7
- - @module-federation/sdk@0.0.0-next-20250408084324
8
- - @module-federation/bridge-shared@0.0.0-next-20250408084324
11
+ - d0a11ff: feat(bridge-react): support react v19 in react compat file.
12
+ - Updated dependencies [f4fb242]
13
+ - @module-federation/sdk@0.0.0-next-20250410121036
14
+ - @module-federation/bridge-shared@0.0.0-next-20250410121036
9
15
 
10
16
  ## 0.11.4
11
17
 
package/dist/index.cjs.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
3
  const React = require("react");
5
- const context = require("./context-C79iMWYD.cjs");
4
+ const reactErrorBoundary_esm = require("./internal/react-error-boundary.esm-D8nxmvmv.cjs.js");
5
+ const context = require("./internal/context.cjs.js");
6
6
  const ReactRouterDOM = require("react-router-dom");
7
7
  const plugin = require("./plugin.cjs.js");
8
8
  const ReactDOM = require("react-dom");
@@ -24,101 +24,6 @@ function _interopNamespaceDefault(e2) {
24
24
  }
25
25
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
26
26
  const ReactRouterDOM__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactRouterDOM);
27
- const ErrorBoundaryContext = React.createContext(null);
28
- const initialState = {
29
- didCatch: false,
30
- error: null
31
- };
32
- class ErrorBoundary extends React.Component {
33
- constructor(props) {
34
- super(props);
35
- this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
36
- this.state = initialState;
37
- }
38
- static getDerivedStateFromError(error) {
39
- return {
40
- didCatch: true,
41
- error
42
- };
43
- }
44
- resetErrorBoundary() {
45
- const {
46
- error
47
- } = this.state;
48
- if (error !== null) {
49
- var _this$props$onReset, _this$props;
50
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
51
- args[_key] = arguments[_key];
52
- }
53
- (_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
54
- args,
55
- reason: "imperative-api"
56
- });
57
- this.setState(initialState);
58
- }
59
- }
60
- componentDidCatch(error, info) {
61
- var _this$props$onError, _this$props2;
62
- (_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
63
- }
64
- componentDidUpdate(prevProps, prevState) {
65
- const {
66
- didCatch
67
- } = this.state;
68
- const {
69
- resetKeys
70
- } = this.props;
71
- if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
72
- var _this$props$onReset2, _this$props3;
73
- (_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
74
- next: resetKeys,
75
- prev: prevProps.resetKeys,
76
- reason: "keys"
77
- });
78
- this.setState(initialState);
79
- }
80
- }
81
- render() {
82
- const {
83
- children,
84
- fallbackRender,
85
- FallbackComponent,
86
- fallback
87
- } = this.props;
88
- const {
89
- didCatch,
90
- error
91
- } = this.state;
92
- let childToRender = children;
93
- if (didCatch) {
94
- const props = {
95
- error,
96
- resetErrorBoundary: this.resetErrorBoundary
97
- };
98
- if (typeof fallbackRender === "function") {
99
- childToRender = fallbackRender(props);
100
- } else if (FallbackComponent) {
101
- childToRender = React.createElement(FallbackComponent, props);
102
- } else if (fallback !== void 0) {
103
- childToRender = fallback;
104
- } else {
105
- throw error;
106
- }
107
- }
108
- return React.createElement(ErrorBoundaryContext.Provider, {
109
- value: {
110
- didCatch,
111
- error,
112
- resetErrorBoundary: this.resetErrorBoundary
113
- }
114
- }, childToRender);
115
- }
116
- }
117
- function hasArrayChanged() {
118
- let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
119
- let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
120
- return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
121
- }
122
27
  function e() {
123
28
  const t = new PopStateEvent("popstate", { state: window.history.state });
124
29
  window.dispatchEvent(t);
@@ -146,8 +51,8 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
146
51
  providerInfoRef.current = providerReturn;
147
52
  setInitialized(true);
148
53
  return () => {
149
- var _a2, _b, _c, _d, _e, _f, _g, _h;
150
- if ((_a2 = providerInfoRef.current) == null ? void 0 : _a2.destroy) {
54
+ var _a, _b, _c, _d, _e, _f, _g, _h;
55
+ if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
151
56
  context.LoggerInstance.debug(
152
57
  `createRemoteComponent LazyComponent destroy >>>`,
153
58
  { moduleName, basename, dom: renderDom.current }
@@ -176,7 +81,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
176
81
  };
177
82
  }, [moduleName]);
178
83
  React.useEffect(() => {
179
- var _a2, _b, _c, _d, _e, _f;
84
+ var _a, _b, _c, _d, _e, _f;
180
85
  if (!initialized || !providerInfoRef.current) return;
181
86
  let renderProps = {
182
87
  moduleName,
@@ -187,7 +92,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
187
92
  ...resProps
188
93
  };
189
94
  renderDom.current = rootRef.current;
190
- const beforeBridgeRenderRes = ((_c = (_b = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
95
+ 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(renderProps)) || {};
191
96
  renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
192
97
  providerInfoRef.current.render(renderProps);
193
98
  (_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);
@@ -197,7 +102,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
197
102
  });
198
103
  function withRouterData(WrappedComponent) {
199
104
  const Component = React.forwardRef(function(props, ref) {
200
- var _a2;
105
+ var _a;
201
106
  if (props == null ? void 0 : props.basename) {
202
107
  return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename: props.basename, ref });
203
108
  }
@@ -230,7 +135,7 @@ function withRouterData(WrappedComponent) {
230
135
  const match = useRouteMatch == null ? void 0 : useRouteMatch();
231
136
  if (useHistory) {
232
137
  const history = useHistory == null ? void 0 : useHistory();
233
- basename = (_a2 = history == null ? void 0 : history.createHref) == null ? void 0 : _a2.call(history, { pathname: "/" });
138
+ basename = (_a = history == null ? void 0 : history.createHref) == null ? void 0 : _a.call(history, { pathname: "/" });
234
139
  }
235
140
  if (match) {
236
141
  basename = context.pathJoin(basename, (match == null ? void 0 : match.path) || "/");
@@ -318,13 +223,27 @@ function createLazyRemoteComponent(info) {
318
223
  function createRemoteComponent(info) {
319
224
  const LazyComponent = createLazyRemoteComponent(info);
320
225
  return React.forwardRef((props, ref) => {
321
- return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref })));
226
+ return /* @__PURE__ */ React.createElement(
227
+ reactErrorBoundary_esm.ErrorBoundary,
228
+ {
229
+ FallbackComponent: info.fallback
230
+ },
231
+ /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref }))
232
+ );
322
233
  });
323
234
  }
324
- const isReact18 = (_a = ReactDOM.version) == null ? void 0 : _a.startsWith("18");
325
- function createRoot(container, options) {
235
+ function defaultCreateRoot(container, options) {
236
+ const reactVersion = ReactDOM.version || "";
237
+ const isReact18 = reactVersion.startsWith("18");
326
238
  if (isReact18) {
327
- return ReactDOM.createRoot(container, options);
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
+ }
328
247
  }
329
248
  return {
330
249
  render(children) {
@@ -336,7 +255,8 @@ function createRoot(container, options) {
336
255
  };
337
256
  }
338
257
  function createBridgeComponent({
339
- createRoot: createRoot$1 = createRoot,
258
+ createRoot = defaultCreateRoot,
259
+ defaultRootOptions,
340
260
  ...bridgeInfo
341
261
  }) {
342
262
  return () => {
@@ -360,7 +280,7 @@ function createBridgeComponent({
360
280
  };
361
281
  return {
362
282
  async render(info) {
363
- var _a2, _b, _c, _d, _e, _f;
283
+ var _a, _b, _c, _d, _e, _f;
364
284
  context.LoggerInstance.debug(`createBridgeComponent render Info`, info);
365
285
  const {
366
286
  moduleName,
@@ -368,38 +288,46 @@ function createBridgeComponent({
368
288
  basename,
369
289
  memoryRoute,
370
290
  fallback,
291
+ rootOptions,
371
292
  ...propsInfo
372
293
  } = info;
373
- const beforeBridgeRenderRes = ((_c = (_b = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(info)) || {};
374
- const rootComponentWithErrorBoundary = /* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
375
- RawComponent,
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,
376
301
  {
377
- appInfo: {
378
- moduleName,
379
- basename,
380
- memoryRoute
381
- },
382
- propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
383
- }
384
- ));
385
- if (bridgeInfo.render) {
386
- await Promise.resolve(
387
- bridgeInfo.render(rootComponentWithErrorBoundary, dom)
388
- ).then((root) => rootMap.set(dom, root));
389
- } else {
390
- let root = rootMap.get(dom);
391
- if (!root) {
392
- root = createRoot$1(dom);
393
- rootMap.set(dom, root);
394
- }
395
- if ("render" in root) {
396
- root.render(rootComponentWithErrorBoundary);
397
- }
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);
398
326
  }
399
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)) || {};
400
328
  },
401
329
  destroy(info) {
402
- var _a2, _b, _c;
330
+ var _a, _b, _c;
403
331
  const { dom } = info;
404
332
  context.LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
405
333
  const root = rootMap.get(dom);
@@ -407,11 +335,11 @@ function createBridgeComponent({
407
335
  if ("unmount" in root) {
408
336
  root.unmount();
409
337
  } else {
410
- ReactDOM.unmountComponentAtNode(root);
338
+ ReactDOM.unmountComponentAtNode(dom);
411
339
  }
412
340
  rootMap.delete(dom);
413
341
  }
414
- (_c = (_b = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b.afterBridgeDestroy) == null ? void 0 : _c.emit(info);
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);
415
343
  }
416
344
  };
417
345
  };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  import { default as default_2 } from 'react';
2
2
  import * as React_2 from 'react';
3
3
 
4
- export declare function createBridgeComponent<T>({ createRoot, ...bridgeInfo }: ProviderFnParams<T>): () => {
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>): () => {
5
9
  render(info: RenderParams): Promise<void>;
6
10
  destroy(info: DestroyParams): void;
7
11
  };
@@ -34,6 +38,16 @@ declare interface ProviderFnParams<T> {
34
38
  rootComponent: React_2.ComponentType<T>;
35
39
  render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
36
40
  createRoot?: (container: Element | DocumentFragment, options?: CreateRootOptions) => Root;
41
+ /**
42
+ * Default options to pass to createRoot for React 18 and 19
43
+ * These options will be used when creating a root unless overridden by rootOptions in render params
44
+ * @example
45
+ * {
46
+ * identifierPrefix: 'app-',
47
+ * onRecoverableError: (err) => console.error(err)
48
+ * }
49
+ */
50
+ defaultRootOptions?: CreateRootOptions;
37
51
  }
38
52
 
39
53
  /**
@@ -97,6 +111,15 @@ export declare interface RenderParams {
97
111
  initialState?: Record<string, unknown>;
98
112
  };
99
113
  dom: HTMLElement;
114
+ /**
115
+ * Options to pass to createRoot for React 18 and 19
116
+ * @example
117
+ * {
118
+ * identifierPrefix: 'app-',
119
+ * onRecoverableError: (err) => console.error(err)
120
+ * }
121
+ */
122
+ rootOptions?: CreateRootOptions;
100
123
  [key: string]: unknown;
101
124
  }
102
125
 
package/dist/index.es.js CHANGED
@@ -1,105 +1,10 @@
1
- var _a;
2
1
  import * as React from "react";
3
- import React__default, { createContext, Component, createElement, forwardRef, useRef, useState, useEffect, useContext } from "react";
4
- import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin, R as RouterContext } from "./context-Dbqf0szX.js";
2
+ import React__default, { forwardRef, useRef, useState, useEffect, useContext } from "react";
3
+ import { E as ErrorBoundary } from "./internal/react-error-boundary.esm-CMdlkNPP.es.js";
4
+ import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin, R as RouterContext } from "./internal/context.es.js";
5
5
  import * as ReactRouterDOM from "react-router-dom";
6
6
  import { federationRuntime } from "./plugin.es.js";
7
7
  import ReactDOM from "react-dom";
8
- const ErrorBoundaryContext = createContext(null);
9
- const initialState = {
10
- didCatch: false,
11
- error: null
12
- };
13
- class ErrorBoundary extends Component {
14
- constructor(props) {
15
- super(props);
16
- this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
17
- this.state = initialState;
18
- }
19
- static getDerivedStateFromError(error) {
20
- return {
21
- didCatch: true,
22
- error
23
- };
24
- }
25
- resetErrorBoundary() {
26
- const {
27
- error
28
- } = this.state;
29
- if (error !== null) {
30
- var _this$props$onReset, _this$props;
31
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
32
- args[_key] = arguments[_key];
33
- }
34
- (_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
35
- args,
36
- reason: "imperative-api"
37
- });
38
- this.setState(initialState);
39
- }
40
- }
41
- componentDidCatch(error, info) {
42
- var _this$props$onError, _this$props2;
43
- (_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
44
- }
45
- componentDidUpdate(prevProps, prevState) {
46
- const {
47
- didCatch
48
- } = this.state;
49
- const {
50
- resetKeys
51
- } = this.props;
52
- if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
53
- var _this$props$onReset2, _this$props3;
54
- (_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
55
- next: resetKeys,
56
- prev: prevProps.resetKeys,
57
- reason: "keys"
58
- });
59
- this.setState(initialState);
60
- }
61
- }
62
- render() {
63
- const {
64
- children,
65
- fallbackRender,
66
- FallbackComponent,
67
- fallback
68
- } = this.props;
69
- const {
70
- didCatch,
71
- error
72
- } = this.state;
73
- let childToRender = children;
74
- if (didCatch) {
75
- const props = {
76
- error,
77
- resetErrorBoundary: this.resetErrorBoundary
78
- };
79
- if (typeof fallbackRender === "function") {
80
- childToRender = fallbackRender(props);
81
- } else if (FallbackComponent) {
82
- childToRender = createElement(FallbackComponent, props);
83
- } else if (fallback !== void 0) {
84
- childToRender = fallback;
85
- } else {
86
- throw error;
87
- }
88
- }
89
- return createElement(ErrorBoundaryContext.Provider, {
90
- value: {
91
- didCatch,
92
- error,
93
- resetErrorBoundary: this.resetErrorBoundary
94
- }
95
- }, childToRender);
96
- }
97
- }
98
- function hasArrayChanged() {
99
- let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
100
- let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
101
- return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
102
- }
103
8
  function e() {
104
9
  const t = new PopStateEvent("popstate", { state: window.history.state });
105
10
  window.dispatchEvent(t);
@@ -127,8 +32,8 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
127
32
  providerInfoRef.current = providerReturn;
128
33
  setInitialized(true);
129
34
  return () => {
130
- var _a2, _b, _c, _d, _e, _f, _g, _h;
131
- if ((_a2 = providerInfoRef.current) == null ? void 0 : _a2.destroy) {
35
+ var _a, _b, _c, _d, _e, _f, _g, _h;
36
+ if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
132
37
  LoggerInstance.debug(
133
38
  `createRemoteComponent LazyComponent destroy >>>`,
134
39
  { moduleName, basename, dom: renderDom.current }
@@ -157,7 +62,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
157
62
  };
158
63
  }, [moduleName]);
159
64
  useEffect(() => {
160
- var _a2, _b, _c, _d, _e, _f;
65
+ var _a, _b, _c, _d, _e, _f;
161
66
  if (!initialized || !providerInfoRef.current) return;
162
67
  let renderProps = {
163
68
  moduleName,
@@ -168,7 +73,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
168
73
  ...resProps
169
74
  };
170
75
  renderDom.current = rootRef.current;
171
- const beforeBridgeRenderRes = ((_c = (_b = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
76
+ 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(renderProps)) || {};
172
77
  renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
173
78
  providerInfoRef.current.render(renderProps);
174
79
  (_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);
@@ -177,8 +82,8 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
177
82
  return /* @__PURE__ */ React__default.createElement("div", { className: rootComponentClassName, style, ref: rootRef });
178
83
  });
179
84
  function withRouterData(WrappedComponent) {
180
- const Component2 = forwardRef(function(props, ref) {
181
- var _a2;
85
+ const Component = forwardRef(function(props, ref) {
86
+ var _a;
182
87
  if (props == null ? void 0 : props.basename) {
183
88
  return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename: props.basename, ref });
184
89
  }
@@ -211,7 +116,7 @@ function withRouterData(WrappedComponent) {
211
116
  const match = useRouteMatch == null ? void 0 : useRouteMatch();
212
117
  if (useHistory) {
213
118
  const history = useHistory == null ? void 0 : useHistory();
214
- basename = (_a2 = history == null ? void 0 : history.createHref) == null ? void 0 : _a2.call(history, { pathname: "/" });
119
+ basename = (_a = history == null ? void 0 : history.createHref) == null ? void 0 : _a.call(history, { pathname: "/" });
215
120
  }
216
121
  if (match) {
217
122
  basename = pathJoin(basename, (match == null ? void 0 : match.path) || "/");
@@ -244,7 +149,7 @@ function withRouterData(WrappedComponent) {
244
149
  return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename, ref });
245
150
  });
246
151
  return forwardRef(function(props, ref) {
247
- return /* @__PURE__ */ React__default.createElement(Component2, { ...props, ref });
152
+ return /* @__PURE__ */ React__default.createElement(Component, { ...props, ref });
248
153
  });
249
154
  }
250
155
  const RemoteApp = withRouterData(RemoteAppWrapper);
@@ -299,13 +204,27 @@ function createLazyRemoteComponent(info) {
299
204
  function createRemoteComponent(info) {
300
205
  const LazyComponent = createLazyRemoteComponent(info);
301
206
  return forwardRef((props, ref) => {
302
- return /* @__PURE__ */ React__default.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: info.loading }, /* @__PURE__ */ React__default.createElement(LazyComponent, { ...props, ref })));
207
+ return /* @__PURE__ */ React__default.createElement(
208
+ ErrorBoundary,
209
+ {
210
+ FallbackComponent: info.fallback
211
+ },
212
+ /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: info.loading }, /* @__PURE__ */ React__default.createElement(LazyComponent, { ...props, ref }))
213
+ );
303
214
  });
304
215
  }
305
- const isReact18 = (_a = ReactDOM.version) == null ? void 0 : _a.startsWith("18");
306
- function createRoot(container, options) {
216
+ function defaultCreateRoot(container, options) {
217
+ const reactVersion = ReactDOM.version || "";
218
+ const isReact18 = reactVersion.startsWith("18");
307
219
  if (isReact18) {
308
- return ReactDOM.createRoot(container, options);
220
+ try {
221
+ return ReactDOM.createRoot(container, options);
222
+ } catch (e2) {
223
+ console.warn(
224
+ "Failed to use React 18 createRoot API, falling back to legacy API",
225
+ e2
226
+ );
227
+ }
309
228
  }
310
229
  return {
311
230
  render(children) {
@@ -317,7 +236,8 @@ function createRoot(container, options) {
317
236
  };
318
237
  }
319
238
  function createBridgeComponent({
320
- createRoot: createRoot$1 = createRoot,
239
+ createRoot = defaultCreateRoot,
240
+ defaultRootOptions,
321
241
  ...bridgeInfo
322
242
  }) {
323
243
  return () => {
@@ -341,7 +261,7 @@ function createBridgeComponent({
341
261
  };
342
262
  return {
343
263
  async render(info) {
344
- var _a2, _b, _c, _d, _e, _f;
264
+ var _a, _b, _c, _d, _e, _f;
345
265
  LoggerInstance.debug(`createBridgeComponent render Info`, info);
346
266
  const {
347
267
  moduleName,
@@ -349,38 +269,46 @@ function createBridgeComponent({
349
269
  basename,
350
270
  memoryRoute,
351
271
  fallback,
272
+ rootOptions,
352
273
  ...propsInfo
353
274
  } = info;
354
- const beforeBridgeRenderRes = ((_c = (_b = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(info)) || {};
355
- const rootComponentWithErrorBoundary = /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
356
- RawComponent,
275
+ const mergedRootOptions = {
276
+ ...defaultRootOptions,
277
+ ...rootOptions
278
+ };
279
+ 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)) || {};
280
+ const rootComponentWithErrorBoundary = /* @__PURE__ */ React.createElement(
281
+ ErrorBoundary,
357
282
  {
358
- appInfo: {
359
- moduleName,
360
- basename,
361
- memoryRoute
362
- },
363
- propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
364
- }
365
- ));
366
- if (bridgeInfo.render) {
367
- await Promise.resolve(
368
- bridgeInfo.render(rootComponentWithErrorBoundary, dom)
369
- ).then((root) => rootMap.set(dom, root));
370
- } else {
371
- let root = rootMap.get(dom);
372
- if (!root) {
373
- root = createRoot$1(dom);
374
- rootMap.set(dom, root);
375
- }
376
- if ("render" in root) {
377
- root.render(rootComponentWithErrorBoundary);
378
- }
283
+ FallbackComponent: fallback
284
+ },
285
+ /* @__PURE__ */ React.createElement(
286
+ RawComponent,
287
+ {
288
+ appInfo: {
289
+ moduleName,
290
+ basename,
291
+ memoryRoute
292
+ },
293
+ propsInfo: {
294
+ ...propsInfo,
295
+ ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
296
+ }
297
+ }
298
+ )
299
+ );
300
+ let root = rootMap.get(dom);
301
+ if (!root) {
302
+ root = createRoot(dom, mergedRootOptions);
303
+ rootMap.set(dom, root);
304
+ }
305
+ if ("render" in root) {
306
+ root.render(rootComponentWithErrorBoundary);
379
307
  }
380
308
  ((_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)) || {};
381
309
  },
382
310
  destroy(info) {
383
- var _a2, _b, _c;
311
+ var _a, _b, _c;
384
312
  const { dom } = info;
385
313
  LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
386
314
  const root = rootMap.get(dom);
@@ -388,11 +316,11 @@ function createBridgeComponent({
388
316
  if ("unmount" in root) {
389
317
  root.unmount();
390
318
  } else {
391
- ReactDOM.unmountComponentAtNode(root);
319
+ ReactDOM.unmountComponentAtNode(dom);
392
320
  }
393
321
  rootMap.delete(dom);
394
322
  }
395
- (_c = (_b = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b.afterBridgeDestroy) == null ? void 0 : _c.emit(info);
323
+ (_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);
396
324
  }
397
325
  };
398
326
  };