@module-federation/bridge-react 2.3.3 → 2.4.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.
Files changed (57) hide show
  1. package/package.json +9 -5
  2. package/.turbo/turbo-build.log +0 -85
  3. package/CHANGELOG.md +0 -839
  4. package/__tests__/bridge.spec.tsx +0 -160
  5. package/__tests__/createLazyComponent.spec.tsx +0 -209
  6. package/__tests__/prefetch.spec.ts +0 -156
  7. package/__tests__/router.spec.tsx +0 -82
  8. package/__tests__/setupTests.ts +0 -8
  9. package/__tests__/util.ts +0 -36
  10. package/jest.config.ts +0 -21
  11. package/src/base.ts +0 -50
  12. package/src/index.ts +0 -50
  13. package/src/lazy/AwaitDataFetch.tsx +0 -217
  14. package/src/lazy/constant.ts +0 -30
  15. package/src/lazy/createLazyComponent.tsx +0 -411
  16. package/src/lazy/data-fetch/cache.ts +0 -291
  17. package/src/lazy/data-fetch/call-data-fetch.ts +0 -13
  18. package/src/lazy/data-fetch/data-fetch-server-middleware.ts +0 -196
  19. package/src/lazy/data-fetch/index.ts +0 -16
  20. package/src/lazy/data-fetch/inject-data-fetch.ts +0 -109
  21. package/src/lazy/data-fetch/prefetch.ts +0 -112
  22. package/src/lazy/data-fetch/runtime-plugin.ts +0 -115
  23. package/src/lazy/index.ts +0 -35
  24. package/src/lazy/logger.ts +0 -6
  25. package/src/lazy/types.ts +0 -75
  26. package/src/lazy/utils.ts +0 -375
  27. package/src/lazy/wrapNoSSR.tsx +0 -10
  28. package/src/modern-app-env.d.ts +0 -2
  29. package/src/plugins/lazy-load-component-plugin.spec.ts +0 -21
  30. package/src/plugins/lazy-load-component-plugin.ts +0 -57
  31. package/src/provider/context.tsx +0 -4
  32. package/src/provider/plugin.ts +0 -22
  33. package/src/provider/versions/bridge-base.tsx +0 -153
  34. package/src/provider/versions/legacy.ts +0 -87
  35. package/src/provider/versions/v18.ts +0 -47
  36. package/src/provider/versions/v19.ts +0 -48
  37. package/src/remote/RemoteAppWrapper.tsx +0 -108
  38. package/src/remote/base-component/component.tsx +0 -2
  39. package/src/remote/base-component/create.tsx +0 -23
  40. package/src/remote/base-component/index.tsx +0 -10
  41. package/src/remote/createHelpers.tsx +0 -132
  42. package/src/remote/router-component/component.tsx +0 -104
  43. package/src/remote/router-component/create.tsx +0 -23
  44. package/src/remote/router-component/index.tsx +0 -10
  45. package/src/router/default.tsx +0 -73
  46. package/src/router/v5.tsx +0 -43
  47. package/src/router/v6.tsx +0 -74
  48. package/src/router/v7.tsx +0 -75
  49. package/src/types.ts +0 -147
  50. package/src/utils/index.ts +0 -44
  51. package/src/v18.ts +0 -9
  52. package/src/v19.ts +0 -9
  53. package/tsconfig.json +0 -42
  54. package/tsconfig.node.json +0 -11
  55. package/tsconfig.spec.json +0 -26
  56. package/vite.config.ts +0 -112
  57. package/vitest.config.ts +0 -27
package/src/base.ts DELETED
@@ -1,50 +0,0 @@
1
- export { createBridgeComponent } from './provider/versions/legacy';
2
-
3
- // Export router-free versions of remote component creators
4
- export {
5
- createRemoteComponent,
6
- createRemoteAppComponent,
7
- } from './remote/base-component';
8
- export type { LazyRemoteComponentInfo } from './remote/base-component';
9
-
10
- // Export all lazy loading and data fetching utilities (no router dependencies)
11
- export {
12
- ERROR_TYPE,
13
- createLazyComponent,
14
- collectSSRAssets,
15
- callDataFetch,
16
- setSSREnv,
17
- autoFetchDataPlugin,
18
- CacheSize,
19
- CacheTime,
20
- configureCache,
21
- generateKey,
22
- cache,
23
- revalidateTag,
24
- clearStore,
25
- prefetch,
26
- } from './lazy';
27
-
28
- export { lazyLoadComponentPlugin } from './plugins/lazy-load-component-plugin';
29
-
30
- // Export all types
31
- export type { CreateRootOptions, Root } from './provider/versions/legacy';
32
- export type {
33
- ProviderParams,
34
- ProviderFnParams,
35
- RootType,
36
- DestroyParams,
37
- RenderParams,
38
- RemoteComponentParams,
39
- RenderFnParams,
40
- RemoteComponentProps,
41
- RemoteModule,
42
- } from './types';
43
- export type {
44
- DataFetchParams,
45
- NoSSRRemoteInfo,
46
- CollectSSRAssetsOptions,
47
- CreateLazyComponentOptions,
48
- CacheStatus,
49
- CacheStatsInfo,
50
- } from './lazy';
package/src/index.ts DELETED
@@ -1,50 +0,0 @@
1
- /**
2
- * Entry point for React 16/17 (legacy) specific bridge components
3
- * This file provides support for React 16 and 17 versions, using the traditional ReactDOM.render API
4
- */
5
- export { createBridgeComponent } from './provider/versions/legacy';
6
- export {
7
- createRemoteComponent,
8
- createRemoteAppComponent,
9
- } from './remote/router-component';
10
- export type { LazyRemoteComponentInfo } from './remote/router-component';
11
- export {
12
- ERROR_TYPE,
13
- createLazyComponent,
14
- collectSSRAssets,
15
- // wrapNoSSR,
16
- callDataFetch,
17
- setSSREnv,
18
- autoFetchDataPlugin,
19
- CacheSize,
20
- CacheTime,
21
- configureCache,
22
- generateKey,
23
- cache,
24
- revalidateTag,
25
- clearStore,
26
- prefetch,
27
- } from './lazy';
28
-
29
- export { lazyLoadComponentPlugin } from './plugins/lazy-load-component-plugin';
30
-
31
- export type { CreateRootOptions, Root } from './provider/versions/legacy';
32
- export type {
33
- ProviderParams,
34
- ProviderFnParams,
35
- RootType,
36
- DestroyParams,
37
- RenderParams,
38
- RemoteComponentParams,
39
- RenderFnParams,
40
- RemoteComponentProps,
41
- RemoteModule,
42
- } from './types';
43
- export type {
44
- DataFetchParams,
45
- NoSSRRemoteInfo,
46
- CollectSSRAssetsOptions,
47
- CreateLazyComponentOptions,
48
- CacheStatus,
49
- CacheStatsInfo,
50
- } from './lazy';
@@ -1,217 +0,0 @@
1
- import React, {
2
- MutableRefObject,
3
- ReactNode,
4
- Suspense,
5
- useRef,
6
- useState,
7
- } from 'react';
8
- import logger from './logger';
9
- import {
10
- DATA_FETCH_ERROR_PREFIX,
11
- LOAD_REMOTE_ERROR_PREFIX,
12
- ERROR_TYPE,
13
- DATA_FETCH_FUNCTION,
14
- } from './constant';
15
-
16
- import { getDataFetchIdWithErrorMsgs, wrapDataFetchId } from './utils';
17
- import type { DataFetchParams } from './types';
18
-
19
- function isPromise<T>(obj: any): obj is PromiseLike<T> {
20
- return (
21
- !!obj &&
22
- (typeof obj === 'object' || typeof obj === 'function') &&
23
- typeof obj.then === 'function'
24
- );
25
- }
26
- const AWAIT_ERROR_PREFIX =
27
- '<Await /> caught the following error during render: ';
28
-
29
- export type ErrorInfo = {
30
- error: Error;
31
- errorType: number;
32
- dataFetchMapKey?: string;
33
- };
34
-
35
- export const transformError = (err: string | Error): ErrorInfo => {
36
- const errMsg = err instanceof Error ? err.message : err;
37
- const originalMsg = errMsg.replace(AWAIT_ERROR_PREFIX, '');
38
- const dataFetchMapKey = getDataFetchIdWithErrorMsgs(originalMsg);
39
- if (originalMsg.indexOf(DATA_FETCH_ERROR_PREFIX) === 0) {
40
- return {
41
- error: new Error(
42
- originalMsg
43
- .replace(DATA_FETCH_ERROR_PREFIX, '')
44
- .replace(wrapDataFetchId(dataFetchMapKey), ''),
45
- ),
46
- errorType: ERROR_TYPE.DATA_FETCH,
47
- dataFetchMapKey,
48
- };
49
- }
50
- if (originalMsg.indexOf(LOAD_REMOTE_ERROR_PREFIX) === 0) {
51
- return {
52
- error: new Error(
53
- originalMsg
54
- .replace(LOAD_REMOTE_ERROR_PREFIX, '')
55
- .replace(wrapDataFetchId(dataFetchMapKey), ''),
56
- ),
57
- errorType: ERROR_TYPE.LOAD_REMOTE,
58
- dataFetchMapKey,
59
- };
60
- }
61
-
62
- return {
63
- error: new Error(originalMsg.replace(wrapDataFetchId(dataFetchMapKey), '')),
64
- errorType: ERROR_TYPE.UNKNOWN,
65
- dataFetchMapKey,
66
- };
67
- };
68
-
69
- export interface AwaitProps<T> {
70
- resolve: T | Promise<T>;
71
- loading?: ReactNode;
72
- delayLoading?: number;
73
- errorElement?: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
74
- children: (data: T) => ReactNode;
75
- params?: DataFetchParams;
76
- }
77
-
78
- export interface AwaitErrorHandlerProps<T = any> extends Omit<
79
- AwaitProps<T>,
80
- 'resolve'
81
- > {
82
- resolve: () => T | string;
83
- }
84
-
85
- const DefaultLoading = <></>;
86
- const DefaultErrorElement = (_data: any) => <div>Error</div>;
87
-
88
- export function AwaitDataFetch<T>({
89
- resolve,
90
- loading = DefaultLoading,
91
- errorElement = DefaultErrorElement,
92
- children,
93
- params,
94
- delayLoading,
95
- }: AwaitProps<T>) {
96
- const dataRef = useRef<T>();
97
- const data = dataRef.current || resolve;
98
- const getData = isPromise(data) ? fetchData(data, dataRef) : () => data;
99
-
100
- return (
101
- <AwaitSuspense
102
- params={params}
103
- loading={loading}
104
- errorElement={errorElement}
105
- delayLoading={delayLoading}
106
- // @ts-expect-error
107
- resolve={getData}
108
- >
109
- {children}
110
- </AwaitSuspense>
111
- );
112
- }
113
-
114
- export const DelayedLoading = ({
115
- delayLoading,
116
- children,
117
- }: {
118
- delayLoading?: number;
119
- children: ReactNode;
120
- }) => {
121
- const [show, setShow] = useState(false);
122
- const timerSet = useRef(false);
123
-
124
- if (!delayLoading) {
125
- return children;
126
- }
127
-
128
- if (typeof window !== 'undefined' && !show && !timerSet.current) {
129
- timerSet.current = true;
130
- setTimeout(() => {
131
- setShow(true);
132
- }, delayLoading);
133
- }
134
-
135
- return show ? children : null;
136
- };
137
-
138
- function AwaitSuspense<T>({
139
- resolve,
140
- children,
141
- loading = DefaultLoading,
142
- errorElement = DefaultErrorElement,
143
- delayLoading,
144
- }: AwaitErrorHandlerProps<T>) {
145
- return (
146
- <Suspense
147
- fallback={
148
- <DelayedLoading delayLoading={delayLoading}>{loading}</DelayedLoading>
149
- }
150
- >
151
- <ResolveAwait resolve={resolve} errorElement={errorElement}>
152
- {children}
153
- </ResolveAwait>
154
- </Suspense>
155
- );
156
- }
157
-
158
- function ResolveAwait<T>({
159
- children,
160
- resolve,
161
- errorElement,
162
- params,
163
- }: AwaitErrorHandlerProps<T>) {
164
- const data = resolve();
165
- logger.debug('resolve data: ', data);
166
- if (typeof data === 'string' && data.indexOf(AWAIT_ERROR_PREFIX) === 0) {
167
- const transformedError = transformError(data);
168
- return (
169
- <>
170
- {typeof errorElement === 'function' ? (
171
- <>
172
- {globalThis.FEDERATION_SSR && (
173
- <script
174
- suppressHydrationWarning
175
- // eslint-disable-next-line react/no-danger
176
- dangerouslySetInnerHTML={{
177
- __html: String.raw`
178
- globalThis['${DATA_FETCH_FUNCTION}'] = globalThis['${DATA_FETCH_FUNCTION}'] || []
179
- globalThis['${DATA_FETCH_FUNCTION}'].push([${transformedError.dataFetchMapKey ? `'${transformedError.dataFetchMapKey}'` : ''},${params ? JSON.stringify(params) : null},true]);`,
180
- }}
181
- ></script>
182
- )}
183
- {errorElement(transformedError)}
184
- </>
185
- ) : (
186
- errorElement
187
- )}
188
- </>
189
- );
190
- }
191
- const toRender =
192
- typeof children === 'function' ? children(data as T) : children;
193
- return <>{toRender}</>;
194
- }
195
-
196
- // return string when promise is rejected
197
- const fetchData = <T,>(promise: Promise<T>, ref: MutableRefObject<T>) => {
198
- let data: T | string;
199
- let status: 'pending' | 'success' = 'pending';
200
- const suspender = promise
201
- .then((res) => {
202
- status = 'success';
203
- data = res;
204
- ref.current = res;
205
- })
206
- .catch((e) => {
207
- status = 'success';
208
- console.warn(e);
209
- data = AWAIT_ERROR_PREFIX + e;
210
- });
211
- return () => {
212
- if (status === 'pending') {
213
- throw suspender;
214
- }
215
- return data;
216
- };
217
- };
@@ -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: ';