@module-federation/bridge-react 0.0.0-next-20250618090118 → 0.0.0-next-20250620084158

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 (53) hide show
  1. package/CHANGELOG.md +3 -8
  2. package/__tests__/bridge.spec.tsx +7 -7
  3. package/dist/{bridge-base-DKPEvcPJ.js → bridge-base-BBH982Tz.cjs} +1 -1
  4. package/dist/{bridge-base-YDjQh_vg.mjs → bridge-base-P6pEjY1q.js} +1 -1
  5. package/dist/{index.esm-BjwhLgko.js → index-Cv3p6r66.cjs} +43 -21
  6. package/dist/{index.esm-nDSYG6Nj.mjs → index-D4yt7Udv.js} +43 -21
  7. package/dist/index.cjs.js +9 -427
  8. package/dist/index.d.ts +0 -77
  9. package/dist/index.es.js +11 -430
  10. package/dist/router-v5.cjs.js +1 -1
  11. package/dist/router-v5.es.js +1 -1
  12. package/dist/router-v6.cjs.js +1 -1
  13. package/dist/router-v6.es.js +1 -1
  14. package/dist/router.cjs.js +1 -1
  15. package/dist/router.es.js +1 -1
  16. package/dist/v18.cjs.js +1 -1
  17. package/dist/v18.es.js +1 -1
  18. package/dist/v19.cjs.js +1 -1
  19. package/dist/v19.es.js +1 -1
  20. package/package.json +5 -44
  21. package/src/index.ts +1 -21
  22. package/src/remote/component.tsx +3 -3
  23. package/src/remote/create.tsx +4 -17
  24. package/vite.config.ts +0 -13
  25. package/dist/data-fetch-runtime-plugin.cjs.js +0 -71
  26. package/dist/data-fetch-runtime-plugin.d.ts +0 -6
  27. package/dist/data-fetch-runtime-plugin.es.js +0 -72
  28. package/dist/data-fetch-server-middleware.cjs.js +0 -158
  29. package/dist/data-fetch-server-middleware.d.ts +0 -6
  30. package/dist/data-fetch-server-middleware.es.js +0 -159
  31. package/dist/data-fetch-utils.cjs.js +0 -90
  32. package/dist/data-fetch-utils.d.ts +0 -5
  33. package/dist/data-fetch-utils.es.js +0 -90
  34. package/dist/index-BYOQ_Qrb.js +0 -45
  35. package/dist/index-CUrEc0Q1.mjs +0 -46
  36. package/dist/lazy-utils.cjs.js +0 -22
  37. package/dist/lazy-utils.d.ts +0 -114
  38. package/dist/lazy-utils.es.js +0 -22
  39. package/dist/utils-DhtukXOQ.mjs +0 -327
  40. package/dist/utils-YoyAVYsh.js +0 -326
  41. package/src/lazy/AwaitDataFetch.tsx +0 -176
  42. package/src/lazy/constant.ts +0 -30
  43. package/src/lazy/createLazyComponent.tsx +0 -390
  44. package/src/lazy/data-fetch/call-data-fetch.ts +0 -13
  45. package/src/lazy/data-fetch/data-fetch-server-middleware.ts +0 -191
  46. package/src/lazy/data-fetch/index.ts +0 -2
  47. package/src/lazy/data-fetch/inject-data-fetch.ts +0 -109
  48. package/src/lazy/data-fetch/runtime-plugin.ts +0 -113
  49. package/src/lazy/index.ts +0 -18
  50. package/src/lazy/logger.ts +0 -6
  51. package/src/lazy/types.ts +0 -49
  52. package/src/lazy/utils.ts +0 -355
  53. package/src/lazy/wrapNoSSR.tsx +0 -10
@@ -1,176 +0,0 @@
1
- import React, { MutableRefObject, ReactNode, Suspense, useRef } from 'react';
2
- import logger from './logger';
3
- import {
4
- DATA_FETCH_ERROR_PREFIX,
5
- LOAD_REMOTE_ERROR_PREFIX,
6
- ERROR_TYPE,
7
- DATA_FETCH_FUNCTION,
8
- } from './constant';
9
-
10
- import { getDataFetchIdWithErrorMsgs, wrapDataFetchId } from './utils';
11
- import type { DataFetchParams } from './types';
12
-
13
- function isPromise<T>(obj: any): obj is PromiseLike<T> {
14
- return (
15
- !!obj &&
16
- (typeof obj === 'object' || typeof obj === 'function') &&
17
- typeof obj.then === 'function'
18
- );
19
- }
20
- const AWAIT_ERROR_PREFIX =
21
- '<Await /> caught the following error during render: ';
22
-
23
- export type ErrorInfo = {
24
- error: Error;
25
- errorType: number;
26
- dataFetchMapKey?: string;
27
- };
28
-
29
- export const transformError = (err: string | Error): ErrorInfo => {
30
- const errMsg = err instanceof Error ? err.message : err;
31
- const originalMsg = errMsg.replace(AWAIT_ERROR_PREFIX, '');
32
- const dataFetchMapKey = getDataFetchIdWithErrorMsgs(originalMsg);
33
- if (originalMsg.indexOf(DATA_FETCH_ERROR_PREFIX) === 0) {
34
- return {
35
- error: new Error(
36
- originalMsg
37
- .replace(DATA_FETCH_ERROR_PREFIX, '')
38
- .replace(wrapDataFetchId(dataFetchMapKey), ''),
39
- ),
40
- errorType: ERROR_TYPE.DATA_FETCH,
41
- dataFetchMapKey,
42
- };
43
- }
44
- if (originalMsg.indexOf(LOAD_REMOTE_ERROR_PREFIX) === 0) {
45
- return {
46
- error: new Error(
47
- originalMsg
48
- .replace(LOAD_REMOTE_ERROR_PREFIX, '')
49
- .replace(wrapDataFetchId(dataFetchMapKey), ''),
50
- ),
51
- errorType: ERROR_TYPE.LOAD_REMOTE,
52
- dataFetchMapKey,
53
- };
54
- }
55
-
56
- return {
57
- error: new Error(originalMsg.replace(wrapDataFetchId(dataFetchMapKey), '')),
58
- errorType: ERROR_TYPE.UNKNOWN,
59
- dataFetchMapKey,
60
- };
61
- };
62
-
63
- export interface AwaitProps<T> {
64
- resolve: T | Promise<T>;
65
- loading?: ReactNode;
66
- errorElement?: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
67
- children: (data: T) => ReactNode;
68
- params?: DataFetchParams;
69
- }
70
-
71
- export interface AwaitErrorHandlerProps<T = any>
72
- extends Omit<AwaitProps<T>, 'resolve'> {
73
- resolve: () => T | string;
74
- }
75
-
76
- const DefaultLoading = <></>;
77
- const DefaultErrorElement = (_data: any) => <div>Error</div>;
78
-
79
- export function AwaitDataFetch<T>({
80
- resolve,
81
- loading = DefaultLoading,
82
- errorElement = DefaultErrorElement,
83
- children,
84
- params,
85
- }: AwaitProps<T>) {
86
- const dataRef = useRef<T>();
87
- const data = dataRef.current || resolve;
88
- const getData = isPromise(data) ? fetchData(data, dataRef) : () => data;
89
-
90
- return (
91
- <AwaitSuspense
92
- params={params}
93
- loading={loading}
94
- errorElement={errorElement}
95
- // @ts-ignore
96
- resolve={getData}
97
- >
98
- {children}
99
- </AwaitSuspense>
100
- );
101
- }
102
-
103
- function AwaitSuspense<T>({
104
- resolve,
105
- children,
106
- loading = DefaultLoading,
107
- errorElement = DefaultErrorElement,
108
- }: AwaitErrorHandlerProps<T>) {
109
- return (
110
- <Suspense fallback={loading}>
111
- <ResolveAwait resolve={resolve} errorElement={errorElement}>
112
- {children}
113
- </ResolveAwait>
114
- </Suspense>
115
- );
116
- }
117
-
118
- function ResolveAwait<T>({
119
- children,
120
- resolve,
121
- errorElement,
122
- params,
123
- }: AwaitErrorHandlerProps<T>) {
124
- const data = resolve();
125
- logger.debug('resolve data: ', data);
126
- if (typeof data === 'string' && data.indexOf(AWAIT_ERROR_PREFIX) === 0) {
127
- const transformedError = transformError(data);
128
- return (
129
- <>
130
- {typeof errorElement === 'function' ? (
131
- <>
132
- {globalThis.FEDERATION_SSR && (
133
- <script
134
- suppressHydrationWarning
135
- dangerouslySetInnerHTML={{
136
- __html: String.raw`
137
- globalThis['${DATA_FETCH_FUNCTION}'] = globalThis['${DATA_FETCH_FUNCTION}'] || []
138
- globalThis['${DATA_FETCH_FUNCTION}'].push([${transformedError.dataFetchMapKey ? `'${transformedError.dataFetchMapKey}'` : ''},${params ? JSON.stringify(params) : null},true]);`,
139
- }}
140
- ></script>
141
- )}
142
- {errorElement(transformedError)}
143
- </>
144
- ) : (
145
- errorElement
146
- )}
147
- </>
148
- );
149
- }
150
- const toRender =
151
- typeof children === 'function' ? children(data as T) : children;
152
- return <>{toRender}</>;
153
- }
154
-
155
- // return string when promise is rejected
156
- const fetchData = <T,>(promise: Promise<T>, ref: MutableRefObject<T>) => {
157
- let data: T | string;
158
- let status: 'pending' | 'success' = 'pending';
159
- const suspender = promise
160
- .then((res) => {
161
- status = 'success';
162
- data = res;
163
- ref.current = res;
164
- })
165
- .catch((e) => {
166
- status = 'success';
167
- console.warn(e);
168
- data = AWAIT_ERROR_PREFIX + e;
169
- });
170
- return () => {
171
- if (status === 'pending') {
172
- throw suspender;
173
- }
174
- return data;
175
- };
176
- };
@@ -1,30 +0,0 @@
1
- export const PLUGIN_IDENTIFIER = '[ Module Federation React ]';
2
- export const DOWNGRADE_KEY = '_mfSSRDowngrade';
3
- export const DATA_FETCH_MAP_KEY = '__MF_DATA_FETCH_MAP__';
4
- export const DATA_FETCH_FUNCTION = '_mfDataFetch';
5
- export const FS_HREF = '_mfFSHref';
6
- export const ERROR_TYPE = {
7
- DATA_FETCH: 1,
8
- LOAD_REMOTE: 2,
9
- UNKNOWN: 3,
10
- };
11
- export const WRAP_DATA_FETCH_ID_IDENTIFIER = 'wrap_dfip_identifier';
12
- export const enum MF_DATA_FETCH_TYPE {
13
- FETCH_SERVER = 1,
14
- FETCH_CLIENT = 2,
15
- }
16
-
17
- export const enum MF_DATA_FETCH_STATUS {
18
- LOADED = 1,
19
- LOADING = 2,
20
- AWAIT = 0,
21
- ERROR = 3,
22
- }
23
-
24
- export const DATA_FETCH_IDENTIFIER = 'data';
25
- export const DATA_FETCH_CLIENT_SUFFIX = '.client';
26
- export const DATA_FETCH_QUERY = 'x-mf-data-fetch';
27
- export const DATA_FETCH_ERROR_PREFIX =
28
- 'caught the following error during dataFetch: ';
29
- export const LOAD_REMOTE_ERROR_PREFIX =
30
- 'caught the following error during loadRemote: ';
@@ -1,390 +0,0 @@
1
- import React, { ReactNode, useEffect, useState } from 'react';
2
- import logger from './logger';
3
- import { AwaitDataFetch, transformError } from './AwaitDataFetch';
4
- import {
5
- fetchData,
6
- getDataFetchItem,
7
- getDataFetchMapKey,
8
- getDataFetchInfo,
9
- getLoadedRemoteInfos,
10
- setDataFetchItemLoadedStatus,
11
- wrapDataFetchId,
12
- } from './utils';
13
- import {
14
- DATA_FETCH_ERROR_PREFIX,
15
- DATA_FETCH_FUNCTION,
16
- FS_HREF,
17
- LOAD_REMOTE_ERROR_PREFIX,
18
- MF_DATA_FETCH_TYPE,
19
- } from './constant';
20
-
21
- import type { ErrorInfo } from './AwaitDataFetch';
22
- import type { DataFetchParams, NoSSRRemoteInfo } from './types';
23
- import type { FederationHost } from '@module-federation/runtime';
24
-
25
- export type IProps = {
26
- id: string;
27
- injectScript?: boolean;
28
- injectLink?: boolean;
29
- runtime: typeof import('@module-federation/runtime');
30
- };
31
-
32
- export type CreateLazyComponentOptions<T, E extends keyof T> = {
33
- loader: () => Promise<T>;
34
- loading: React.ReactNode;
35
- fallback: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
36
- export?: E;
37
- dataFetchParams?: DataFetchParams;
38
- noSSR?: boolean;
39
- runtime: typeof import('@module-federation/runtime');
40
- };
41
-
42
- type ReactKey = { key?: React.Key | null };
43
-
44
- function getTargetModuleInfo(id: string, instance?: FederationHost) {
45
- if (!instance) {
46
- return;
47
- }
48
- const loadedRemoteInfo = getLoadedRemoteInfos(id, instance);
49
- if (!loadedRemoteInfo) {
50
- return;
51
- }
52
- const snapshot = loadedRemoteInfo.snapshot;
53
- if (!snapshot) {
54
- return;
55
- }
56
- const publicPath =
57
- 'publicPath' in snapshot
58
- ? snapshot.publicPath
59
- : 'getPublicPath' in snapshot
60
- ? new Function(snapshot.getPublicPath)()
61
- : '';
62
- if (!publicPath) {
63
- return;
64
- }
65
- const modules = 'modules' in snapshot ? snapshot.modules : [];
66
- const targetModule = modules.find(
67
- (m) => m.modulePath === loadedRemoteInfo.expose,
68
- );
69
- if (!targetModule) {
70
- return;
71
- }
72
-
73
- const remoteEntry = 'remoteEntry' in snapshot ? snapshot.remoteEntry : '';
74
- if (!remoteEntry) {
75
- return;
76
- }
77
- return {
78
- module: targetModule,
79
- publicPath,
80
- remoteEntry,
81
- };
82
- }
83
-
84
- export function collectSSRAssets(options: IProps) {
85
- const {
86
- id,
87
- injectLink = true,
88
- injectScript = false,
89
- } = typeof options === 'string' ? { id: options } : options;
90
- const links: React.ReactNode[] = [];
91
- const scripts: React.ReactNode[] = [];
92
- const instance = options.runtime.getInstance();
93
- if (!instance || (!injectLink && !injectScript)) {
94
- return [...scripts, ...links];
95
- }
96
-
97
- const moduleAndPublicPath = getTargetModuleInfo(id, instance);
98
- if (!moduleAndPublicPath) {
99
- return [...scripts, ...links];
100
- }
101
- const { module: targetModule, publicPath, remoteEntry } = moduleAndPublicPath;
102
- if (injectLink) {
103
- [...targetModule.assets.css.sync, ...targetModule.assets.css.async]
104
- .sort()
105
- .forEach((file, index) => {
106
- links.push(
107
- <link
108
- key={`${file.split('.')[0]}_${index}`}
109
- href={`${publicPath}${file}`}
110
- rel="stylesheet"
111
- type="text/css"
112
- />,
113
- );
114
- });
115
- }
116
-
117
- if (injectScript) {
118
- scripts.push(
119
- <script
120
- async={true}
121
- key={remoteEntry.split('.')[0]}
122
- src={`${publicPath}${remoteEntry}`}
123
- crossOrigin="anonymous"
124
- />,
125
- );
126
- [...targetModule.assets.js.sync].sort().forEach((file, index) => {
127
- scripts.push(
128
- <script
129
- key={`${file.split('.')[0]}_${index}`}
130
- async={true}
131
- src={`${publicPath}${file}`}
132
- crossOrigin="anonymous"
133
- />,
134
- );
135
- });
136
- }
137
-
138
- return [...scripts, ...links];
139
- }
140
-
141
- function getServerNeedRemoteInfo(
142
- loadedRemoteInfo: ReturnType<typeof getLoadedRemoteInfos>,
143
- id: string,
144
- noSSR?: boolean,
145
- ): NoSSRRemoteInfo | undefined {
146
- if (
147
- noSSR ||
148
- (typeof window !== 'undefined' && window.location.href !== window[FS_HREF])
149
- ) {
150
- if (!loadedRemoteInfo?.version) {
151
- throw new Error(`${loadedRemoteInfo?.name} version is empty`);
152
- }
153
- const { snapshot } = loadedRemoteInfo;
154
- if (!snapshot) {
155
- throw new Error(`${loadedRemoteInfo?.name} snapshot is empty`);
156
- }
157
- const dataFetchItem = getDataFetchItem(id);
158
- const isFetchServer =
159
- dataFetchItem?.[0]?.[1] === MF_DATA_FETCH_TYPE.FETCH_SERVER;
160
-
161
- if (
162
- isFetchServer &&
163
- (!('ssrPublicPath' in snapshot) || !snapshot.ssrPublicPath)
164
- ) {
165
- throw new Error(
166
- `ssrPublicPath is required while fetching ${loadedRemoteInfo?.name} data in SSR project!`,
167
- );
168
- }
169
-
170
- if (
171
- isFetchServer &&
172
- (!('ssrRemoteEntry' in snapshot) || !snapshot.ssrRemoteEntry)
173
- ) {
174
- throw new Error(
175
- `ssrRemoteEntry is required while loading ${loadedRemoteInfo?.name} data loader in SSR project!`,
176
- );
177
- }
178
-
179
- return {
180
- name: loadedRemoteInfo.name,
181
- version: loadedRemoteInfo.version,
182
- ssrPublicPath:
183
- 'ssrPublicPath' in snapshot ? snapshot.ssrPublicPath || '' : '',
184
- ssrRemoteEntry:
185
- 'ssrRemoteEntry' in snapshot ? snapshot.ssrRemoteEntry || '' : '',
186
- globalName: loadedRemoteInfo.entryGlobalName,
187
- };
188
- }
189
- return;
190
- }
191
-
192
- export function createLazyComponent<T, E extends keyof T>(
193
- options: CreateLazyComponentOptions<T, E>,
194
- ) {
195
- const { runtime } = options;
196
- if (!runtime?.getInstance) {
197
- throw new Error(
198
- 'runtime is required if used in "@module-federation/bridge-react"!',
199
- );
200
- }
201
- type ComponentType = T[E] extends (...args: any) => any
202
- ? Parameters<T[E]>[0] extends undefined
203
- ? ReactKey
204
- : Parameters<T[E]>[0] & ReactKey
205
- : ReactKey;
206
- const exportName = options?.export || 'default';
207
-
208
- const callLoader = async () => {
209
- logger.debug('callLoader start', Date.now());
210
- const m = (await options.loader()) as Record<string, React.FC> &
211
- Record<symbol, string>;
212
- logger.debug('callLoader end', Date.now());
213
- if (!m) {
214
- throw new Error('load remote failed');
215
- }
216
- return m;
217
- };
218
-
219
- const getData = async (noSSR?: boolean) => {
220
- let loadedRemoteInfo: ReturnType<typeof getLoadedRemoteInfos>;
221
- let moduleId: string;
222
- const instance = runtime.getInstance();
223
- try {
224
- const m = await callLoader();
225
- moduleId = m && m[Symbol.for('mf_module_id')];
226
- if (!moduleId) {
227
- throw new Error('moduleId is empty');
228
- }
229
- loadedRemoteInfo = getLoadedRemoteInfos(moduleId, instance);
230
- if (!loadedRemoteInfo) {
231
- throw new Error(`can not find loaded remote('${moduleId}') info!`);
232
- }
233
- } catch (e) {
234
- const errMsg = `${LOAD_REMOTE_ERROR_PREFIX}${e}`;
235
- logger.debug(e);
236
- throw new Error(errMsg);
237
- }
238
- let dataFetchMapKey: string | undefined;
239
- try {
240
- dataFetchMapKey = getDataFetchMapKey(
241
- getDataFetchInfo({
242
- name: loadedRemoteInfo.name,
243
- alias: loadedRemoteInfo.alias,
244
- id: moduleId,
245
- remoteSnapshot: loadedRemoteInfo.snapshot,
246
- }),
247
- { name: instance!.name, version: instance?.options.version },
248
- );
249
- logger.debug('getData dataFetchMapKey: ', dataFetchMapKey);
250
- if (!dataFetchMapKey) {
251
- return;
252
- }
253
- const data = await fetchData(
254
- dataFetchMapKey,
255
- {
256
- ...options.dataFetchParams,
257
- isDowngrade: false,
258
- },
259
- getServerNeedRemoteInfo(loadedRemoteInfo, dataFetchMapKey, noSSR),
260
- );
261
- setDataFetchItemLoadedStatus(dataFetchMapKey);
262
- logger.debug('get data res: \n', data);
263
- return data;
264
- } catch (err) {
265
- const errMsg = `${DATA_FETCH_ERROR_PREFIX}${wrapDataFetchId(dataFetchMapKey)}${err}`;
266
- logger.debug(errMsg);
267
- throw new Error(errMsg);
268
- }
269
- };
270
-
271
- const LazyComponent = React.lazy(async () => {
272
- const m = await callLoader();
273
- const moduleId = m && m[Symbol.for('mf_module_id')];
274
- const instance = runtime.getInstance()!;
275
- const loadedRemoteInfo = getLoadedRemoteInfos(moduleId, instance);
276
- loadedRemoteInfo?.snapshot;
277
- const dataFetchMapKey = loadedRemoteInfo
278
- ? getDataFetchMapKey(
279
- getDataFetchInfo({
280
- name: loadedRemoteInfo.name,
281
- alias: loadedRemoteInfo.alias,
282
- id: moduleId,
283
- remoteSnapshot: loadedRemoteInfo.snapshot,
284
- }),
285
- { name: instance.name, version: instance?.options.version },
286
- )
287
- : undefined;
288
- logger.debug('LazyComponent dataFetchMapKey: ', dataFetchMapKey);
289
-
290
- const assets = collectSSRAssets({
291
- id: moduleId,
292
- runtime,
293
- });
294
-
295
- const Com = m[exportName] as React.FC<ComponentType>;
296
- if (exportName in m && typeof Com === 'function') {
297
- return {
298
- default: (props: Omit<ComponentType, 'key'> & { mfData?: unknown }) => (
299
- <>
300
- {globalThis.FEDERATION_SSR && dataFetchMapKey && (
301
- <script
302
- suppressHydrationWarning
303
- dangerouslySetInnerHTML={{
304
- __html: String.raw`
305
- globalThis['${DATA_FETCH_FUNCTION}'] = globalThis['${DATA_FETCH_FUNCTION}'] || [];
306
- globalThis['${DATA_FETCH_FUNCTION}'].push(['${dataFetchMapKey}',${JSON.stringify(props.mfData)}]);
307
- `,
308
- }}
309
- ></script>
310
- )}
311
- {globalThis.FEDERATION_SSR && assets}
312
- <Com {...props} />
313
- </>
314
- ),
315
- };
316
- } else {
317
- throw Error(
318
- `Make sure that ${moduleId} has the correct export when export is ${String(
319
- exportName,
320
- )}`,
321
- );
322
- }
323
- });
324
-
325
- return (props: ComponentType) => {
326
- const { key, ...args } = props;
327
- if (globalThis.FEDERATION_SSR && !options.noSSR) {
328
- const { key, ...args } = props;
329
-
330
- return (
331
- <AwaitDataFetch
332
- resolve={getData(options.noSSR)}
333
- loading={options.loading}
334
- errorElement={options.fallback}
335
- >
336
- {/* @ts-ignore */}
337
- {(data) => <LazyComponent {...args} mfData={data} />}
338
- </AwaitDataFetch>
339
- );
340
- } else {
341
- // Client-side rendering logic
342
- const [data, setData] = useState<unknown>(null);
343
- const [loading, setLoading] = useState<boolean>(true);
344
- const [error, setError] = useState<ErrorInfo | null>(null);
345
-
346
- useEffect(() => {
347
- let isMounted = true;
348
- const fetchDataAsync = async () => {
349
- try {
350
- setLoading(true);
351
- const result = await getData(options.noSSR);
352
- if (isMounted) {
353
- setData(result);
354
- }
355
- } catch (e: any) {
356
- if (isMounted) {
357
- setError(transformError(e));
358
- }
359
- } finally {
360
- if (isMounted) {
361
- setLoading(false);
362
- }
363
- }
364
- };
365
-
366
- fetchDataAsync();
367
-
368
- return () => {
369
- isMounted = false;
370
- };
371
- }, []);
372
-
373
- if (loading) {
374
- return <>{options.loading}</>;
375
- }
376
-
377
- if (error) {
378
- return (
379
- <>
380
- {typeof options.fallback === 'function'
381
- ? options.fallback(error)
382
- : options.fallback}
383
- </>
384
- );
385
- }
386
- // @ts-ignore
387
- return <LazyComponent {...args} mfData={data} />;
388
- }
389
- };
390
- }
@@ -1,13 +0,0 @@
1
- import { DATA_FETCH_FUNCTION } from '../constant';
2
- import { dataFetchFunction } from './inject-data-fetch';
3
-
4
- export async function callDataFetch() {
5
- const dataFetch = globalThis[DATA_FETCH_FUNCTION];
6
- if (dataFetch) {
7
- await Promise.all(
8
- dataFetch.map(async (options) => {
9
- await dataFetchFunction(options);
10
- }),
11
- );
12
- }
13
- }