@module-federation/bridge-react 0.0.0-next-20240620034636 → 0.0.0-next-20240620052430
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 +2 -2
- package/dist/index.cjs.js +0 -7
- package/dist/index.es.js +1 -8
- package/package.json +2 -2
- package/src/create.tsx +39 -21
package/CHANGELOG.md
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -96,13 +96,6 @@ function createRemoteComponent(lazyComponent, info) {
|
|
|
96
96
|
} catch {
|
|
97
97
|
enableDispathPopstate = false;
|
|
98
98
|
}
|
|
99
|
-
if (ReactRouterDOM__namespace.UNSAFE_RouteContext && enableDispathPopstate) {
|
|
100
|
-
routerContextVal = React.useContext(ReactRouterDOM__namespace.UNSAFE_RouteContext);
|
|
101
|
-
if (routerContextVal && routerContextVal.matches && routerContextVal.matches[0] && routerContextVal.matches[0].pathnameBase) {
|
|
102
|
-
basename = routerContextVal.matches[0].pathnameBase;
|
|
103
|
-
}
|
|
104
|
-
enableDispathPopstate = (routerContextVal == null ? void 0 : routerContextVal.matches) && (routerContextVal == null ? void 0 : routerContextVal.matches.length) > 0;
|
|
105
|
-
}
|
|
106
99
|
const LazyComponent = React.useMemo(() => {
|
|
107
100
|
return React.lazy(async () => {
|
|
108
101
|
context.LoggerInstance.log(`createRemoteComponent LazyComponent create >>>`, {
|
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import React__default, {
|
|
2
|
+
import React__default, { useMemo, useRef, useState, useEffect } from "react";
|
|
3
3
|
import * as ReactRouterDOM from "react-router-dom";
|
|
4
4
|
import { L as LoggerInstance, f, a as atLeastReact18, R as RouterContext } from "./context-CPtN38Ur.js";
|
|
5
5
|
import ReactDOM from "react-dom";
|
|
@@ -77,13 +77,6 @@ function createRemoteComponent(lazyComponent, info) {
|
|
|
77
77
|
} catch {
|
|
78
78
|
enableDispathPopstate = false;
|
|
79
79
|
}
|
|
80
|
-
if (ReactRouterDOM.UNSAFE_RouteContext && enableDispathPopstate) {
|
|
81
|
-
routerContextVal = useContext(ReactRouterDOM.UNSAFE_RouteContext);
|
|
82
|
-
if (routerContextVal && routerContextVal.matches && routerContextVal.matches[0] && routerContextVal.matches[0].pathnameBase) {
|
|
83
|
-
basename = routerContextVal.matches[0].pathnameBase;
|
|
84
|
-
}
|
|
85
|
-
enableDispathPopstate = (routerContextVal == null ? void 0 : routerContextVal.matches) && (routerContextVal == null ? void 0 : routerContextVal.matches.length) > 0;
|
|
86
|
-
}
|
|
87
80
|
const LazyComponent = useMemo(() => {
|
|
88
81
|
return React__default.lazy(async () => {
|
|
89
82
|
LoggerInstance.log(`createRemoteComponent LazyComponent create >>>`, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/bridge-react",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240620052430",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@loadable/component": "^5.16.4",
|
|
27
27
|
"react-error-boundary": "^4.0.13",
|
|
28
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
28
|
+
"@module-federation/bridge-shared": "0.0.0-next-20240620052430"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"react": ">=16.9.0",
|
package/src/create.tsx
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
ReactNode,
|
|
3
|
-
useContext,
|
|
4
|
-
useEffect,
|
|
5
|
-
useMemo,
|
|
6
|
-
useRef,
|
|
7
|
-
useState,
|
|
8
|
-
} from 'react';
|
|
1
|
+
import React, { ReactNode, useEffect, useMemo, useRef, useState } from 'react';
|
|
9
2
|
import * as ReactRouterDOM from 'react-router-dom';
|
|
10
3
|
import type { ProviderParams } from '@module-federation/bridge-shared';
|
|
11
4
|
import { LoggerInstance } from './utils';
|
|
@@ -135,19 +128,44 @@ export function createRemoteComponent<T, E extends keyof T>(
|
|
|
135
128
|
enableDispathPopstate = false;
|
|
136
129
|
}
|
|
137
130
|
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
131
|
+
// if (props.basename) {
|
|
132
|
+
// basename = props.basename
|
|
133
|
+
// } else if (enableDispathPopstate) {
|
|
134
|
+
// const routerV5Api = 'useRoute' + 'Match';
|
|
135
|
+
// const routerV6Api = 'useMatches';
|
|
136
|
+
// const routerV5History = 'use' + 'History';
|
|
137
|
+
// const useHref = 'useHref';
|
|
138
|
+
|
|
139
|
+
// const match = (ReactRouterDOM as any)[routerV5Api]?.();
|
|
140
|
+
// const matchs = (ReactRouterDOM as any)[routerV6Api]?.();
|
|
141
|
+
// const location = ReactRouterDOM.useLocation();
|
|
142
|
+
|
|
143
|
+
// if ((ReactRouterDOM as any)[routerV5History] /* react-router@5 */) {
|
|
144
|
+
// // there is no dynamic switching of the router version in the project
|
|
145
|
+
// // so hooks can be used in conditional judgment
|
|
146
|
+
// // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
147
|
+
// const history = (ReactRouterDOM as any)[routerV5History]?.();
|
|
148
|
+
// // To be compatible to history@4.10.1 and @5.3.0 we cannot write like this `history.createHref(pathname)`
|
|
149
|
+
// basename = history?.createHref?.({ pathname: '/' });
|
|
150
|
+
// } else if (useHref /* react-router@6 */) {
|
|
151
|
+
// // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
152
|
+
// basename = useHref?.('/');
|
|
153
|
+
// }
|
|
154
|
+
// }
|
|
155
|
+
|
|
156
|
+
// if (ReactRouterDOM.UNSAFE_RouteContext && enableDispathPopstate) {
|
|
157
|
+
// routerContextVal = eval('useContext(ReactRouterDOM.UNSAFE_RouteContext)');
|
|
158
|
+
// if (
|
|
159
|
+
// routerContextVal &&
|
|
160
|
+
// routerContextVal.matches &&
|
|
161
|
+
// routerContextVal.matches[0] &&
|
|
162
|
+
// routerContextVal.matches[0].pathnameBase
|
|
163
|
+
// ) {
|
|
164
|
+
// basename = routerContextVal.matches[0].pathnameBase;
|
|
165
|
+
// }
|
|
166
|
+
// enableDispathPopstate =
|
|
167
|
+
// routerContextVal?.matches && routerContextVal?.matches.length > 0;
|
|
168
|
+
// }
|
|
151
169
|
|
|
152
170
|
const LazyComponent = useMemo(() => {
|
|
153
171
|
//@ts-ignore
|