@module-federation/bridge-react 0.16.0 → 0.17.1
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 +39 -0
- package/__tests__/bridge.spec.tsx +10 -10
- package/__tests__/createLazyComponent.spec.tsx +209 -0
- package/__tests__/prefetch.spec.ts +156 -0
- package/__tests__/router.spec.tsx +3 -3
- package/__tests__/setupTests.ts +8 -0
- package/dist/{bridge-base-P6pEjY1q.js → bridge-base-BoshEggF.mjs} +1 -1
- package/dist/{bridge-base-BBH982Tz.cjs → bridge-base-UGCwcMnG.js} +1 -1
- package/dist/data-fetch-server-middleware.cjs.js +163 -0
- package/dist/data-fetch-server-middleware.d.ts +15 -0
- package/dist/data-fetch-server-middleware.es.js +164 -0
- package/dist/data-fetch-utils.cjs.js +24 -0
- package/dist/data-fetch-utils.d.ts +81 -0
- package/dist/data-fetch-utils.es.js +26 -0
- package/dist/index-C0fDZB5b.js +45 -0
- package/dist/index-CqxytsLY.mjs +46 -0
- package/dist/index.cjs.js +35 -9
- package/dist/index.d.ts +141 -1
- package/dist/index.es.js +39 -13
- package/dist/index.esm-BCeUd-x9.mjs +418 -0
- package/dist/index.esm-j_1sIRzg.js +417 -0
- package/dist/lazy-load-component-plugin-B80Ud11k.js +521 -0
- package/dist/lazy-load-component-plugin-_UbR2mWQ.mjs +522 -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.cjs.js +24 -0
- package/dist/lazy-utils.d.ts +149 -0
- package/dist/lazy-utils.es.js +24 -0
- package/dist/plugin.d.ts +13 -4
- package/dist/prefetch-BaKIdUwP.js +1338 -0
- package/dist/prefetch-YpJYjpWC.mjs +1339 -0
- package/dist/router-v5.cjs.js +1 -1
- package/dist/router-v5.d.ts +9 -0
- package/dist/router-v5.es.js +1 -1
- package/dist/router-v6.cjs.js +1 -1
- package/dist/router-v6.d.ts +9 -0
- package/dist/router-v6.es.js +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.d.ts +9 -0
- package/dist/router.es.js +1 -1
- package/dist/utils-C4oPJV34.mjs +2016 -0
- package/dist/utils-iEVlDmyk.js +2015 -0
- package/dist/v18.cjs.js +1 -1
- package/dist/v18.d.ts +9 -0
- package/dist/v18.es.js +1 -1
- package/dist/v19.cjs.js +1 -1
- package/dist/v19.d.ts +9 -0
- package/dist/v19.es.js +1 -1
- package/jest.config.ts +21 -0
- package/package.json +48 -6
- package/project.json +4 -8
- package/src/index.ts +32 -1
- package/src/lazy/AwaitDataFetch.tsx +215 -0
- package/src/lazy/constant.ts +30 -0
- package/src/lazy/createLazyComponent.tsx +411 -0
- package/src/lazy/data-fetch/cache.ts +291 -0
- package/src/lazy/data-fetch/call-data-fetch.ts +13 -0
- package/src/lazy/data-fetch/data-fetch-server-middleware.ts +196 -0
- package/src/lazy/data-fetch/index.ts +16 -0
- package/src/lazy/data-fetch/inject-data-fetch.ts +109 -0
- package/src/lazy/data-fetch/prefetch.ts +106 -0
- package/src/lazy/data-fetch/runtime-plugin.ts +115 -0
- package/src/lazy/index.ts +35 -0
- package/src/lazy/logger.ts +6 -0
- package/src/lazy/types.ts +75 -0
- package/src/lazy/utils.ts +372 -0
- package/src/lazy/wrapNoSSR.tsx +10 -0
- package/src/plugins/lazy-load-component-plugin.spec.ts +21 -0
- package/src/plugins/lazy-load-component-plugin.ts +57 -0
- package/src/provider/plugin.ts +4 -4
- package/src/remote/component.tsx +3 -3
- package/src/remote/create.tsx +18 -5
- package/tsconfig.json +1 -1
- package/tsconfig.spec.json +26 -0
- package/vite.config.ts +13 -0
- package/vitest.config.ts +6 -1
- package/dist/index-Cv3p6r66.cjs +0 -235
- package/dist/index-D4yt7Udv.js +0 -236
- package/src/.eslintrc.js +0 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,92 @@
|
|
|
1
1
|
import { default as default_2 } from 'react';
|
|
2
|
+
import { getInstance } from '@module-federation/runtime';
|
|
3
|
+
import { ModuleFederationRuntimePlugin } from '@module-federation/runtime';
|
|
2
4
|
import * as React_2 from 'react';
|
|
5
|
+
import { ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
export declare const autoFetchDataPlugin: () => ModuleFederationRuntimePlugin;
|
|
8
|
+
|
|
9
|
+
export declare function cache<T>(fn: DataFetch<T>, options?: CacheOptions): DataFetch<T>;
|
|
10
|
+
|
|
11
|
+
declare interface CacheConfig {
|
|
12
|
+
maxSize?: number;
|
|
13
|
+
unstable_shouldDisable?: ({ request, }: {
|
|
14
|
+
request: Request;
|
|
15
|
+
}) => boolean | Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare interface CacheOptions {
|
|
19
|
+
tag?: string | string[];
|
|
20
|
+
maxAge?: number;
|
|
21
|
+
revalidate?: number;
|
|
22
|
+
getKey?: <Args extends any[]>(...args: Args) => string;
|
|
23
|
+
onCache?: (info: CacheStatsInfo) => boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export declare const CacheSize: {
|
|
27
|
+
readonly KB: 1024;
|
|
28
|
+
readonly MB: number;
|
|
29
|
+
readonly GB: number;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export declare interface CacheStatsInfo {
|
|
33
|
+
status: CacheStatus;
|
|
34
|
+
key: string | symbol;
|
|
35
|
+
params: DataFetchParams;
|
|
36
|
+
result: any;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export declare type CacheStatus = 'hit' | 'stale' | 'miss';
|
|
40
|
+
|
|
41
|
+
export declare const CacheTime: {
|
|
42
|
+
readonly SECOND: 1000;
|
|
43
|
+
readonly MINUTE: number;
|
|
44
|
+
readonly HOUR: number;
|
|
45
|
+
readonly DAY: number;
|
|
46
|
+
readonly WEEK: number;
|
|
47
|
+
readonly MONTH: number;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export declare function callDataFetch(): Promise<void>;
|
|
51
|
+
|
|
52
|
+
export declare function clearStore(): void;
|
|
53
|
+
|
|
54
|
+
export declare function collectSSRAssets(options: CollectSSRAssetsOptions): default_2.ReactNode[];
|
|
55
|
+
|
|
56
|
+
export declare type CollectSSRAssetsOptions = {
|
|
57
|
+
id: string;
|
|
58
|
+
instance: ReturnType<typeof getInstance>;
|
|
59
|
+
injectScript?: boolean;
|
|
60
|
+
injectLink?: boolean;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export declare function configureCache(config: CacheConfig): void;
|
|
3
64
|
|
|
4
65
|
export declare function createBridgeComponent<T = any>(bridgeInfo: Omit<ProviderFnParams<T>, 'createRoot'>): () => {
|
|
5
66
|
render(info: RenderParams): Promise<void>;
|
|
6
67
|
destroy(info: DestroyParams): void;
|
|
7
68
|
};
|
|
8
69
|
|
|
70
|
+
export declare function createLazyComponent<T, E extends keyof T>(options: CreateLazyComponentOptions<T, E>): (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? ReactKey : Parameters<T[E]>[0] & ReactKey : ReactKey) => default_2.JSX.Element;
|
|
71
|
+
|
|
72
|
+
export declare type CreateLazyComponentOptions<T, E extends keyof T> = {
|
|
73
|
+
loader: () => Promise<T>;
|
|
74
|
+
instance: ReturnType<typeof getInstance>;
|
|
75
|
+
loading: default_2.ReactNode;
|
|
76
|
+
delayLoading?: number;
|
|
77
|
+
fallback: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
|
|
78
|
+
export?: E;
|
|
79
|
+
dataFetchParams?: DataFetchParams;
|
|
80
|
+
noSSR?: boolean;
|
|
81
|
+
injectScript?: boolean;
|
|
82
|
+
injectLink?: boolean;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export declare function createRemoteAppComponent<T = Record<string, unknown>, E extends keyof T = keyof T>(info: LazyRemoteComponentInfo<T, E>): default_2.ForwardRefExoticComponent<Omit<RemoteComponentProps<Record<string, unknown>>, "ref"> & default_2.RefAttributes<HTMLDivElement>>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @deprecated createRemoteAppComponent is deprecated, please use createRemoteAppComponent instead!
|
|
89
|
+
*/
|
|
9
90
|
export declare function createRemoteComponent<T = Record<string, unknown>, E extends keyof T = keyof T>(info: LazyRemoteComponentInfo<T, E>): default_2.ForwardRefExoticComponent<Omit<RemoteComponentProps<Record<string, unknown>>, "ref"> & default_2.RefAttributes<HTMLDivElement>>;
|
|
10
91
|
|
|
11
92
|
export declare interface CreateRootOptions {
|
|
@@ -22,6 +103,13 @@ declare interface CreateRootOptions_2 {
|
|
|
22
103
|
transitionCallbacks?: unknown;
|
|
23
104
|
}
|
|
24
105
|
|
|
106
|
+
declare type DataFetch<T> = (params: DataFetchParams) => Promise<T>;
|
|
107
|
+
|
|
108
|
+
export declare type DataFetchParams = {
|
|
109
|
+
isDowngrade: boolean;
|
|
110
|
+
_id?: string;
|
|
111
|
+
} & Record<string, unknown>;
|
|
112
|
+
|
|
25
113
|
/**
|
|
26
114
|
* Parameters for the destroy function
|
|
27
115
|
*/
|
|
@@ -30,7 +118,40 @@ export declare interface DestroyParams {
|
|
|
30
118
|
dom: HTMLElement;
|
|
31
119
|
}
|
|
32
120
|
|
|
33
|
-
declare
|
|
121
|
+
export declare const ERROR_TYPE: {
|
|
122
|
+
DATA_FETCH: number;
|
|
123
|
+
LOAD_REMOTE: number;
|
|
124
|
+
UNKNOWN: number;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
declare type ErrorInfo = {
|
|
128
|
+
error: Error;
|
|
129
|
+
errorType: number;
|
|
130
|
+
dataFetchMapKey?: string;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export declare function generateKey(dataFetchOptions: DataFetchParams): string;
|
|
134
|
+
|
|
135
|
+
export declare function lazyLoadComponentPlugin(): ModuleFederationRuntimePlugin;
|
|
136
|
+
|
|
137
|
+
declare type LazyRemoteComponentInfo<T, _E extends keyof T> = RemoteComponentParams<T>;
|
|
138
|
+
|
|
139
|
+
export declare type NoSSRRemoteInfo = {
|
|
140
|
+
name: string;
|
|
141
|
+
version: string;
|
|
142
|
+
ssrPublicPath: string;
|
|
143
|
+
ssrRemoteEntry: string;
|
|
144
|
+
globalName: string;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export declare function prefetch(options: PrefetchOptions): Promise<void>;
|
|
148
|
+
|
|
149
|
+
declare type PrefetchOptions = {
|
|
150
|
+
id: string;
|
|
151
|
+
instance: ReturnType<typeof getInstance>;
|
|
152
|
+
dataFetchParams?: DataFetchParams;
|
|
153
|
+
preloadComponentResource?: boolean;
|
|
154
|
+
};
|
|
34
155
|
|
|
35
156
|
/**
|
|
36
157
|
* Parameters for the provider function
|
|
@@ -65,6 +186,10 @@ export declare interface ProviderParams {
|
|
|
65
186
|
className?: string;
|
|
66
187
|
}
|
|
67
188
|
|
|
189
|
+
declare type ReactKey = {
|
|
190
|
+
key?: default_2.Key | null;
|
|
191
|
+
};
|
|
192
|
+
|
|
68
193
|
/**
|
|
69
194
|
* Parameters for the remote component loader
|
|
70
195
|
*/
|
|
@@ -113,6 +238,8 @@ export declare interface RenderParams {
|
|
|
113
238
|
[key: string]: unknown;
|
|
114
239
|
}
|
|
115
240
|
|
|
241
|
+
export declare function revalidateTag(tag: string): void;
|
|
242
|
+
|
|
116
243
|
export declare interface Root {
|
|
117
244
|
render(children: React.ReactNode): void;
|
|
118
245
|
unmount(): void;
|
|
@@ -131,4 +258,17 @@ declare interface Root_2 {
|
|
|
131
258
|
*/
|
|
132
259
|
export declare type RootType = HTMLElement | Root_2;
|
|
133
260
|
|
|
261
|
+
export declare function setSSREnv({ fetchServerQuery, }: {
|
|
262
|
+
fetchServerQuery?: Record<string, unknown>;
|
|
263
|
+
}): void;
|
|
264
|
+
|
|
134
265
|
export { }
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
declare module '@module-federation/runtime-core' {
|
|
269
|
+
interface ModuleFederation {
|
|
270
|
+
createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
|
|
271
|
+
prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
|
|
272
|
+
collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
|
|
273
|
+
}
|
|
274
|
+
}
|
package/dist/index.es.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { c as createBaseBridgeComponent, E as ErrorBoundary } from "./bridge-base-
|
|
1
|
+
import { c as createBaseBridgeComponent, E as ErrorBoundary } from "./bridge-base-BoshEggF.mjs";
|
|
2
2
|
import ReactDOM from "react-dom";
|
|
3
|
-
import React__default, { forwardRef,
|
|
4
|
-
import {
|
|
3
|
+
import React__default, { forwardRef, useContext, useState, useEffect, useRef } from "react";
|
|
4
|
+
import { p as pathJoin, L as LoggerInstance, g as getRootDomDefaultClassName } from "./index-CqxytsLY.mjs";
|
|
5
5
|
import * as ReactRouterDOM from "react-router-dom";
|
|
6
6
|
import { federationRuntime } from "./plugin.es.js";
|
|
7
|
+
import { b, a, c, l } from "./lazy-load-component-plugin-_UbR2mWQ.mjs";
|
|
8
|
+
import { C, b as b2, E, e, h, c as c2, d, r, s } from "./utils-C4oPJV34.mjs";
|
|
9
|
+
import { callDataFetch } from "./data-fetch-utils.es.js";
|
|
10
|
+
import { p } from "./prefetch-YpJYjpWC.mjs";
|
|
7
11
|
function createReact16Or17Root(container) {
|
|
8
12
|
return {
|
|
9
13
|
render(children) {
|
|
@@ -34,7 +38,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
34
38
|
};
|
|
35
39
|
return createBaseBridgeComponent(fullBridgeInfo);
|
|
36
40
|
}
|
|
37
|
-
function
|
|
41
|
+
function e2() {
|
|
38
42
|
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
39
43
|
window.dispatchEvent(t);
|
|
40
44
|
}
|
|
@@ -64,7 +68,7 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
64
68
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
65
69
|
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
66
70
|
LoggerInstance.debug(
|
|
67
|
-
`
|
|
71
|
+
`createRemoteAppComponent LazyComponent destroy >>>`,
|
|
68
72
|
{ moduleName, basename, dom: renderDom.current }
|
|
69
73
|
);
|
|
70
74
|
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
@@ -152,7 +156,7 @@ function withRouterData(WrappedComponent) {
|
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
}
|
|
155
|
-
LoggerInstance.debug(`
|
|
159
|
+
LoggerInstance.debug(`createRemoteAppComponent withRouterData >>>`, {
|
|
156
160
|
...props,
|
|
157
161
|
basename,
|
|
158
162
|
routerContextVal,
|
|
@@ -164,13 +168,13 @@ function withRouterData(WrappedComponent) {
|
|
|
164
168
|
useEffect(() => {
|
|
165
169
|
if (pathname !== "" && pathname !== location.pathname) {
|
|
166
170
|
LoggerInstance.debug(
|
|
167
|
-
`
|
|
171
|
+
`createRemoteAppComponent dispatchPopstateEnv >>>`,
|
|
168
172
|
{
|
|
169
173
|
name: props.name,
|
|
170
174
|
pathname: location.pathname
|
|
171
175
|
}
|
|
172
176
|
);
|
|
173
|
-
|
|
177
|
+
e2();
|
|
174
178
|
}
|
|
175
179
|
setPathname(location.pathname);
|
|
176
180
|
}, [location]);
|
|
@@ -185,7 +189,7 @@ const RemoteApp = withRouterData(RemoteAppWrapper);
|
|
|
185
189
|
function createLazyRemoteComponent(info) {
|
|
186
190
|
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
187
191
|
return React__default.lazy(async () => {
|
|
188
|
-
LoggerInstance.debug(`
|
|
192
|
+
LoggerInstance.debug(`createRemoteAppComponent LazyComponent create >>>`, {
|
|
189
193
|
lazyComponent: info.loader,
|
|
190
194
|
exportName
|
|
191
195
|
});
|
|
@@ -193,7 +197,7 @@ function createLazyRemoteComponent(info) {
|
|
|
193
197
|
const m = await info.loader();
|
|
194
198
|
const moduleName = m && m[Symbol.for("mf_module_id")];
|
|
195
199
|
LoggerInstance.debug(
|
|
196
|
-
`
|
|
200
|
+
`createRemoteAppComponent LazyComponent loadRemote info >>>`,
|
|
197
201
|
{ name: moduleName, module: m, exportName }
|
|
198
202
|
);
|
|
199
203
|
const exportFn = m[exportName];
|
|
@@ -216,7 +220,7 @@ function createLazyRemoteComponent(info) {
|
|
|
216
220
|
};
|
|
217
221
|
} else {
|
|
218
222
|
LoggerInstance.debug(
|
|
219
|
-
`
|
|
223
|
+
`createRemoteAppComponent LazyComponent module not found >>>`,
|
|
220
224
|
{ name: moduleName, module: m, exportName }
|
|
221
225
|
);
|
|
222
226
|
throw Error(
|
|
@@ -230,7 +234,7 @@ function createLazyRemoteComponent(info) {
|
|
|
230
234
|
}
|
|
231
235
|
});
|
|
232
236
|
}
|
|
233
|
-
function
|
|
237
|
+
function createRemoteAppComponent(info) {
|
|
234
238
|
const LazyComponent = createLazyRemoteComponent(info);
|
|
235
239
|
return forwardRef((props, ref) => {
|
|
236
240
|
return /* @__PURE__ */ React__default.createElement(
|
|
@@ -242,7 +246,29 @@ function createRemoteComponent(info) {
|
|
|
242
246
|
);
|
|
243
247
|
});
|
|
244
248
|
}
|
|
249
|
+
function createRemoteComponent(info) {
|
|
250
|
+
LoggerInstance.warn(
|
|
251
|
+
`createRemoteAppComponent is deprecated, please use createRemoteAppComponent instead!`
|
|
252
|
+
);
|
|
253
|
+
return createRemoteAppComponent(info);
|
|
254
|
+
}
|
|
245
255
|
export {
|
|
256
|
+
C as CacheSize,
|
|
257
|
+
b2 as CacheTime,
|
|
258
|
+
E as ERROR_TYPE,
|
|
259
|
+
b as autoFetchDataPlugin,
|
|
260
|
+
e as cache,
|
|
261
|
+
callDataFetch,
|
|
262
|
+
h as clearStore,
|
|
263
|
+
a as collectSSRAssets,
|
|
264
|
+
c2 as configureCache,
|
|
246
265
|
createBridgeComponent,
|
|
247
|
-
|
|
266
|
+
c as createLazyComponent,
|
|
267
|
+
createRemoteAppComponent,
|
|
268
|
+
createRemoteComponent,
|
|
269
|
+
d as generateKey,
|
|
270
|
+
l as lazyLoadComponentPlugin,
|
|
271
|
+
p as prefetch,
|
|
272
|
+
r as revalidateTag,
|
|
273
|
+
s as setSSREnv
|
|
248
274
|
};
|