@module-federation/bridge-react 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
+ ## 0.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 88a018d: feat(react-bridge): Add native support for React 19 in bridge-react with enhanced createRoot options
8
+
9
+ ### Patch Changes
10
+
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.13.0
17
+ - @module-federation/sdk@0.13.0
18
+
3
19
  ## 0.12.0
4
20
 
5
21
  ### Patch Changes
@@ -0,0 +1,199 @@
1
+ import * as React from "react";
2
+ import { Component, createElement, createContext } from "react";
3
+ import { L as LoggerInstance, R as RouterContext } from "./index-BlBMQSoq.js";
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
+ }
100
+ function createBaseBridgeComponent({
101
+ createRoot,
102
+ defaultRootOptions,
103
+ ...bridgeInfo
104
+ }) {
105
+ return () => {
106
+ const rootMap = /* @__PURE__ */ new Map();
107
+ const instance = federationRuntime.instance;
108
+ LoggerInstance.debug(
109
+ `createBridgeComponent instance from props >>>`,
110
+ instance
111
+ );
112
+ const RawComponent = (info) => {
113
+ const { appInfo, propsInfo, ...restProps } = info;
114
+ const { moduleName, memoryRoute, basename = "/" } = appInfo;
115
+ return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { moduleName, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(
116
+ bridgeInfo.rootComponent,
117
+ {
118
+ ...propsInfo,
119
+ basename,
120
+ ...restProps
121
+ }
122
+ ));
123
+ };
124
+ return {
125
+ async render(info) {
126
+ var _a, _b, _c, _d, _e, _f;
127
+ LoggerInstance.debug(`createBridgeComponent render Info`, info);
128
+ const {
129
+ moduleName,
130
+ dom,
131
+ basename,
132
+ memoryRoute,
133
+ fallback,
134
+ rootOptions,
135
+ ...propsInfo
136
+ } = info;
137
+ const mergedRootOptions = {
138
+ ...defaultRootOptions,
139
+ ...rootOptions
140
+ };
141
+ const beforeBridgeRenderRes = ((_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(info)) || {};
142
+ const rootComponentWithErrorBoundary = /* @__PURE__ */ React.createElement(
143
+ ErrorBoundary,
144
+ {
145
+ FallbackComponent: fallback
146
+ },
147
+ /* @__PURE__ */ React.createElement(
148
+ RawComponent,
149
+ {
150
+ appInfo: {
151
+ moduleName,
152
+ basename,
153
+ memoryRoute
154
+ },
155
+ propsInfo: {
156
+ ...propsInfo,
157
+ ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
158
+ }
159
+ }
160
+ )
161
+ );
162
+ if (bridgeInfo.render) {
163
+ await Promise.resolve(
164
+ bridgeInfo.render(rootComponentWithErrorBoundary, dom)
165
+ ).then((root) => rootMap.set(dom, root));
166
+ } else {
167
+ let root = rootMap.get(dom);
168
+ if (!root && createRoot) {
169
+ root = createRoot(dom, mergedRootOptions);
170
+ rootMap.set(dom, root);
171
+ }
172
+ if (root && "render" in root) {
173
+ root.render(rootComponentWithErrorBoundary);
174
+ }
175
+ }
176
+ ((_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)) || {};
177
+ },
178
+ destroy(info) {
179
+ var _a, _b, _c;
180
+ const { dom } = info;
181
+ LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
182
+ const root = rootMap.get(dom);
183
+ if (root) {
184
+ if ("unmount" in root) {
185
+ root.unmount();
186
+ } else {
187
+ console.warn("Root does not have unmount method");
188
+ }
189
+ rootMap.delete(dom);
190
+ }
191
+ (_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);
192
+ }
193
+ };
194
+ };
195
+ }
196
+ export {
197
+ ErrorBoundary as E,
198
+ createBaseBridgeComponent as c
199
+ };
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ const React = require("react");
3
+ const index = require("./index-BYDWxFmi.cjs");
4
+ const plugin = require("./plugin.cjs.js");
5
+ function _interopNamespaceDefault(e) {
6
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
7
+ if (e) {
8
+ for (const k in e) {
9
+ if (k !== "default") {
10
+ const d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: () => e[k]
14
+ });
15
+ }
16
+ }
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
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
+ }
117
+ function createBaseBridgeComponent({
118
+ createRoot,
119
+ defaultRootOptions,
120
+ ...bridgeInfo
121
+ }) {
122
+ return () => {
123
+ const rootMap = /* @__PURE__ */ new Map();
124
+ const instance = plugin.federationRuntime.instance;
125
+ index.LoggerInstance.debug(
126
+ `createBridgeComponent instance from props >>>`,
127
+ instance
128
+ );
129
+ const RawComponent = (info) => {
130
+ const { appInfo, propsInfo, ...restProps } = info;
131
+ const { moduleName, memoryRoute, basename = "/" } = appInfo;
132
+ return /* @__PURE__ */ React__namespace.createElement(index.RouterContext.Provider, { value: { moduleName, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(
133
+ bridgeInfo.rootComponent,
134
+ {
135
+ ...propsInfo,
136
+ basename,
137
+ ...restProps
138
+ }
139
+ ));
140
+ };
141
+ return {
142
+ async render(info) {
143
+ var _a, _b, _c, _d, _e, _f;
144
+ index.LoggerInstance.debug(`createBridgeComponent render Info`, info);
145
+ const {
146
+ moduleName,
147
+ dom,
148
+ basename,
149
+ memoryRoute,
150
+ fallback,
151
+ rootOptions,
152
+ ...propsInfo
153
+ } = info;
154
+ const mergedRootOptions = {
155
+ ...defaultRootOptions,
156
+ ...rootOptions
157
+ };
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)) || {};
159
+ const rootComponentWithErrorBoundary = /* @__PURE__ */ React__namespace.createElement(
160
+ ErrorBoundary,
161
+ {
162
+ FallbackComponent: fallback
163
+ },
164
+ /* @__PURE__ */ React__namespace.createElement(
165
+ RawComponent,
166
+ {
167
+ appInfo: {
168
+ moduleName,
169
+ basename,
170
+ memoryRoute
171
+ },
172
+ propsInfo: {
173
+ ...propsInfo,
174
+ ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps
175
+ }
176
+ }
177
+ )
178
+ );
179
+ if (bridgeInfo.render) {
180
+ await Promise.resolve(
181
+ bridgeInfo.render(rootComponentWithErrorBoundary, dom)
182
+ ).then((root) => rootMap.set(dom, root));
183
+ } else {
184
+ let root = rootMap.get(dom);
185
+ if (!root && createRoot) {
186
+ root = createRoot(dom, mergedRootOptions);
187
+ rootMap.set(dom, root);
188
+ }
189
+ if (root && "render" in root) {
190
+ root.render(rootComponentWithErrorBoundary);
191
+ }
192
+ }
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(info)) || {};
194
+ },
195
+ destroy(info) {
196
+ var _a, _b, _c;
197
+ const { dom } = info;
198
+ index.LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
199
+ const root = rootMap.get(dom);
200
+ if (root) {
201
+ if ("unmount" in root) {
202
+ root.unmount();
203
+ } else {
204
+ console.warn("Root does not have unmount method");
205
+ }
206
+ rootMap.delete(dom);
207
+ }
208
+ (_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);
209
+ }
210
+ };
211
+ };
212
+ }
213
+ exports.ErrorBoundary = ErrorBoundary;
214
+ exports.createBaseBridgeComponent = createBaseBridgeComponent;