@module-federation/bridge-react 0.0.0-next-20250208084948 → 0.0.0-next-20250208115611

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,12 +1,12 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
- ## 0.0.0-next-20250208084948
3
+ ## 0.0.0-next-20250208115611
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - c3387db: fix: the bridge-react package was failing when used with React 16 due to missing react-dom/client module
8
- - @module-federation/sdk@0.0.0-next-20250208084948
9
- - @module-federation/bridge-shared@0.0.0-next-20250208084948
8
+ - @module-federation/sdk@0.0.0-next-20250208115611
9
+ - @module-federation/bridge-shared@0.0.0-next-20250208115611
10
10
 
11
11
  ## 0.8.10
12
12
 
package/dist/index.cjs.js CHANGED
@@ -1,26 +1,4 @@
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
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
3
  const React = require("react");
26
4
  const context = require("./context-BwD5jfgB.cjs");
@@ -365,6 +343,20 @@ function createRemoteComponent(info) {
365
343
  }
366
344
  );
367
345
  }
346
+ const isReact18 = ReactDOM.version.startsWith("18");
347
+ function createRoot(container, options) {
348
+ if (isReact18) {
349
+ return ReactDOM.createRoot(container, options);
350
+ }
351
+ return {
352
+ render(children) {
353
+ ReactDOM.render(children, container);
354
+ },
355
+ unmount() {
356
+ ReactDOM.unmountComponentAtNode(container);
357
+ }
358
+ };
359
+ }
368
360
  function createBridgeComponent(bridgeInfo) {
369
361
  return () => {
370
362
  const rootMap = /* @__PURE__ */ new Map();
@@ -414,13 +406,9 @@ function createBridgeComponent(bridgeInfo) {
414
406
  bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
415
407
  ).then((root) => rootMap.set(info.dom, root));
416
408
  } else {
417
- import("react-dom/client").then(
418
- (ReactDOMClient) => {
419
- const root = ReactDOMClient.createRoot(info.dom);
420
- root.render(rootComponentWithErrorBoundary);
421
- rootMap.set(info.dom, root);
422
- }
423
- );
409
+ const root = createRoot(info.dom);
410
+ root.render(rootComponentWithErrorBoundary);
411
+ rootMap.set(info.dom, root);
424
412
  }
425
413
  ((_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)) || {};
426
414
  },
package/dist/index.es.js CHANGED
@@ -324,6 +324,20 @@ function createRemoteComponent(info) {
324
324
  }
325
325
  );
326
326
  }
327
+ const isReact18 = ReactDOM.version.startsWith("18");
328
+ function createRoot(container, options) {
329
+ if (isReact18) {
330
+ return ReactDOM.createRoot(container, options);
331
+ }
332
+ return {
333
+ render(children) {
334
+ ReactDOM.render(children, container);
335
+ },
336
+ unmount() {
337
+ ReactDOM.unmountComponentAtNode(container);
338
+ }
339
+ };
340
+ }
327
341
  function createBridgeComponent(bridgeInfo) {
328
342
  return () => {
329
343
  const rootMap = /* @__PURE__ */ new Map();
@@ -373,13 +387,9 @@ function createBridgeComponent(bridgeInfo) {
373
387
  bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
374
388
  ).then((root) => rootMap.set(info.dom, root));
375
389
  } else {
376
- import("react-dom/client").then(
377
- (ReactDOMClient) => {
378
- const root = ReactDOMClient.createRoot(info.dom);
379
- root.render(rootComponentWithErrorBoundary);
380
- rootMap.set(info.dom, root);
381
- }
382
- );
390
+ const root = createRoot(info.dom);
391
+ root.render(rootComponentWithErrorBoundary);
392
+ rootMap.set(info.dom, root);
383
393
  }
384
394
  ((_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)) || {};
385
395
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/bridge-react",
3
- "version": "0.0.0-next-20250208084948",
3
+ "version": "0.0.0-next-20250208115611",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -46,8 +46,8 @@
46
46
  "dependencies": {
47
47
  "@loadable/component": "^5.16.4",
48
48
  "react-error-boundary": "^4.1.2",
49
- "@module-federation/bridge-shared": "0.0.0-next-20250208084948",
50
- "@module-federation/sdk": "0.0.0-next-20250208084948"
49
+ "@module-federation/bridge-shared": "0.0.0-next-20250208115611",
50
+ "@module-federation/sdk": "0.0.0-next-20250208115611"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "react": ">=16.9.0",
@@ -68,7 +68,7 @@
68
68
  "typescript": "^5.2.2",
69
69
  "vite": "^5.2.14",
70
70
  "vite-plugin-dts": "^4.3.0",
71
- "@module-federation/runtime": "0.0.0-next-20250208084948"
71
+ "@module-federation/runtime": "0.0.0-next-20250208115611"
72
72
  },
73
73
  "scripts": {
74
74
  "dev": "vite",
package/src/compat.ts CHANGED
@@ -11,7 +11,6 @@ interface Root {
11
11
  unmount(): void;
12
12
  }
13
13
 
14
- // Check if we're running React 18
15
14
  const isReact18 = ReactDOM.version.startsWith('18');
16
15
 
17
16
  /**
@@ -27,9 +26,10 @@ export function createRoot(
27
26
  return (ReactDOM as any).createRoot(container, options);
28
27
  }
29
28
 
30
- // For React 16, simulate the new root API using render/unmountComponentAtNode
29
+ // For React 16/17, simulate the new root API using render/unmountComponentAtNode
31
30
  return {
32
31
  render(children: React.ReactNode) {
32
+ // @ts-ignore - React 17's render method is deprecated but still functional
33
33
  ReactDOM.render(children, container);
34
34
  },
35
35
  unmount() {
@@ -52,9 +52,10 @@ export function hydrateRoot(
52
52
  return (ReactDOM as any).hydrateRoot(container, initialChildren, options);
53
53
  }
54
54
 
55
- // For React 16, simulate the new root API using hydrate
55
+ // For React 16/17, simulate the new root API using hydrate
56
56
  return {
57
57
  render(children: React.ReactNode) {
58
+ // @ts-ignore - React 17's hydrate method is deprecated but still functional
58
59
  ReactDOM.hydrate(children, container);
59
60
  },
60
61
  unmount() {
package/src/provider.tsx CHANGED
@@ -86,14 +86,9 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
86
86
  bridgeInfo?.render(rootComponentWithErrorBoundary, dom),
87
87
  ).then((root: RootType) => rootMap.set(info.dom, root));
88
88
  } else {
89
- // Dynamically import react-dom/client
90
- import('react-dom/client').then(
91
- (ReactDOMClient: typeof import('react-dom/client')) => {
92
- const root = ReactDOMClient.createRoot(info.dom);
93
- root.render(rootComponentWithErrorBoundary);
94
- rootMap.set(info.dom, root);
95
- },
96
- );
89
+ const root = createRoot(info.dom);
90
+ root.render(rootComponentWithErrorBoundary);
91
+ rootMap.set(info.dom, root);
97
92
  }
98
93
 
99
94
  instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};