@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.
Files changed (40) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/dist/data-fetch-server-middleware.d.ts +9 -0
  3. package/dist/data-fetch-server-middleware.es.js +1 -1
  4. package/dist/data-fetch-utils.cjs.js +4 -1253
  5. package/dist/data-fetch-utils.d.ts +10 -1
  6. package/dist/data-fetch-utils.es.js +11 -1260
  7. package/dist/index.cjs.js +7 -433
  8. package/dist/index.d.ts +11 -11
  9. package/dist/index.es.js +20 -447
  10. package/dist/lazy-load-component-plugin-CttAWi8N.js +500 -0
  11. package/dist/lazy-load-component-plugin-hOC-Yus_.mjs +501 -0
  12. package/dist/lazy-load-component-plugin.cjs.js +6 -0
  13. package/dist/lazy-load-component-plugin.d.ts +16 -0
  14. package/dist/lazy-load-component-plugin.es.js +6 -0
  15. package/dist/lazy-utils.d.ts +9 -0
  16. package/dist/lazy-utils.es.js +19 -19
  17. package/dist/plugin.d.ts +9 -0
  18. package/dist/prefetch-Cx6MrkdU.mjs +1330 -0
  19. package/dist/prefetch-cGDaDkgV.js +1329 -0
  20. package/dist/router-v5.d.ts +9 -0
  21. package/dist/router-v6.d.ts +9 -0
  22. package/dist/router.d.ts +9 -0
  23. package/dist/{utils-Bk8hGjjF.mjs → utils-BTYYwZcb.mjs} +31 -31
  24. package/dist/v18.d.ts +9 -0
  25. package/dist/v19.d.ts +9 -0
  26. package/package.json +11 -11
  27. package/src/index.ts +3 -1
  28. package/src/lazy/createLazyComponent.tsx +88 -74
  29. package/src/lazy/data-fetch/index.ts +1 -0
  30. package/src/lazy/data-fetch/prefetch.ts +1 -1
  31. package/src/lazy/data-fetch/runtime-plugin.ts +80 -81
  32. package/src/lazy/index.ts +6 -2
  33. package/src/plugins/lazy-load-component-plugin.ts +72 -0
  34. package/vite.config.ts +2 -2
  35. package/dist/data-fetch-runtime-plugin.cjs.js +0 -73
  36. package/dist/data-fetch-runtime-plugin.d.ts +0 -6
  37. package/dist/data-fetch-runtime-plugin.es.js +0 -74
  38. package/dist/inject-data-fetch-CAvi-gSf.js +0 -79
  39. package/dist/inject-data-fetch-errCdqBS.mjs +0 -80
  40. package/src/.eslintrc.js +0 -9
@@ -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
+ }
@@ -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
- generateKey as A,
1979
- cache as B,
1978
+ DOWNGRADE_KEY as A,
1979
+ getDowngradeTag as B,
1980
1980
  CacheSize as C,
1981
- DATA_FETCH_CLIENT_SUFFIX as D,
1981
+ DATA_FETCH_QUERY as D,
1982
1982
  ERROR_TYPE as E,
1983
1983
  FS_HREF as F,
1984
- revalidateTag as G,
1985
- clearStore as H,
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
- MF_DATA_FETCH_TYPE as M,
1990
- getDataFetchMapKey as a,
1991
- getDataFetchItem as b,
1992
- isServerEnv as c,
1993
- isCSROnly as d,
1994
- loadDataFetchModule as e,
1995
- MF_DATA_FETCH_STATUS as f,
1996
- getDataFetchInfo as g,
1997
- getDataFetchMap as h,
1998
- isDataLoaderExpose as i,
1999
- initDataFetchMap as j,
2000
- DATA_FETCH_QUERY as k,
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
- fetchData as m,
2003
- DATA_FETCH_FUNCTION as n,
2004
- DOWNGRADE_KEY as o,
2005
- getDowngradeTag as p,
2006
- callAllDowngrade as q,
2007
- callDowngrade as r,
2008
- getDataFetchIdWithErrorMsgs as s,
2009
- DATA_FETCH_ERROR_PREFIX as t,
2010
- getLoadedRemoteInfos as u,
2011
- setDataFetchItemLoadedStatus as v,
2012
- wrapDataFetchId as w,
2013
- setSSREnv as x,
2014
- CacheTime as y,
2015
- configureCache as z
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-20250708033956",
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
- "data-fetch-runtime-plugin": [
81
- "./dist/lazy-utils.d.ts"
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-20250708033956",
98
- "@module-federation/sdk": "0.0.0-next-20250708033956"
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-20250708033956"
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(id: string, instance?: FederationHost) {
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.snapshot;
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
- (typeof window !== 'undefined' && window.location.href !== window[FS_HREF])
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
- if (!options.noSSR) {
339
- return (
340
- <AwaitDataFetch
341
- resolve={getData(options.noSSR)}
342
- loading={options.loading}
343
- delayLoading={options.delayLoading}
344
- errorElement={options.fallback}
345
- >
346
- {/* @ts-expect-error ignore */}
347
- {(data) => <LazyComponent {...args} mfData={data} />}
348
- </AwaitDataFetch>
349
- );
350
- } else {
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
- useEffect(() => {
357
- let isMounted = true;
358
- const fetchDataAsync = async () => {
359
- try {
360
- setLoading(true);
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
- fetchDataAsync();
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
- return () => {
379
- isMounted = false;
380
- };
381
- }, []);
390
+ // fetchDataAsync();
382
391
 
383
- if (loading) {
384
- return (
385
- <DelayedLoading delayLoading={options.delayLoading}>
386
- {options.loading}
387
- </DelayedLoading>
388
- );
389
- }
392
+ // return () => {
393
+ // isMounted = false;
394
+ // };
395
+ // }, []);
390
396
 
391
- if (error) {
392
- return (
393
- <>
394
- {typeof options.fallback === 'function'
395
- ? options.fallback(error)
396
- : options.fallback}
397
- </>
398
- );
399
- }
400
- // @ts-expect-error ignore
401
- return <LazyComponent {...args} mfData={data} />;
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
  }
@@ -12,4 +12,5 @@ export {
12
12
 
13
13
  export type { CacheStatus, CacheStatsInfo } from './cache';
14
14
 
15
+ export type { PrefetchOptions } from './prefetch';
15
16
  export { prefetch } from './prefetch';
@@ -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
- name: 'auto-fetch-data-plugin',
25
- beforeInit(args) {
26
- initDataFetchMap();
27
- injectDataFetch();
28
- return args;
29
- },
30
- afterLoadSnapshot(args) {
31
- const { id, moduleInfo, remoteSnapshot, host } = args;
32
- if (typeof id === 'string' && isDataLoaderExpose(id)) {
33
- return args;
34
- }
35
- if (!remoteSnapshot || !id || !('modules' in remoteSnapshot)) {
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
- const { name, alias } = moduleInfo;
40
- const dataFetchInfo = getDataFetchInfo({
41
- name,
42
- alias,
43
- id,
44
- remoteSnapshot,
45
- });
46
- if (!dataFetchInfo) {
47
- return args;
48
- }
49
- const { dataFetchId, dataFetchName } = dataFetchInfo;
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
- const dataFetchMapKey = getDataFetchMapKey(dataFetchInfo, {
52
- name: host.name,
53
- version: host.options.version,
54
- });
55
- logger.debug(
56
- '======= auto fetch plugin dataFetchMapKey: ',
57
- dataFetchMapKey,
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
- if (!dataFetchMapKey) {
61
- return args;
62
- }
58
+ if (!dataFetchMapKey) {
59
+ return args;
60
+ }
63
61
 
64
- const dataFetchItem = getDataFetchItem(dataFetchMapKey);
65
- if (dataFetchItem) {
66
- return args;
67
- }
62
+ const dataFetchItem = getDataFetchItem(dataFetchMapKey);
63
+ if (dataFetchItem) {
64
+ return args;
65
+ }
68
66
 
69
- const dataFetchMap = getDataFetchMap();
70
- const hasSSRAsset = Boolean(remoteSnapshot.ssrRemoteEntry);
71
- const hasDataFetchClient = Boolean(
72
- remoteSnapshot.modules.find(
73
- (module) =>
74
- module.moduleName === `${dataFetchName}${DATA_FETCH_CLIENT_SUFFIX}`,
75
- ),
76
- );
77
- const downgradeType = hasDataFetchClient
78
- ? MF_DATA_FETCH_TYPE.FETCH_CLIENT
79
- : hasSSRAsset
80
- ? MF_DATA_FETCH_TYPE.FETCH_SERVER
81
- : MF_DATA_FETCH_TYPE.FETCH_CLIENT;
82
- let finalDataFetchId = dataFetchId;
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
- if (!isServerEnv()) {
85
- finalDataFetchId =
86
- downgradeType === MF_DATA_FETCH_TYPE.FETCH_CLIENT
87
- ? hasDataFetchClient
88
- ? `${dataFetchId}${DATA_FETCH_CLIENT_SUFFIX}`
89
- : dataFetchId
90
- : dataFetchId;
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
- const getDataFetchGetter = () =>
94
- loadDataFetchModule(host, finalDataFetchId);
91
+ const getDataFetchGetter = () =>
92
+ loadDataFetchModule(host, finalDataFetchId);
95
93
 
96
- const dataFetchFnItem: MF_DATA_FETCH_MAP_VALUE[0] = [
97
- getDataFetchGetter,
98
- downgradeType,
99
- ];
94
+ const dataFetchFnItem: MF_DATA_FETCH_MAP_VALUE[0] = [
95
+ getDataFetchGetter,
96
+ downgradeType,
97
+ ];
100
98
 
101
- // server client must execute
102
- if (typeof window === 'undefined' || isCSROnly()) {
103
- dataFetchFnItem.push(getDataFetchGetter());
104
- }
99
+ // server client must execute
100
+ if (typeof window === 'undefined' || isCSROnly()) {
101
+ dataFetchFnItem.push(getDataFetchGetter());
102
+ }
105
103
 
106
- dataFetchMap[dataFetchMapKey] = [
107
- dataFetchFnItem,
108
- undefined,
109
- MF_DATA_FETCH_STATUS.AWAIT,
110
- ];
104
+ dataFetchMap[dataFetchMapKey] = [
105
+ dataFetchFnItem,
106
+ undefined,
107
+ MF_DATA_FETCH_STATUS.AWAIT,
108
+ ];
111
109
 
112
- return args;
113
- },
114
- });
110
+ return args;
111
+ },
112
+ };
113
+ };
115
114
 
116
115
  export default autoFetchData;