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

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,26 +1,20 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
- ## 0.0.0-next-20250408024819
3
+ ## 0.0.0-next-20250408084324
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - chore: bump next
8
- - @module-federation/sdk@0.0.0-next-20250408024819
9
- - @module-federation/bridge-shared@0.0.0-next-20250408024819
7
+ - @module-federation/sdk@0.0.0-next-20250408084324
8
+ - @module-federation/bridge-shared@0.0.0-next-20250408084324
10
9
 
11
- ## 0.12.0
12
-
13
- ### Minor Changes
14
-
15
- - 8b3f9d0: feat(react-bridge): Add native support for React 19 in bridge-react with enhanced createRoot options
10
+ ## 0.11.4
16
11
 
17
12
  ### Patch Changes
18
13
 
19
- - 8b3f9d0: feat(bridge-react): support react v19 in react compat file.
20
14
  - Updated dependencies [64a2bc1]
21
15
  - Updated dependencies [c14842f]
22
- - @module-federation/sdk@0.12.0
23
- - @module-federation/bridge-shared@0.12.0
16
+ - @module-federation/sdk@0.11.4
17
+ - @module-federation/bridge-shared@0.11.4
24
18
 
25
19
  ## 0.11.3
26
20
 
package/dist/index.cjs.js CHANGED
@@ -1,27 +1,5 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
- var _a, _b;
2
+ var _a;
25
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
26
4
  const React = require("react");
27
5
  const context = require("./context-C79iMWYD.cjs");
@@ -168,13 +146,13 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
168
146
  providerInfoRef.current = providerReturn;
169
147
  setInitialized(true);
170
148
  return () => {
171
- var _a2, _b2, _c, _d, _e, _f, _g, _h;
149
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
172
150
  if ((_a2 = providerInfoRef.current) == null ? void 0 : _a2.destroy) {
173
151
  context.LoggerInstance.debug(
174
152
  `createRemoteComponent LazyComponent destroy >>>`,
175
153
  { moduleName, basename, dom: renderDom.current }
176
154
  );
177
- (_d = (_c = (_b2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b2.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
155
+ (_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
178
156
  moduleName,
179
157
  dom: renderDom.current,
180
158
  basename,
@@ -198,7 +176,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
198
176
  };
199
177
  }, [moduleName]);
200
178
  React.useEffect(() => {
201
- var _a2, _b2, _c, _d, _e, _f;
179
+ var _a2, _b, _c, _d, _e, _f;
202
180
  if (!initialized || !providerInfoRef.current) return;
203
181
  let renderProps = {
204
182
  moduleName,
@@ -209,7 +187,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
209
187
  ...resProps
210
188
  };
211
189
  renderDom.current = rootRef.current;
212
- const beforeBridgeRenderRes = ((_c = (_b2 = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b2.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
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)) || {};
213
191
  renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
214
192
  providerInfoRef.current.render(renderProps);
215
193
  (_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);
@@ -344,40 +322,10 @@ function createRemoteComponent(info) {
344
322
  });
345
323
  }
346
324
  const isReact18 = (_a = ReactDOM.version) == null ? void 0 : _a.startsWith("18");
347
- const isReact19 = (_b = ReactDOM.version) == null ? void 0 : _b.startsWith("19");
348
- let reactDOMClientPromise = null;
349
- async function loadReactDOMClient() {
350
- if (!isReact19) return null;
351
- if (!reactDOMClientPromise) {
352
- reactDOMClientPromise = import("react-dom/client");
325
+ function createRoot(container, options) {
326
+ if (isReact18) {
327
+ return ReactDOM.createRoot(container, options);
353
328
  }
354
- return reactDOMClientPromise;
355
- }
356
- function createReact19Root(container, options) {
357
- loadReactDOMClient();
358
- return {
359
- render(children) {
360
- loadReactDOMClient().then((client) => {
361
- if (client && client.createRoot) {
362
- const root = client.createRoot(container, options);
363
- root.render(children);
364
- }
365
- });
366
- },
367
- unmount() {
368
- loadReactDOMClient().then((client) => {
369
- if (client && client.createRoot) {
370
- const root = client.createRoot(container, options);
371
- root.unmount();
372
- }
373
- });
374
- }
375
- };
376
- }
377
- function createReact18Root(container, options) {
378
- return ReactDOM.createRoot(container, options);
379
- }
380
- function createReact16Or17Root(container) {
381
329
  return {
382
330
  render(children) {
383
331
  ReactDOM.render(children, container);
@@ -387,18 +335,8 @@ function createReact16Or17Root(container) {
387
335
  }
388
336
  };
389
337
  }
390
- function createRoot(container, options) {
391
- if (isReact19) {
392
- return createReact19Root(container, options);
393
- }
394
- if (isReact18) {
395
- return createReact18Root(container, options);
396
- }
397
- return createReact16Or17Root(container);
398
- }
399
338
  function createBridgeComponent({
400
339
  createRoot: createRoot$1 = createRoot,
401
- defaultRootOptions,
402
340
  ...bridgeInfo
403
341
  }) {
404
342
  return () => {
@@ -422,7 +360,7 @@ function createBridgeComponent({
422
360
  };
423
361
  return {
424
362
  async render(info) {
425
- var _a2, _b2, _c, _d, _e, _f;
363
+ var _a2, _b, _c, _d, _e, _f;
426
364
  context.LoggerInstance.debug(`createBridgeComponent render Info`, info);
427
365
  const {
428
366
  moduleName,
@@ -430,14 +368,9 @@ function createBridgeComponent({
430
368
  basename,
431
369
  memoryRoute,
432
370
  fallback,
433
- rootOptions,
434
371
  ...propsInfo
435
372
  } = info;
436
- const mergedRootOptions = {
437
- ...defaultRootOptions,
438
- ...rootOptions
439
- };
440
- const beforeBridgeRenderRes = ((_c = (_b2 = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b2.beforeBridgeRender) == null ? void 0 : _c.emit(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)) || {};
441
374
  const rootComponentWithErrorBoundary = /* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement(
442
375
  RawComponent,
443
376
  {
@@ -446,10 +379,7 @@ function createBridgeComponent({
446
379
  basename,
447
380
  memoryRoute
448
381
  },
449
- propsInfo: {
450
- ...propsInfo,
451
- ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
452
- }
382
+ propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
453
383
  }
454
384
  ));
455
385
  if (bridgeInfo.render) {
@@ -459,7 +389,7 @@ function createBridgeComponent({
459
389
  } else {
460
390
  let root = rootMap.get(dom);
461
391
  if (!root) {
462
- root = createRoot$1(dom, mergedRootOptions);
392
+ root = createRoot$1(dom);
463
393
  rootMap.set(dom, root);
464
394
  }
465
395
  if ("render" in root) {
@@ -469,7 +399,7 @@ function createBridgeComponent({
469
399
  ((_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)) || {};
470
400
  },
471
401
  destroy(info) {
472
- var _a2, _b2, _c;
402
+ var _a2, _b, _c;
473
403
  const { dom } = info;
474
404
  context.LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
475
405
  const root = rootMap.get(dom);
@@ -481,7 +411,7 @@ function createBridgeComponent({
481
411
  }
482
412
  rootMap.delete(dom);
483
413
  }
484
- (_c = (_b2 = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b2.afterBridgeDestroy) == null ? void 0 : _c.emit(info);
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);
485
415
  }
486
416
  };
487
417
  };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
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, defaultRootOptions, ...bridgeInfo }: ProviderFnParams<T>): () => {
4
+ export declare function createBridgeComponent<T>({ createRoot, ...bridgeInfo }: ProviderFnParams<T>): () => {
5
5
  render(info: RenderParams): Promise<void>;
6
6
  destroy(info: DestroyParams): void;
7
7
  };
@@ -34,16 +34,6 @@ declare interface ProviderFnParams<T> {
34
34
  rootComponent: React_2.ComponentType<T>;
35
35
  render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
36
36
  createRoot?: (container: Element | DocumentFragment, options?: CreateRootOptions) => Root;
37
- /**
38
- * Default options to pass to createRoot for React 18 and 19
39
- * These options will be used when creating a root unless overridden by rootOptions in render params
40
- * @example
41
- * {
42
- * identifierPrefix: 'app-',
43
- * onRecoverableError: (err) => console.error(err)
44
- * }
45
- */
46
- defaultRootOptions?: CreateRootOptions;
47
37
  }
48
38
 
49
39
  /**
@@ -107,15 +97,6 @@ export declare interface RenderParams {
107
97
  initialState?: Record<string, unknown>;
108
98
  };
109
99
  dom: HTMLElement;
110
- /**
111
- * Options to pass to createRoot for React 18 and 19
112
- * @example
113
- * {
114
- * identifierPrefix: 'app-',
115
- * onRecoverableError: (err) => console.error(err)
116
- * }
117
- */
118
- rootOptions?: CreateRootOptions;
119
100
  [key: string]: unknown;
120
101
  }
121
102
 
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- var _a, _b;
1
+ var _a;
2
2
  import * as React from "react";
3
3
  import React__default, { createContext, Component, createElement, forwardRef, useRef, useState, useEffect, useContext } from "react";
4
4
  import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin, R as RouterContext } from "./context-Dbqf0szX.js";
@@ -127,13 +127,13 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
127
127
  providerInfoRef.current = providerReturn;
128
128
  setInitialized(true);
129
129
  return () => {
130
- var _a2, _b2, _c, _d, _e, _f, _g, _h;
130
+ var _a2, _b, _c, _d, _e, _f, _g, _h;
131
131
  if ((_a2 = providerInfoRef.current) == null ? void 0 : _a2.destroy) {
132
132
  LoggerInstance.debug(
133
133
  `createRemoteComponent LazyComponent destroy >>>`,
134
134
  { moduleName, basename, dom: renderDom.current }
135
135
  );
136
- (_d = (_c = (_b2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b2.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
136
+ (_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
137
137
  moduleName,
138
138
  dom: renderDom.current,
139
139
  basename,
@@ -157,7 +157,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
157
157
  };
158
158
  }, [moduleName]);
159
159
  useEffect(() => {
160
- var _a2, _b2, _c, _d, _e, _f;
160
+ var _a2, _b, _c, _d, _e, _f;
161
161
  if (!initialized || !providerInfoRef.current) return;
162
162
  let renderProps = {
163
163
  moduleName,
@@ -168,7 +168,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
168
168
  ...resProps
169
169
  };
170
170
  renderDom.current = rootRef.current;
171
- const beforeBridgeRenderRes = ((_c = (_b2 = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b2.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
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)) || {};
172
172
  renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
173
173
  providerInfoRef.current.render(renderProps);
174
174
  (_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);
@@ -303,40 +303,10 @@ function createRemoteComponent(info) {
303
303
  });
304
304
  }
305
305
  const isReact18 = (_a = ReactDOM.version) == null ? void 0 : _a.startsWith("18");
306
- const isReact19 = (_b = ReactDOM.version) == null ? void 0 : _b.startsWith("19");
307
- let reactDOMClientPromise = null;
308
- async function loadReactDOMClient() {
309
- if (!isReact19) return null;
310
- if (!reactDOMClientPromise) {
311
- reactDOMClientPromise = import("react-dom/client");
306
+ function createRoot(container, options) {
307
+ if (isReact18) {
308
+ return ReactDOM.createRoot(container, options);
312
309
  }
313
- return reactDOMClientPromise;
314
- }
315
- function createReact19Root(container, options) {
316
- loadReactDOMClient();
317
- return {
318
- render(children) {
319
- loadReactDOMClient().then((client) => {
320
- if (client && client.createRoot) {
321
- const root = client.createRoot(container, options);
322
- root.render(children);
323
- }
324
- });
325
- },
326
- unmount() {
327
- loadReactDOMClient().then((client) => {
328
- if (client && client.createRoot) {
329
- const root = client.createRoot(container, options);
330
- root.unmount();
331
- }
332
- });
333
- }
334
- };
335
- }
336
- function createReact18Root(container, options) {
337
- return ReactDOM.createRoot(container, options);
338
- }
339
- function createReact16Or17Root(container) {
340
310
  return {
341
311
  render(children) {
342
312
  ReactDOM.render(children, container);
@@ -346,18 +316,8 @@ function createReact16Or17Root(container) {
346
316
  }
347
317
  };
348
318
  }
349
- function createRoot(container, options) {
350
- if (isReact19) {
351
- return createReact19Root(container, options);
352
- }
353
- if (isReact18) {
354
- return createReact18Root(container, options);
355
- }
356
- return createReact16Or17Root(container);
357
- }
358
319
  function createBridgeComponent({
359
320
  createRoot: createRoot$1 = createRoot,
360
- defaultRootOptions,
361
321
  ...bridgeInfo
362
322
  }) {
363
323
  return () => {
@@ -381,7 +341,7 @@ function createBridgeComponent({
381
341
  };
382
342
  return {
383
343
  async render(info) {
384
- var _a2, _b2, _c, _d, _e, _f;
344
+ var _a2, _b, _c, _d, _e, _f;
385
345
  LoggerInstance.debug(`createBridgeComponent render Info`, info);
386
346
  const {
387
347
  moduleName,
@@ -389,14 +349,9 @@ function createBridgeComponent({
389
349
  basename,
390
350
  memoryRoute,
391
351
  fallback,
392
- rootOptions,
393
352
  ...propsInfo
394
353
  } = info;
395
- const mergedRootOptions = {
396
- ...defaultRootOptions,
397
- ...rootOptions
398
- };
399
- const beforeBridgeRenderRes = ((_c = (_b2 = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b2.beforeBridgeRender) == null ? void 0 : _c.emit(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)) || {};
400
355
  const rootComponentWithErrorBoundary = /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
401
356
  RawComponent,
402
357
  {
@@ -405,10 +360,7 @@ function createBridgeComponent({
405
360
  basename,
406
361
  memoryRoute
407
362
  },
408
- propsInfo: {
409
- ...propsInfo,
410
- ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
411
- }
363
+ propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
412
364
  }
413
365
  ));
414
366
  if (bridgeInfo.render) {
@@ -418,7 +370,7 @@ function createBridgeComponent({
418
370
  } else {
419
371
  let root = rootMap.get(dom);
420
372
  if (!root) {
421
- root = createRoot$1(dom, mergedRootOptions);
373
+ root = createRoot$1(dom);
422
374
  rootMap.set(dom, root);
423
375
  }
424
376
  if ("render" in root) {
@@ -428,7 +380,7 @@ function createBridgeComponent({
428
380
  ((_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)) || {};
429
381
  },
430
382
  destroy(info) {
431
- var _a2, _b2, _c;
383
+ var _a2, _b, _c;
432
384
  const { dom } = info;
433
385
  LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
434
386
  const root = rootMap.get(dom);
@@ -440,7 +392,7 @@ function createBridgeComponent({
440
392
  }
441
393
  rootMap.delete(dom);
442
394
  }
443
- (_c = (_b2 = (_a2 = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a2.lifecycle) == null ? void 0 : _b2.afterBridgeDestroy) == null ? void 0 : _c.emit(info);
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);
444
396
  }
445
397
  };
446
398
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/bridge-react",
3
- "version": "0.0.0-next-20250408024819",
3
+ "version": "0.0.0-next-20250408084324",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -45,8 +45,8 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "react-error-boundary": "^4.1.2",
48
- "@module-federation/bridge-shared": "0.0.0-next-20250408024819",
49
- "@module-federation/sdk": "0.0.0-next-20250408024819"
48
+ "@module-federation/bridge-shared": "0.0.0-next-20250408084324",
49
+ "@module-federation/sdk": "0.0.0-next-20250408084324"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "react": ">=16.9.0",
@@ -67,7 +67,7 @@
67
67
  "typescript": "^5.2.2",
68
68
  "vite": "^5.4.12",
69
69
  "vite-plugin-dts": "^4.3.0",
70
- "@module-federation/runtime": "0.0.0-next-20250408024819"
70
+ "@module-federation/runtime": "0.0.0-next-20250408084324"
71
71
  },
72
72
  "scripts": {
73
73
  "dev": "vite",
@@ -1,192 +1,60 @@
1
1
  import ReactDOM from 'react-dom';
2
+ import { CreateRootOptions, Root } from '../types';
2
3
 
3
- export interface CreateRootOptions {
4
- identifierPrefix?: string;
5
- onRecoverableError?: (error: unknown) => void;
6
- transitionCallbacks?: unknown;
7
- }
8
-
9
- interface Root {
10
- render(children: React.ReactNode): void;
11
- unmount(): void;
12
- }
13
-
14
- // Check React version
4
+ // ReactDOM.version is only available in React 16.13.0 and later
15
5
  const isReact18 = ReactDOM.version?.startsWith('18');
16
- const isReact19 = ReactDOM.version?.startsWith('19');
17
-
18
- // Store the promise for async loaded ReactDOMClient
19
- let reactDOMClientPromise: Promise<any> | null = null;
20
-
21
- /**
22
- * Asynchronously load the react-dom/client module
23
- * Only attempts to load in React 19 environment
24
- */
25
- async function loadReactDOMClient() {
26
- if (!isReact19) return null;
27
-
28
- if (!reactDOMClientPromise) {
29
- reactDOMClientPromise = import('react-dom/client');
30
- }
31
-
32
- return reactDOMClientPromise;
33
- }
34
-
35
- /**
36
- * Creates a root for React 19 using dynamic import of react-dom/client
37
- */
38
- function createReact19Root(
39
- container: Element | DocumentFragment,
40
- options?: CreateRootOptions,
41
- ): Root {
42
- // Preload react-dom/client module
43
- loadReactDOMClient();
44
-
45
- // Return a simple Root object
46
- return {
47
- render(children: React.ReactNode) {
48
- // Try to load client again when render is called
49
- loadReactDOMClient().then((client) => {
50
- if (client && client.createRoot) {
51
- const root = client.createRoot(container, options);
52
- root.render(children);
53
- }
54
- });
55
- },
56
- unmount() {
57
- // Try to load client again when unmount is called
58
- loadReactDOMClient().then((client) => {
59
- if (client && client.createRoot) {
60
- const root = client.createRoot(container, options);
61
- root.unmount();
62
- }
63
- });
64
- },
65
- };
66
- }
67
-
68
- /**
69
- * Creates a root for React 18 using ReactDOM.createRoot
70
- */
71
- function createReact18Root(
72
- container: Element | DocumentFragment,
73
- options?: CreateRootOptions,
74
- ): Root {
75
- // @ts-ignore - Types will be available in React 18
76
- return (ReactDOM as any).createRoot(container, options);
77
- }
78
-
79
- /**
80
- * Creates a root for React 16/17 using legacy APIs
81
- */
82
- function createReact16Or17Root(container: Element | DocumentFragment): Root {
83
- return {
84
- render(children: React.ReactNode) {
85
- // @ts-ignore - React 17's render method is deprecated but still functional
86
- ReactDOM.render(children, container);
87
- },
88
- unmount() {
89
- ReactDOM.unmountComponentAtNode(container);
90
- },
91
- };
92
- }
93
6
 
94
7
  /**
95
- * Creates a root for a container element compatible with React 16, 18, and 19
8
+ * Creates a root for a container element compatible with both React 16 and 18
96
9
  */
97
10
  export function createRoot(
98
11
  container: Element | DocumentFragment,
99
12
  options?: CreateRootOptions,
100
13
  ): Root {
101
- if (isReact19) {
102
- return createReact19Root(container, options);
103
- }
104
-
105
14
  if (isReact18) {
106
- return createReact18Root(container, options);
15
+ // For React 18, use the new createRoot API
16
+ // @ts-ignore - Types will be available in React 18
17
+ return (ReactDOM as any).createRoot(container, options);
107
18
  }
108
19
 
109
- // For React 16/17
110
- return createReact16Or17Root(container);
111
- }
112
-
113
- /**
114
- * Creates a hydration root for React 19 using dynamic import of react-dom/client
115
- */
116
- function hydrateReact19Root(
117
- container: Element | DocumentFragment,
118
- initialChildren: React.ReactNode,
119
- options?: CreateRootOptions,
120
- ): Root {
121
- // Preload react-dom/client module
122
- loadReactDOMClient();
123
-
124
- // Return a simple Root object
20
+ // For React 16/17, simulate the new root API using render/unmountComponentAtNode
125
21
  return {
126
22
  render(children: React.ReactNode) {
127
- // Try to load client again when render is called
128
- loadReactDOMClient().then((client) => {
129
- if (client && client.hydrateRoot) {
130
- const root = client.hydrateRoot(container, initialChildren, options);
131
- root.render(children);
132
- }
133
- });
23
+ ReactDOM.render(children, container);
134
24
  },
135
25
  unmount() {
136
- // Try to load client again when unmount is called
137
- loadReactDOMClient().then((client) => {
138
- if (client && client.hydrateRoot) {
139
- const root = client.hydrateRoot(container, initialChildren, options);
140
- root.unmount();
141
- }
142
- });
26
+ ReactDOM.unmountComponentAtNode(container);
143
27
  },
144
28
  };
145
29
  }
146
30
 
147
31
  /**
148
- * Creates a hydration root for React 18 using ReactDOM.hydrateRoot
32
+ * Hydrates a container compatible with both React 16 and 18
149
33
  */
150
- function hydrateReact18Root(
34
+ export function hydrateRoot(
151
35
  container: Element | DocumentFragment,
152
36
  initialChildren: React.ReactNode,
153
37
  options?: CreateRootOptions,
154
38
  ): Root {
155
- // @ts-ignore - Types will be available in React 18
156
- return (ReactDOM as any).hydrateRoot(container, initialChildren, options);
157
- }
39
+ if (isReact18) {
40
+ // For React 18, use the new hydrateRoot API
41
+ // @ts-ignore - Types will be available in React 18
42
+ return (ReactDOM as any).hydrateRoot(container, initialChildren, options);
43
+ }
158
44
 
159
- /**
160
- * Creates a hydration root for React 16/17 using legacy APIs
161
- */
162
- function hydrateReact16Or17Root(container: Element | DocumentFragment): Root {
45
+ // For React 16/17, simulate the new root API using hydrate/unmountComponentAtNode
163
46
  return {
164
47
  render(children: React.ReactNode) {
165
- // @ts-ignore - React 17's hydrate method is deprecated but still functional
166
- ReactDOM.hydrate(children, container);
48
+ // For the initial render, use hydrate
49
+ if (children === initialChildren) {
50
+ ReactDOM.hydrate(children, container);
51
+ } else {
52
+ // For subsequent renders, use regular render
53
+ ReactDOM.render(children, container);
54
+ }
167
55
  },
168
56
  unmount() {
169
57
  ReactDOM.unmountComponentAtNode(container);
170
58
  },
171
59
  };
172
60
  }
173
-
174
- /**
175
- * Hydrates a container compatible with React 16, 18, and 19
176
- */
177
- export function hydrateRoot(
178
- container: Element | DocumentFragment,
179
- initialChildren: React.ReactNode,
180
- options?: CreateRootOptions,
181
- ): Root {
182
- if (isReact19) {
183
- return hydrateReact19Root(container, initialChildren, options);
184
- }
185
-
186
- if (isReact18) {
187
- return hydrateReact18Root(container, initialChildren, options);
188
- }
189
-
190
- // For React 16/17
191
- return hydrateReact16Or17Root(container);
192
- }
@@ -6,7 +6,6 @@ import type {
6
6
  RootType,
7
7
  DestroyParams,
8
8
  RenderParams,
9
- CreateRootOptions,
10
9
  } from '../types';
11
10
  import { ErrorBoundary } from 'react-error-boundary';
12
11
  import { RouterContext } from './context';
@@ -16,7 +15,6 @@ import { createRoot as defaultCreateRoot } from './compat';
16
15
 
17
16
  export function createBridgeComponent<T>({
18
17
  createRoot = defaultCreateRoot,
19
- defaultRootOptions,
20
18
  ...bridgeInfo
21
19
  }: ProviderFnParams<T>) {
22
20
  return () => {
@@ -50,16 +48,9 @@ export function createBridgeComponent<T>({
50
48
  basename,
51
49
  memoryRoute,
52
50
  fallback,
53
- rootOptions,
54
51
  ...propsInfo
55
52
  } = info;
56
53
 
57
- // Merge default root options with render-specific root options
58
- const mergedRootOptions: CreateRootOptions | undefined = {
59
- ...defaultRootOptions,
60
- ...(rootOptions as CreateRootOptions),
61
- };
62
-
63
54
  const beforeBridgeRenderRes =
64
55
  instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(info) || {};
65
56
 
@@ -72,10 +63,7 @@ export function createBridgeComponent<T>({
72
63
  memoryRoute,
73
64
  }}
74
65
  propsInfo={
75
- {
76
- ...propsInfo,
77
- ...(beforeBridgeRenderRes as any)?.extraProps,
78
- } as T
66
+ { ...propsInfo, ...beforeBridgeRenderRes?.extraProps } as T
79
67
  }
80
68
  />
81
69
  </ErrorBoundary>
@@ -89,7 +77,7 @@ export function createBridgeComponent<T>({
89
77
  let root = rootMap.get(dom);
90
78
  // do not call createRoot multiple times
91
79
  if (!root) {
92
- root = createRoot(dom, mergedRootOptions);
80
+ root = createRoot(dom);
93
81
  rootMap.set(dom, root);
94
82
  }
95
83
 
@@ -97,6 +85,7 @@ export function createBridgeComponent<T>({
97
85
  root.render(rootComponentWithErrorBoundary);
98
86
  }
99
87
  }
88
+
100
89
  instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
101
90
  },
102
91
 
package/src/types.ts CHANGED
@@ -34,15 +34,6 @@ export interface RenderParams {
34
34
  initialState?: Record<string, unknown>;
35
35
  };
36
36
  dom: HTMLElement;
37
- /**
38
- * Options to pass to createRoot for React 18 and 19
39
- * @example
40
- * {
41
- * identifierPrefix: 'app-',
42
- * onRecoverableError: (err) => console.error(err)
43
- * }
44
- */
45
- rootOptions?: CreateRootOptions;
46
37
  [key: string]: unknown;
47
38
  }
48
39
 
@@ -90,16 +81,6 @@ export interface ProviderFnParams<T> {
90
81
  container: Element | DocumentFragment,
91
82
  options?: CreateRootOptions,
92
83
  ) => Root;
93
- /**
94
- * Default options to pass to createRoot for React 18 and 19
95
- * These options will be used when creating a root unless overridden by rootOptions in render params
96
- * @example
97
- * {
98
- * identifierPrefix: 'app-',
99
- * onRecoverableError: (err) => console.error(err)
100
- * }
101
- */
102
- defaultRootOptions?: CreateRootOptions;
103
84
  }
104
85
 
105
86
  /**