@module-federation/bridge-react 0.0.0-next-20250708033956 → 0.0.0-next-20250708104625
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 +3 -3
- package/dist/data-fetch-server-middleware.d.ts +9 -0
- package/dist/data-fetch-server-middleware.es.js +1 -1
- package/dist/data-fetch-utils.cjs.js +4 -1253
- package/dist/data-fetch-utils.d.ts +10 -1
- package/dist/data-fetch-utils.es.js +11 -1260
- package/dist/index.cjs.js +7 -433
- package/dist/index.d.ts +11 -11
- package/dist/index.es.js +20 -447
- package/dist/lazy-load-component-plugin-CttAWi8N.js +500 -0
- package/dist/lazy-load-component-plugin-hOC-Yus_.mjs +501 -0
- package/dist/lazy-load-component-plugin.cjs.js +6 -0
- package/dist/lazy-load-component-plugin.d.ts +16 -0
- package/dist/lazy-load-component-plugin.es.js +6 -0
- package/dist/lazy-utils.d.ts +9 -0
- package/dist/lazy-utils.es.js +19 -19
- package/dist/plugin.d.ts +9 -0
- package/dist/prefetch-Cx6MrkdU.mjs +1330 -0
- package/dist/prefetch-cGDaDkgV.js +1329 -0
- package/dist/router-v5.d.ts +9 -0
- package/dist/router-v6.d.ts +9 -0
- package/dist/router.d.ts +9 -0
- package/dist/{utils-Bk8hGjjF.mjs → utils-BTYYwZcb.mjs} +31 -31
- package/dist/v18.d.ts +9 -0
- package/dist/v19.d.ts +9 -0
- package/package.json +11 -11
- package/src/index.ts +3 -1
- package/src/lazy/createLazyComponent.tsx +88 -74
- package/src/lazy/data-fetch/index.ts +1 -0
- package/src/lazy/data-fetch/prefetch.ts +1 -1
- package/src/lazy/data-fetch/runtime-plugin.ts +80 -81
- package/src/lazy/index.ts +6 -2
- package/src/plugins/lazy-load-component-plugin.ts +72 -0
- package/vite.config.ts +2 -2
- package/dist/data-fetch-runtime-plugin.cjs.js +0 -73
- package/dist/data-fetch-runtime-plugin.d.ts +0 -6
- package/dist/data-fetch-runtime-plugin.es.js +0 -74
- package/dist/inject-data-fetch-CAvi-gSf.js +0 -79
- package/dist/inject-data-fetch-errCdqBS.mjs +0 -80
- package/src/.eslintrc.js +0 -9
package/dist/router-v5.d.ts
CHANGED
|
@@ -7,3 +7,12 @@ export declare function BrowserRouter(props: Parameters<typeof ReactRouterDom.Br
|
|
|
7
7
|
export * from "react-router-dom/";
|
|
8
8
|
|
|
9
9
|
export { }
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
declare module '@module-federation/runtime' {
|
|
13
|
+
interface FederationHost {
|
|
14
|
+
createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
|
|
15
|
+
prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
|
|
16
|
+
collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/dist/router-v6.d.ts
CHANGED
|
@@ -9,3 +9,12 @@ export declare function RouterProvider(props: Parameters<typeof ReactRouterDom.R
|
|
|
9
9
|
export * from "react-router-dom/";
|
|
10
10
|
|
|
11
11
|
export { }
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
declare module '@module-federation/runtime' {
|
|
15
|
+
interface FederationHost {
|
|
16
|
+
createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
|
|
17
|
+
prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
|
|
18
|
+
collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/dist/router.d.ts
CHANGED
|
@@ -9,3 +9,12 @@ export declare function RouterProvider(props: Parameters<typeof ReactRouterDom.R
|
|
|
9
9
|
export * from "react-router-dom/";
|
|
10
10
|
|
|
11
11
|
export { }
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
declare module '@module-federation/runtime' {
|
|
15
|
+
interface FederationHost {
|
|
16
|
+
createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
|
|
17
|
+
prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
|
|
18
|
+
collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1975,42 +1975,42 @@ function getLoadedRemoteInfos(id, instance) {
|
|
|
1975
1975
|
};
|
|
1976
1976
|
}
|
|
1977
1977
|
export {
|
|
1978
|
-
|
|
1979
|
-
|
|
1978
|
+
DOWNGRADE_KEY as A,
|
|
1979
|
+
getDowngradeTag as B,
|
|
1980
1980
|
CacheSize as C,
|
|
1981
|
-
|
|
1981
|
+
DATA_FETCH_QUERY as D,
|
|
1982
1982
|
ERROR_TYPE as E,
|
|
1983
1983
|
FS_HREF as F,
|
|
1984
|
-
|
|
1985
|
-
|
|
1984
|
+
callAllDowngrade as G,
|
|
1985
|
+
callDowngrade as H,
|
|
1986
1986
|
getDataFetchCache as I,
|
|
1987
1987
|
flushDataFetch as J,
|
|
1988
1988
|
LOAD_REMOTE_ERROR_PREFIX as L,
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
1989
|
+
MF_DATA_FETCH_STATUS as M,
|
|
1990
|
+
loadDataFetchModule as a,
|
|
1991
|
+
CacheTime as b,
|
|
1992
|
+
configureCache as c,
|
|
1993
|
+
generateKey as d,
|
|
1994
|
+
cache as e,
|
|
1995
|
+
fetchData as f,
|
|
1996
|
+
getDataFetchMap as g,
|
|
1997
|
+
clearStore as h,
|
|
1998
|
+
initDataFetchMap as i,
|
|
1999
|
+
isDataLoaderExpose as j,
|
|
2000
|
+
getDataFetchInfo as k,
|
|
2001
2001
|
logger as l,
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2002
|
+
getDataFetchMapKey as m,
|
|
2003
|
+
getDataFetchItem as n,
|
|
2004
|
+
DATA_FETCH_CLIENT_SUFFIX as o,
|
|
2005
|
+
MF_DATA_FETCH_TYPE as p,
|
|
2006
|
+
isServerEnv as q,
|
|
2007
|
+
revalidateTag as r,
|
|
2008
|
+
setSSREnv as s,
|
|
2009
|
+
isCSROnly as t,
|
|
2010
|
+
DATA_FETCH_FUNCTION as u,
|
|
2011
|
+
getDataFetchIdWithErrorMsgs as v,
|
|
2012
|
+
DATA_FETCH_ERROR_PREFIX as w,
|
|
2013
|
+
wrapDataFetchId as x,
|
|
2014
|
+
getLoadedRemoteInfos as y,
|
|
2015
|
+
setDataFetchItemLoadedStatus as z
|
|
2016
2016
|
};
|
package/dist/v18.d.ts
CHANGED
|
@@ -103,3 +103,12 @@ declare interface Root_2 {
|
|
|
103
103
|
export declare type RootType = HTMLElement | Root_2;
|
|
104
104
|
|
|
105
105
|
export { }
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
declare module '@module-federation/runtime' {
|
|
109
|
+
interface FederationHost {
|
|
110
|
+
createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
|
|
111
|
+
prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
|
|
112
|
+
collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
|
|
113
|
+
}
|
|
114
|
+
}
|
package/dist/v19.d.ts
CHANGED
|
@@ -104,3 +104,12 @@ declare interface Root_2 {
|
|
|
104
104
|
export declare type RootType = HTMLElement | Root_2;
|
|
105
105
|
|
|
106
106
|
export { }
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
declare module '@module-federation/runtime' {
|
|
110
|
+
interface FederationHost {
|
|
111
|
+
createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
|
|
112
|
+
prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
|
|
113
|
+
collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
|
|
114
|
+
}
|
|
115
|
+
}
|
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-20250708104625",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -50,11 +50,6 @@
|
|
|
50
50
|
"import": "./dist/router-v6.es.js",
|
|
51
51
|
"require": "./dist/router-v6.cjs.js"
|
|
52
52
|
},
|
|
53
|
-
"./data-fetch-runtime-plugin": {
|
|
54
|
-
"types": "./dist/data-fetch-runtime-plugin.d.ts",
|
|
55
|
-
"import": "./dist/data-fetch-runtime-plugin.es.js",
|
|
56
|
-
"require": "./dist/data-fetch-runtime-plugin.cjs.js"
|
|
57
|
-
},
|
|
58
53
|
"./lazy-utils": {
|
|
59
54
|
"types": "./dist/lazy-utils.d.ts",
|
|
60
55
|
"import": "./dist/lazy-utils.es.js",
|
|
@@ -70,6 +65,11 @@
|
|
|
70
65
|
"import": "./dist/data-fetch-server-middleware.es.js",
|
|
71
66
|
"require": "./dist/data-fetch-server-middleware.cjs.js"
|
|
72
67
|
},
|
|
68
|
+
"./lazy-load-component-plugin": {
|
|
69
|
+
"types": "./dist/lazy-load-component-plugin.d.ts",
|
|
70
|
+
"import": "./dist/lazy-load-component-plugin.es.js",
|
|
71
|
+
"require": "./dist/lazy-load-component-plugin.cjs.js"
|
|
72
|
+
},
|
|
73
73
|
"./*": "./*"
|
|
74
74
|
},
|
|
75
75
|
"typesVersions": {
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
".": [
|
|
78
78
|
"./dist/types/index.d.ts"
|
|
79
79
|
],
|
|
80
|
-
"
|
|
81
|
-
"./dist/lazy-
|
|
80
|
+
"lazy-load-component-plugin": [
|
|
81
|
+
"./dist/lazy-load-component-plugin.d.ts"
|
|
82
82
|
],
|
|
83
83
|
"lazy-utils": [
|
|
84
84
|
"./dist/lazy-utils.d.ts"
|
|
@@ -94,8 +94,8 @@
|
|
|
94
94
|
"dependencies": {
|
|
95
95
|
"react-error-boundary": "^4.1.2",
|
|
96
96
|
"lru-cache": "^10.4.3",
|
|
97
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
98
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
97
|
+
"@module-federation/bridge-shared": "0.0.0-next-20250708104625",
|
|
98
|
+
"@module-federation/sdk": "0.0.0-next-20250708104625"
|
|
99
99
|
},
|
|
100
100
|
"peerDependencies": {
|
|
101
101
|
"react": ">=16.9.0",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"vite": "^5.4.18",
|
|
118
118
|
"vite-plugin-dts": "^4.3.0",
|
|
119
119
|
"hono": "3.12.12",
|
|
120
|
-
"@module-federation/runtime": "0.0.0-next-
|
|
120
|
+
"@module-federation/runtime": "0.0.0-next-20250708104625"
|
|
121
121
|
},
|
|
122
122
|
"scripts": {
|
|
123
123
|
"dev": "vite",
|
package/src/index.ts
CHANGED
|
@@ -11,7 +11,7 @@ export {
|
|
|
11
11
|
ERROR_TYPE,
|
|
12
12
|
createLazyComponent,
|
|
13
13
|
collectSSRAssets,
|
|
14
|
-
wrapNoSSR,
|
|
14
|
+
// wrapNoSSR,
|
|
15
15
|
callDataFetch,
|
|
16
16
|
setSSREnv,
|
|
17
17
|
autoFetchDataPlugin,
|
|
@@ -25,6 +25,8 @@ export {
|
|
|
25
25
|
prefetch,
|
|
26
26
|
} from './lazy';
|
|
27
27
|
|
|
28
|
+
export { lazyLoadComponentPlugin } from './plugins/lazy-load-component-plugin';
|
|
29
|
+
|
|
28
30
|
export type { CreateRootOptions, Root } from './provider/versions/legacy';
|
|
29
31
|
export type {
|
|
30
32
|
ProviderParams,
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import type { FederationHost, getInstance } from '@module-federation/runtime';
|
|
2
|
+
import type { BasicProviderModuleInfo } from '@module-federation/sdk';
|
|
1
3
|
import React, { ReactNode, useState, useEffect } from 'react';
|
|
4
|
+
import type { ErrorInfo } from './AwaitDataFetch';
|
|
5
|
+
import type { DataFetchParams, NoSSRRemoteInfo } from './types';
|
|
6
|
+
|
|
2
7
|
import logger from './logger';
|
|
3
8
|
import {
|
|
4
9
|
AwaitDataFetch,
|
|
@@ -13,7 +18,6 @@ import {
|
|
|
13
18
|
getLoadedRemoteInfos,
|
|
14
19
|
setDataFetchItemLoadedStatus,
|
|
15
20
|
wrapDataFetchId,
|
|
16
|
-
isServerEnv,
|
|
17
21
|
} from './utils';
|
|
18
22
|
import {
|
|
19
23
|
DATA_FETCH_ERROR_PREFIX,
|
|
@@ -23,10 +27,6 @@ import {
|
|
|
23
27
|
MF_DATA_FETCH_TYPE,
|
|
24
28
|
} from './constant';
|
|
25
29
|
|
|
26
|
-
import type { ErrorInfo } from './AwaitDataFetch';
|
|
27
|
-
import type { DataFetchParams, NoSSRRemoteInfo } from './types';
|
|
28
|
-
import type { FederationHost, getInstance } from '@module-federation/runtime';
|
|
29
|
-
|
|
30
30
|
export type IProps = {
|
|
31
31
|
id: string;
|
|
32
32
|
instance: ReturnType<typeof getInstance>;
|
|
@@ -42,13 +42,22 @@ export type CreateLazyComponentOptions<T, E extends keyof T> = {
|
|
|
42
42
|
fallback: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
|
|
43
43
|
export?: E;
|
|
44
44
|
dataFetchParams?: DataFetchParams;
|
|
45
|
-
noSSR?: boolean;
|
|
45
|
+
// noSSR?: boolean;
|
|
46
46
|
cacheData?: boolean;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
type ReactKey = { key?: React.Key | null };
|
|
50
50
|
|
|
51
|
-
function getTargetModuleInfo(
|
|
51
|
+
function getTargetModuleInfo(
|
|
52
|
+
id: string,
|
|
53
|
+
instance?: FederationHost,
|
|
54
|
+
):
|
|
55
|
+
| {
|
|
56
|
+
module: BasicProviderModuleInfo['modules'][0];
|
|
57
|
+
publicPath: string;
|
|
58
|
+
remoteEntry: string;
|
|
59
|
+
}
|
|
60
|
+
| undefined {
|
|
52
61
|
if (!instance) {
|
|
53
62
|
return;
|
|
54
63
|
}
|
|
@@ -56,11 +65,11 @@ function getTargetModuleInfo(id: string, instance?: FederationHost) {
|
|
|
56
65
|
if (!loadedRemoteInfo) {
|
|
57
66
|
return;
|
|
58
67
|
}
|
|
59
|
-
const snapshot = loadedRemoteInfo
|
|
68
|
+
const { snapshot } = loadedRemoteInfo;
|
|
60
69
|
if (!snapshot) {
|
|
61
70
|
return;
|
|
62
71
|
}
|
|
63
|
-
const publicPath =
|
|
72
|
+
const publicPath: string =
|
|
64
73
|
'publicPath' in snapshot
|
|
65
74
|
? snapshot.publicPath
|
|
66
75
|
: 'getPublicPath' in snapshot
|
|
@@ -148,11 +157,12 @@ export function collectSSRAssets(options: IProps) {
|
|
|
148
157
|
function getServerNeedRemoteInfo(
|
|
149
158
|
loadedRemoteInfo: ReturnType<typeof getLoadedRemoteInfos>,
|
|
150
159
|
id: string,
|
|
151
|
-
noSSR?: boolean,
|
|
160
|
+
// noSSR?: boolean,
|
|
152
161
|
): NoSSRRemoteInfo | undefined {
|
|
153
162
|
if (
|
|
154
|
-
noSSR ||
|
|
155
|
-
|
|
163
|
+
// noSSR ||
|
|
164
|
+
typeof window !== 'undefined' &&
|
|
165
|
+
window.location.href !== window[FS_HREF]
|
|
156
166
|
) {
|
|
157
167
|
if (!loadedRemoteInfo?.version) {
|
|
158
168
|
throw new Error(`${loadedRemoteInfo?.name} version is empty`);
|
|
@@ -223,7 +233,8 @@ export function createLazyComponent<T, E extends keyof T>(
|
|
|
223
233
|
return m;
|
|
224
234
|
};
|
|
225
235
|
|
|
226
|
-
const getData = async (noSSR?: boolean) => {
|
|
236
|
+
// const getData = async (noSSR?: boolean) => {
|
|
237
|
+
const getData = async () => {
|
|
227
238
|
let loadedRemoteInfo: ReturnType<typeof getLoadedRemoteInfos>;
|
|
228
239
|
let moduleId: string;
|
|
229
240
|
try {
|
|
@@ -262,7 +273,8 @@ export function createLazyComponent<T, E extends keyof T>(
|
|
|
262
273
|
...options.dataFetchParams,
|
|
263
274
|
isDowngrade: false,
|
|
264
275
|
},
|
|
265
|
-
getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey, noSSR),
|
|
276
|
+
// getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey, noSSR),
|
|
277
|
+
getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey),
|
|
266
278
|
);
|
|
267
279
|
setDataFetchItemLoadedStatus(dataFetchMapKey);
|
|
268
280
|
logger.debug('get data res: \n', data);
|
|
@@ -335,70 +347,72 @@ export function createLazyComponent<T, E extends keyof T>(
|
|
|
335
347
|
// @ts-expect-error ignore
|
|
336
348
|
return <LazyComponent {...args} mfData={dataCache} />;
|
|
337
349
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
// Client-side rendering logic
|
|
352
|
-
const [data, setData] = useState<unknown>(null);
|
|
353
|
-
const [loading, setLoading] = useState<boolean>(true);
|
|
354
|
-
const [error, setError] = useState<ErrorInfo | null>(null);
|
|
350
|
+
return (
|
|
351
|
+
<AwaitDataFetch
|
|
352
|
+
// resolve={getData(options.noSSR)}
|
|
353
|
+
resolve={getData()}
|
|
354
|
+
loading={options.loading}
|
|
355
|
+
delayLoading={options.delayLoading}
|
|
356
|
+
errorElement={options.fallback}
|
|
357
|
+
>
|
|
358
|
+
{/* @ts-expect-error ignore */}
|
|
359
|
+
{(data) => <LazyComponent {...args} mfData={data} />}
|
|
360
|
+
</AwaitDataFetch>
|
|
361
|
+
);
|
|
362
|
+
// if (!options.noSSR) {
|
|
355
363
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
const result = await getData(options.noSSR);
|
|
362
|
-
if (isMounted) {
|
|
363
|
-
setData(result);
|
|
364
|
-
}
|
|
365
|
-
} catch (e) {
|
|
366
|
-
if (isMounted) {
|
|
367
|
-
setError(transformError(e as Error));
|
|
368
|
-
}
|
|
369
|
-
} finally {
|
|
370
|
-
if (isMounted) {
|
|
371
|
-
setLoading(false);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
};
|
|
364
|
+
// } else {
|
|
365
|
+
// // Client-side rendering logic
|
|
366
|
+
// const [data, setData] = useState<unknown>(null);
|
|
367
|
+
// const [loading, setLoading] = useState<boolean>(true);
|
|
368
|
+
// const [error, setError] = useState<ErrorInfo | null>(null);
|
|
375
369
|
|
|
376
|
-
|
|
370
|
+
// useEffect(() => {
|
|
371
|
+
// let isMounted = true;
|
|
372
|
+
// const fetchDataAsync = async () => {
|
|
373
|
+
// try {
|
|
374
|
+
// setLoading(true);
|
|
375
|
+
// const result = await getData(options.noSSR);
|
|
376
|
+
// if (isMounted) {
|
|
377
|
+
// setData(result);
|
|
378
|
+
// }
|
|
379
|
+
// } catch (e) {
|
|
380
|
+
// if (isMounted) {
|
|
381
|
+
// setError(transformError(e as Error));
|
|
382
|
+
// }
|
|
383
|
+
// } finally {
|
|
384
|
+
// if (isMounted) {
|
|
385
|
+
// setLoading(false);
|
|
386
|
+
// }
|
|
387
|
+
// }
|
|
388
|
+
// };
|
|
377
389
|
|
|
378
|
-
|
|
379
|
-
isMounted = false;
|
|
380
|
-
};
|
|
381
|
-
}, []);
|
|
390
|
+
// fetchDataAsync();
|
|
382
391
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
</DelayedLoading>
|
|
388
|
-
);
|
|
389
|
-
}
|
|
392
|
+
// return () => {
|
|
393
|
+
// isMounted = false;
|
|
394
|
+
// };
|
|
395
|
+
// }, []);
|
|
390
396
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
397
|
+
// if (loading) {
|
|
398
|
+
// return (
|
|
399
|
+
// <DelayedLoading delayLoading={options.delayLoading}>
|
|
400
|
+
// {options.loading}
|
|
401
|
+
// </DelayedLoading>
|
|
402
|
+
// );
|
|
403
|
+
// }
|
|
404
|
+
|
|
405
|
+
// if (error) {
|
|
406
|
+
// return (
|
|
407
|
+
// <>
|
|
408
|
+
// {typeof options.fallback === 'function'
|
|
409
|
+
// ? options.fallback(error)
|
|
410
|
+
// : options.fallback}
|
|
411
|
+
// </>
|
|
412
|
+
// );
|
|
413
|
+
// }
|
|
414
|
+
// // @ts-expect-error ignore
|
|
415
|
+
// return <LazyComponent {...args} mfData={data} />;
|
|
416
|
+
// }
|
|
403
417
|
};
|
|
404
418
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import helpers from '@module-federation/runtime/helpers';
|
|
8
8
|
import { DataFetchParams } from '../types';
|
|
9
9
|
|
|
10
|
-
type PrefetchOptions = {
|
|
10
|
+
export type PrefetchOptions = {
|
|
11
11
|
id: string;
|
|
12
12
|
instance: ReturnType<typeof getInstance>;
|
|
13
13
|
dataFetchParams?: DataFetchParams;
|
|
@@ -20,97 +20,96 @@ import {
|
|
|
20
20
|
import type { MF_DATA_FETCH_MAP_VALUE } from '../types';
|
|
21
21
|
import type { FederationRuntimePlugin } from '@module-federation/runtime';
|
|
22
22
|
|
|
23
|
-
const autoFetchData: () => FederationRuntimePlugin = () =>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return args;
|
|
37
|
-
}
|
|
23
|
+
const autoFetchData: () => FederationRuntimePlugin = () => {
|
|
24
|
+
initDataFetchMap();
|
|
25
|
+
injectDataFetch();
|
|
26
|
+
return {
|
|
27
|
+
name: 'auto-fetch-data-plugin',
|
|
28
|
+
afterLoadSnapshot(args) {
|
|
29
|
+
const { id, moduleInfo, remoteSnapshot, host } = args;
|
|
30
|
+
if (typeof id === 'string' && isDataLoaderExpose(id)) {
|
|
31
|
+
return args;
|
|
32
|
+
}
|
|
33
|
+
if (!remoteSnapshot || !id || !('modules' in remoteSnapshot)) {
|
|
34
|
+
return args;
|
|
35
|
+
}
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
const { name, alias } = moduleInfo;
|
|
38
|
+
const dataFetchInfo = getDataFetchInfo({
|
|
39
|
+
name,
|
|
40
|
+
alias,
|
|
41
|
+
id,
|
|
42
|
+
remoteSnapshot,
|
|
43
|
+
});
|
|
44
|
+
if (!dataFetchInfo) {
|
|
45
|
+
return args;
|
|
46
|
+
}
|
|
47
|
+
const { dataFetchId, dataFetchName } = dataFetchInfo;
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
const dataFetchMapKey = getDataFetchMapKey(dataFetchInfo, {
|
|
50
|
+
name: host.name,
|
|
51
|
+
version: host.options.version,
|
|
52
|
+
});
|
|
53
|
+
logger.debug(
|
|
54
|
+
'======= auto fetch plugin dataFetchMapKey: ',
|
|
55
|
+
dataFetchMapKey,
|
|
56
|
+
);
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
if (!dataFetchMapKey) {
|
|
59
|
+
return args;
|
|
60
|
+
}
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
const dataFetchItem = getDataFetchItem(dataFetchMapKey);
|
|
63
|
+
if (dataFetchItem) {
|
|
64
|
+
return args;
|
|
65
|
+
}
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
67
|
+
const dataFetchMap = getDataFetchMap();
|
|
68
|
+
const hasSSRAsset = Boolean(remoteSnapshot.ssrRemoteEntry);
|
|
69
|
+
const hasDataFetchClient = Boolean(
|
|
70
|
+
remoteSnapshot.modules.find(
|
|
71
|
+
(module) =>
|
|
72
|
+
module.moduleName === `${dataFetchName}${DATA_FETCH_CLIENT_SUFFIX}`,
|
|
73
|
+
),
|
|
74
|
+
);
|
|
75
|
+
const downgradeType = hasDataFetchClient
|
|
76
|
+
? MF_DATA_FETCH_TYPE.FETCH_CLIENT
|
|
77
|
+
: hasSSRAsset
|
|
78
|
+
? MF_DATA_FETCH_TYPE.FETCH_SERVER
|
|
79
|
+
: MF_DATA_FETCH_TYPE.FETCH_CLIENT;
|
|
80
|
+
let finalDataFetchId = dataFetchId;
|
|
83
81
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
if (!isServerEnv()) {
|
|
83
|
+
finalDataFetchId =
|
|
84
|
+
downgradeType === MF_DATA_FETCH_TYPE.FETCH_CLIENT
|
|
85
|
+
? hasDataFetchClient
|
|
86
|
+
? `${dataFetchId}${DATA_FETCH_CLIENT_SUFFIX}`
|
|
87
|
+
: dataFetchId
|
|
88
|
+
: dataFetchId;
|
|
89
|
+
}
|
|
92
90
|
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
const getDataFetchGetter = () =>
|
|
92
|
+
loadDataFetchModule(host, finalDataFetchId);
|
|
95
93
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
const dataFetchFnItem: MF_DATA_FETCH_MAP_VALUE[0] = [
|
|
95
|
+
getDataFetchGetter,
|
|
96
|
+
downgradeType,
|
|
97
|
+
];
|
|
100
98
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
// server client must execute
|
|
100
|
+
if (typeof window === 'undefined' || isCSROnly()) {
|
|
101
|
+
dataFetchFnItem.push(getDataFetchGetter());
|
|
102
|
+
}
|
|
105
103
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
dataFetchMap[dataFetchMapKey] = [
|
|
105
|
+
dataFetchFnItem,
|
|
106
|
+
undefined,
|
|
107
|
+
MF_DATA_FETCH_STATUS.AWAIT,
|
|
108
|
+
];
|
|
111
109
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
110
|
+
return args;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
};
|
|
115
114
|
|
|
116
115
|
export default autoFetchData;
|