@module-federation/bridge-react 0.21.6 → 0.22.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.
- package/CHANGELOG.md +7 -0
- package/dist/base.cjs.js +29 -0
- package/dist/base.d.ts +311 -0
- package/dist/base.es.js +30 -0
- package/dist/createHelpers-B_L612IN.js +190 -0
- package/dist/createHelpers-Ui5pt7je.mjs +191 -0
- package/dist/data-fetch-server-middleware.es.js +1 -1
- package/dist/data-fetch-utils.cjs.js +1 -1
- package/dist/data-fetch-utils.es.js +8 -8
- package/dist/index.cjs.js +10 -178
- package/dist/index.d.ts +5 -3
- package/dist/index.es.js +19 -186
- package/dist/{lazy-load-component-plugin-CxWa3Efv.mjs → lazy-load-component-plugin-BkcO9pUC.mjs} +2 -2
- package/dist/{lazy-load-component-plugin-DMaHklzL.js → lazy-load-component-plugin-Bt990iJq.js} +1 -1
- package/dist/lazy-load-component-plugin.cjs.js +2 -2
- package/dist/lazy-load-component-plugin.es.js +2 -2
- package/dist/lazy-utils.es.js +3 -3
- package/dist/{prefetch-CiUoylUM.js → prefetch-D-d4LlJ3.js} +1 -1
- package/dist/{prefetch-BUGM-Vgt.mjs → prefetch-DAwiqbcO.mjs} +2 -2
- package/dist/{utils-Bx_8GGd-.mjs → utils-dUgb9Jkm.mjs} +6 -6
- package/package.json +13 -5
- package/src/base.ts +50 -0
- package/src/index.ts +2 -2
- package/src/remote/RemoteAppWrapper.tsx +108 -0
- package/src/remote/base-component/component.tsx +2 -0
- package/src/remote/base-component/create.tsx +23 -0
- package/src/remote/base-component/index.tsx +10 -0
- package/src/remote/createHelpers.tsx +130 -0
- package/src/remote/{component.tsx → router-component/component.tsx} +3 -110
- package/src/remote/router-component/create.tsx +23 -0
- package/src/remote/router-component/index.tsx +10 -0
- package/vite.config.ts +1 -0
- package/src/remote/create.tsx +0 -106
package/CHANGELOG.md
CHANGED
package/dist/base.cjs.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const createHelpers = require("./createHelpers-B_L612IN.js");
|
|
4
|
+
const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-Bt990iJq.js");
|
|
5
|
+
const lazyUtils = require("./utils-tM9yE73c.js");
|
|
6
|
+
const dataFetchUtils = require("./data-fetch-utils.cjs.js");
|
|
7
|
+
const prefetch = require("./prefetch-D-d4LlJ3.js");
|
|
8
|
+
const createRemoteAppComponent = createHelpers.createRemoteAppComponentFactory(createHelpers.RemoteAppWrapper);
|
|
9
|
+
const createRemoteComponent = createHelpers.createDeprecatedRemoteComponentFactory(
|
|
10
|
+
createRemoteAppComponent
|
|
11
|
+
);
|
|
12
|
+
exports.createBridgeComponent = createHelpers.createBridgeComponent;
|
|
13
|
+
exports.autoFetchDataPlugin = lazyLoadComponentPlugin.autoFetchData;
|
|
14
|
+
exports.collectSSRAssets = lazyLoadComponentPlugin.collectSSRAssets;
|
|
15
|
+
exports.createLazyComponent = lazyLoadComponentPlugin.createLazyComponent;
|
|
16
|
+
exports.lazyLoadComponentPlugin = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
|
|
17
|
+
exports.CacheSize = lazyUtils.CacheSize;
|
|
18
|
+
exports.CacheTime = lazyUtils.CacheTime;
|
|
19
|
+
exports.ERROR_TYPE = lazyUtils.ERROR_TYPE;
|
|
20
|
+
exports.cache = lazyUtils.cache;
|
|
21
|
+
exports.clearStore = lazyUtils.clearStore;
|
|
22
|
+
exports.configureCache = lazyUtils.configureCache;
|
|
23
|
+
exports.generateKey = lazyUtils.generateKey;
|
|
24
|
+
exports.revalidateTag = lazyUtils.revalidateTag;
|
|
25
|
+
exports.setSSREnv = lazyUtils.setSSREnv;
|
|
26
|
+
exports.callDataFetch = dataFetchUtils.callDataFetch;
|
|
27
|
+
exports.prefetch = prefetch.prefetch;
|
|
28
|
+
exports.createRemoteAppComponent = createRemoteAppComponent;
|
|
29
|
+
exports.createRemoteComponent = createRemoteComponent;
|
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { default as default_2 } from 'react';
|
|
2
|
+
import { ForwardRefExoticComponent } from 'react';
|
|
3
|
+
import { getInstance } from '@module-federation/runtime';
|
|
4
|
+
import { ModuleFederationRuntimePlugin } from '@module-federation/runtime';
|
|
5
|
+
import * as React_2 from 'react';
|
|
6
|
+
import { ReactNode } from 'react';
|
|
7
|
+
import { RefAttributes } from 'react';
|
|
8
|
+
|
|
9
|
+
export declare const autoFetchDataPlugin: () => ModuleFederationRuntimePlugin;
|
|
10
|
+
|
|
11
|
+
export declare function cache<T>(fn: DataFetch<T>, options?: CacheOptions): DataFetch<T>;
|
|
12
|
+
|
|
13
|
+
declare interface CacheConfig {
|
|
14
|
+
maxSize?: number;
|
|
15
|
+
unstable_shouldDisable?: ({ request, }: {
|
|
16
|
+
request: Request;
|
|
17
|
+
}) => boolean | Promise<boolean>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare interface CacheOptions {
|
|
21
|
+
tag?: string | string[];
|
|
22
|
+
maxAge?: number;
|
|
23
|
+
revalidate?: number;
|
|
24
|
+
getKey?: <Args extends any[]>(...args: Args) => string;
|
|
25
|
+
onCache?: (info: CacheStatsInfo) => boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export declare const CacheSize: {
|
|
29
|
+
readonly KB: 1024;
|
|
30
|
+
readonly MB: number;
|
|
31
|
+
readonly GB: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export declare interface CacheStatsInfo {
|
|
35
|
+
status: CacheStatus;
|
|
36
|
+
key: string | symbol;
|
|
37
|
+
params: DataFetchParams;
|
|
38
|
+
result: any;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export declare type CacheStatus = 'hit' | 'stale' | 'miss';
|
|
42
|
+
|
|
43
|
+
export declare const CacheTime: {
|
|
44
|
+
readonly SECOND: 1000;
|
|
45
|
+
readonly MINUTE: number;
|
|
46
|
+
readonly HOUR: number;
|
|
47
|
+
readonly DAY: number;
|
|
48
|
+
readonly WEEK: number;
|
|
49
|
+
readonly MONTH: number;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export declare function callDataFetch(): Promise<void>;
|
|
53
|
+
|
|
54
|
+
export declare function clearStore(): void;
|
|
55
|
+
|
|
56
|
+
export declare function collectSSRAssets(options: CollectSSRAssetsOptions): default_2.ReactNode[];
|
|
57
|
+
|
|
58
|
+
export declare type CollectSSRAssetsOptions = {
|
|
59
|
+
id: string;
|
|
60
|
+
instance: ReturnType<typeof getInstance>;
|
|
61
|
+
injectScript?: boolean;
|
|
62
|
+
injectLink?: boolean;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export declare function configureCache(config: CacheConfig): void;
|
|
66
|
+
|
|
67
|
+
export declare function createBridgeComponent<T = any>(bridgeInfo: Omit<ProviderFnParams<T>, 'createRoot'>): () => {
|
|
68
|
+
render(info: RenderParams): Promise<void>;
|
|
69
|
+
destroy(info: DestroyParams): void;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
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;
|
|
73
|
+
|
|
74
|
+
export declare type CreateLazyComponentOptions<T, E extends keyof T> = {
|
|
75
|
+
loader: () => Promise<T>;
|
|
76
|
+
instance: ReturnType<typeof getInstance>;
|
|
77
|
+
loading: default_2.ReactNode;
|
|
78
|
+
delayLoading?: number;
|
|
79
|
+
fallback: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
|
|
80
|
+
export?: E;
|
|
81
|
+
dataFetchParams?: DataFetchParams;
|
|
82
|
+
noSSR?: boolean;
|
|
83
|
+
injectScript?: boolean;
|
|
84
|
+
injectLink?: boolean;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export declare const createRemoteAppComponent: <T = Record<string, unknown>, E extends keyof T = keyof T>(info: LazyRemoteComponentInfo<T, E>) => ForwardRefExoticComponent<Omit<RemoteComponentProps_2<Record<string, unknown>>, "ref"> & RefAttributes<HTMLDivElement>>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated createRemoteComponent is deprecated, please use createRemoteAppComponent instead!
|
|
91
|
+
*/
|
|
92
|
+
export declare const createRemoteComponent: <T = Record<string, unknown>, E extends keyof T = keyof T>(info: LazyRemoteComponentInfo<T, E>) => any;
|
|
93
|
+
|
|
94
|
+
export declare interface CreateRootOptions {
|
|
95
|
+
identifierPrefix?: string;
|
|
96
|
+
onRecoverableError?: (error: unknown, errorInfo: unknown) => void;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Options for creating a React root
|
|
101
|
+
*/
|
|
102
|
+
declare interface CreateRootOptions_2 {
|
|
103
|
+
identifierPrefix?: string;
|
|
104
|
+
onRecoverableError?: (error: unknown) => void;
|
|
105
|
+
transitionCallbacks?: unknown;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
declare type DataFetch<T> = (params: DataFetchParams) => Promise<T>;
|
|
109
|
+
|
|
110
|
+
export declare type DataFetchParams = {
|
|
111
|
+
isDowngrade: boolean;
|
|
112
|
+
_id?: string;
|
|
113
|
+
} & Record<string, unknown>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Parameters for the destroy function
|
|
117
|
+
*/
|
|
118
|
+
export declare interface DestroyParams {
|
|
119
|
+
moduleName: string;
|
|
120
|
+
dom: HTMLElement;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export declare const ERROR_TYPE: {
|
|
124
|
+
DATA_FETCH: number;
|
|
125
|
+
LOAD_REMOTE: number;
|
|
126
|
+
UNKNOWN: number;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
declare type ErrorInfo = {
|
|
130
|
+
error: Error;
|
|
131
|
+
errorType: number;
|
|
132
|
+
dataFetchMapKey?: string;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export declare function generateKey(dataFetchOptions: DataFetchParams): string;
|
|
136
|
+
|
|
137
|
+
export declare function lazyLoadComponentPlugin(): ModuleFederationRuntimePlugin;
|
|
138
|
+
|
|
139
|
+
export declare type LazyRemoteComponentInfo<T, _E extends keyof T> = RemoteComponentParams<T>;
|
|
140
|
+
|
|
141
|
+
export declare type NoSSRRemoteInfo = {
|
|
142
|
+
name: string;
|
|
143
|
+
version: string;
|
|
144
|
+
ssrPublicPath: string;
|
|
145
|
+
ssrRemoteEntry: string;
|
|
146
|
+
globalName: string;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export declare function prefetch(options: PrefetchOptions): Promise<void>;
|
|
150
|
+
|
|
151
|
+
declare type PrefetchOptions = {
|
|
152
|
+
id: string;
|
|
153
|
+
instance: ReturnType<typeof getInstance>;
|
|
154
|
+
dataFetchParams?: DataFetchParams;
|
|
155
|
+
preloadComponentResource?: boolean;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Parameters for the provider function
|
|
160
|
+
*/
|
|
161
|
+
export declare interface ProviderFnParams<T> {
|
|
162
|
+
rootComponent: React_2.ComponentType<T>;
|
|
163
|
+
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
164
|
+
createRoot?: (container: Element | DocumentFragment, options?: CreateRootOptions_2) => Root_2;
|
|
165
|
+
/**
|
|
166
|
+
* Default options to pass to createRoot for React 18 and 19
|
|
167
|
+
* These options will be used when creating a root unless overridden by rootOptions in render params
|
|
168
|
+
* @example
|
|
169
|
+
* {
|
|
170
|
+
* identifierPrefix: 'app-',
|
|
171
|
+
* onRecoverableError: (err) => console.error(err)
|
|
172
|
+
* }
|
|
173
|
+
*/
|
|
174
|
+
defaultRootOptions?: CreateRootOptions_2;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Parameters for the provider function
|
|
179
|
+
*/
|
|
180
|
+
export declare interface ProviderParams {
|
|
181
|
+
moduleName?: string;
|
|
182
|
+
basename?: string;
|
|
183
|
+
memoryRoute?: {
|
|
184
|
+
entryPath: string;
|
|
185
|
+
initialState?: Record<string, unknown>;
|
|
186
|
+
};
|
|
187
|
+
style?: React_2.CSSProperties;
|
|
188
|
+
className?: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
declare type ReactKey = {
|
|
192
|
+
key?: default_2.Key | null;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Parameters for the remote component loader
|
|
197
|
+
*/
|
|
198
|
+
export declare interface RemoteComponentParams<T = Record<string, unknown>, E extends keyof T = keyof T> {
|
|
199
|
+
loader: () => Promise<T>;
|
|
200
|
+
loading: React_2.ReactNode;
|
|
201
|
+
fallback: React_2.ComponentType<{
|
|
202
|
+
error: Error;
|
|
203
|
+
}>;
|
|
204
|
+
export?: E;
|
|
205
|
+
props?: T;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Parameters for the remote component
|
|
210
|
+
*/
|
|
211
|
+
export declare interface RemoteComponentProps<T = Record<string, unknown>> {
|
|
212
|
+
props?: T;
|
|
213
|
+
fallback?: React_2.ComponentType<{
|
|
214
|
+
error: Error;
|
|
215
|
+
}>;
|
|
216
|
+
loading?: React_2.ReactNode;
|
|
217
|
+
[key: string]: unknown;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Parameters for the remote component
|
|
222
|
+
*/
|
|
223
|
+
declare interface RemoteComponentProps_2<T = Record<string, unknown>> {
|
|
224
|
+
props?: T;
|
|
225
|
+
fallback?: React_2.ComponentType<{
|
|
226
|
+
error: Error;
|
|
227
|
+
}>;
|
|
228
|
+
loading?: React_2.ReactNode;
|
|
229
|
+
[key: string]: unknown;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Interface for a remote module provider
|
|
234
|
+
*/
|
|
235
|
+
export declare interface RemoteModule {
|
|
236
|
+
provider: () => {
|
|
237
|
+
render: (info: RenderFnParams) => void;
|
|
238
|
+
destroy: (info: {
|
|
239
|
+
dom: any;
|
|
240
|
+
}) => void;
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Parameters for the render function, extending ProviderParams
|
|
246
|
+
*/
|
|
247
|
+
export declare interface RenderFnParams extends ProviderParams {
|
|
248
|
+
dom: HTMLElement;
|
|
249
|
+
fallback?: React_2.ComponentType<{
|
|
250
|
+
error: Error;
|
|
251
|
+
}>;
|
|
252
|
+
[key: string]: unknown;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Parameters for the render function
|
|
257
|
+
*/
|
|
258
|
+
export declare interface RenderParams {
|
|
259
|
+
moduleName?: string;
|
|
260
|
+
basename?: string;
|
|
261
|
+
memoryRoute?: {
|
|
262
|
+
entryPath: string;
|
|
263
|
+
initialState?: Record<string, unknown>;
|
|
264
|
+
};
|
|
265
|
+
dom: HTMLElement;
|
|
266
|
+
/**
|
|
267
|
+
* Options to pass to createRoot for React 18 and 19
|
|
268
|
+
* @example
|
|
269
|
+
* {
|
|
270
|
+
* identifierPrefix: 'app-',
|
|
271
|
+
* onRecoverableError: (err) => console.error(err)
|
|
272
|
+
* }
|
|
273
|
+
*/
|
|
274
|
+
rootOptions?: CreateRootOptions_2;
|
|
275
|
+
[key: string]: unknown;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export declare function revalidateTag(tag: string): void;
|
|
279
|
+
|
|
280
|
+
export declare interface Root {
|
|
281
|
+
render(children: React.ReactNode): void;
|
|
282
|
+
unmount(): void;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Interface for a React root object
|
|
287
|
+
*/
|
|
288
|
+
declare interface Root_2 {
|
|
289
|
+
render(children: React_2.ReactNode): void;
|
|
290
|
+
unmount(): void;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Type for a root element, which can be either an HTMLElement or a React root
|
|
295
|
+
*/
|
|
296
|
+
export declare type RootType = HTMLElement | Root_2;
|
|
297
|
+
|
|
298
|
+
export declare function setSSREnv({ fetchServerQuery, }: {
|
|
299
|
+
fetchServerQuery?: Record<string, unknown>;
|
|
300
|
+
}): void;
|
|
301
|
+
|
|
302
|
+
export { }
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
declare module '@module-federation/runtime-core' {
|
|
306
|
+
interface ModuleFederation {
|
|
307
|
+
createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
|
|
308
|
+
prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
|
|
309
|
+
collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
|
|
310
|
+
}
|
|
311
|
+
}
|
package/dist/base.es.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { c as createDeprecatedRemoteComponentFactory, a as createRemoteAppComponentFactory, R as RemoteAppWrapper } from "./createHelpers-Ui5pt7je.mjs";
|
|
2
|
+
import { b } from "./createHelpers-Ui5pt7je.mjs";
|
|
3
|
+
import { b as b2, a, c, l } from "./lazy-load-component-plugin-BkcO9pUC.mjs";
|
|
4
|
+
import { C, a as a2, E, b as b3, d, c as c2, g, r, s } from "./utils-dUgb9Jkm.mjs";
|
|
5
|
+
import { callDataFetch } from "./data-fetch-utils.es.js";
|
|
6
|
+
import { p } from "./prefetch-DAwiqbcO.mjs";
|
|
7
|
+
const createRemoteAppComponent = createRemoteAppComponentFactory(RemoteAppWrapper);
|
|
8
|
+
const createRemoteComponent = createDeprecatedRemoteComponentFactory(
|
|
9
|
+
createRemoteAppComponent
|
|
10
|
+
);
|
|
11
|
+
export {
|
|
12
|
+
C as CacheSize,
|
|
13
|
+
a2 as CacheTime,
|
|
14
|
+
E as ERROR_TYPE,
|
|
15
|
+
b2 as autoFetchDataPlugin,
|
|
16
|
+
b3 as cache,
|
|
17
|
+
callDataFetch,
|
|
18
|
+
d as clearStore,
|
|
19
|
+
a as collectSSRAssets,
|
|
20
|
+
c2 as configureCache,
|
|
21
|
+
b as createBridgeComponent,
|
|
22
|
+
c as createLazyComponent,
|
|
23
|
+
createRemoteAppComponent,
|
|
24
|
+
createRemoteComponent,
|
|
25
|
+
g as generateKey,
|
|
26
|
+
l as lazyLoadComponentPlugin,
|
|
27
|
+
p as prefetch,
|
|
28
|
+
r as revalidateTag,
|
|
29
|
+
s as setSSREnv
|
|
30
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const bridgeBase = require("./bridge-base-RStDxH71.js");
|
|
3
|
+
const ReactDOM = require("react-dom");
|
|
4
|
+
const index = require("./index-DRSBaSu3.js");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const plugin = require("./plugin.cjs.js");
|
|
7
|
+
function createReact16Or17Root(container) {
|
|
8
|
+
return {
|
|
9
|
+
render(children) {
|
|
10
|
+
const reactVersion = ReactDOM.version || "";
|
|
11
|
+
const isReact18 = reactVersion.startsWith("18");
|
|
12
|
+
const isReact19 = reactVersion.startsWith("19");
|
|
13
|
+
if (isReact19) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
`React 19 detected in legacy mode. This is not supported. Please use the version-specific import: import { createBridgeComponent } from '@module-federation/bridge-react/v19'`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
if (isReact18) {
|
|
19
|
+
index.LoggerInstance.warn(
|
|
20
|
+
`[Bridge-React] React 18 detected in legacy mode. For better compatibility, please use the version-specific import: import { createBridgeComponent } from '@module-federation/bridge-react/v18'`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
ReactDOM.render(children, container);
|
|
24
|
+
},
|
|
25
|
+
unmount() {
|
|
26
|
+
ReactDOM.unmountComponentAtNode(container);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function createBridgeComponent(bridgeInfo) {
|
|
31
|
+
const fullBridgeInfo = {
|
|
32
|
+
createRoot: createReact16Or17Root,
|
|
33
|
+
...bridgeInfo
|
|
34
|
+
};
|
|
35
|
+
return bridgeBase.createBaseBridgeComponent(fullBridgeInfo);
|
|
36
|
+
}
|
|
37
|
+
const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
38
|
+
const {
|
|
39
|
+
moduleName,
|
|
40
|
+
memoryRoute,
|
|
41
|
+
basename,
|
|
42
|
+
providerInfo,
|
|
43
|
+
className,
|
|
44
|
+
style,
|
|
45
|
+
fallback,
|
|
46
|
+
loading,
|
|
47
|
+
...resProps
|
|
48
|
+
} = props;
|
|
49
|
+
const instance = plugin.federationRuntime.instance;
|
|
50
|
+
const rootRef = ref && "current" in ref ? ref : React.useRef(null);
|
|
51
|
+
const renderDom = React.useRef(null);
|
|
52
|
+
const providerInfoRef = React.useRef(null);
|
|
53
|
+
const [initialized, setInitialized] = React.useState(false);
|
|
54
|
+
index.LoggerInstance.debug(`RemoteAppWrapper instance from props >>>`, instance);
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
if (initialized) return;
|
|
57
|
+
const providerReturn = providerInfo();
|
|
58
|
+
providerInfoRef.current = providerReturn;
|
|
59
|
+
setInitialized(true);
|
|
60
|
+
return () => {
|
|
61
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
62
|
+
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
63
|
+
index.LoggerInstance.debug(
|
|
64
|
+
`createRemoteAppComponent LazyComponent destroy >>>`,
|
|
65
|
+
{ moduleName, basename, dom: renderDom.current }
|
|
66
|
+
);
|
|
67
|
+
(_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
|
|
68
|
+
moduleName,
|
|
69
|
+
dom: renderDom.current,
|
|
70
|
+
basename,
|
|
71
|
+
memoryRoute,
|
|
72
|
+
fallback,
|
|
73
|
+
...resProps
|
|
74
|
+
});
|
|
75
|
+
(_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
|
|
76
|
+
moduleName,
|
|
77
|
+
dom: renderDom.current
|
|
78
|
+
});
|
|
79
|
+
(_h = (_g = (_f = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
|
|
80
|
+
moduleName,
|
|
81
|
+
dom: renderDom.current,
|
|
82
|
+
basename,
|
|
83
|
+
memoryRoute,
|
|
84
|
+
fallback,
|
|
85
|
+
...resProps
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}, [moduleName]);
|
|
90
|
+
React.useEffect(() => {
|
|
91
|
+
var _a, _b, _c, _d, _e, _f;
|
|
92
|
+
if (!initialized || !providerInfoRef.current) return;
|
|
93
|
+
let renderProps = {
|
|
94
|
+
moduleName,
|
|
95
|
+
dom: rootRef.current,
|
|
96
|
+
basename,
|
|
97
|
+
memoryRoute,
|
|
98
|
+
fallback,
|
|
99
|
+
...resProps
|
|
100
|
+
};
|
|
101
|
+
renderDom.current = rootRef.current;
|
|
102
|
+
const beforeBridgeRenderRes = ((_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(renderProps)) || {};
|
|
103
|
+
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
|
|
104
|
+
providerInfoRef.current.render(renderProps);
|
|
105
|
+
(_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(renderProps);
|
|
106
|
+
}, [initialized, ...Object.values(props)]);
|
|
107
|
+
const rootComponentClassName = `${index.getRootDomDefaultClassName(moduleName)} ${className || ""}`;
|
|
108
|
+
return /* @__PURE__ */ React.createElement("div", { className: rootComponentClassName, style, ref: rootRef }, loading);
|
|
109
|
+
});
|
|
110
|
+
function createLazyRemoteComponentFactory(RemoteApp) {
|
|
111
|
+
return function createLazyRemoteComponent(info) {
|
|
112
|
+
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
113
|
+
return React.lazy(async () => {
|
|
114
|
+
index.LoggerInstance.debug(
|
|
115
|
+
`createRemoteAppComponent LazyComponent create >>>`,
|
|
116
|
+
{
|
|
117
|
+
lazyComponent: info.loader,
|
|
118
|
+
exportName
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
try {
|
|
122
|
+
const m = await info.loader();
|
|
123
|
+
const moduleName = m && m[Symbol.for("mf_module_id")];
|
|
124
|
+
index.LoggerInstance.debug(
|
|
125
|
+
`createRemoteAppComponent LazyComponent loadRemote info >>>`,
|
|
126
|
+
{ name: moduleName, module: m, exportName }
|
|
127
|
+
);
|
|
128
|
+
const exportFn = m[exportName];
|
|
129
|
+
if (exportName in m && typeof exportFn === "function") {
|
|
130
|
+
const RemoteAppComponent = React.forwardRef((props, ref) => {
|
|
131
|
+
return /* @__PURE__ */ React.createElement(
|
|
132
|
+
RemoteApp,
|
|
133
|
+
{
|
|
134
|
+
moduleName,
|
|
135
|
+
providerInfo: exportFn,
|
|
136
|
+
exportName: info.export || "default",
|
|
137
|
+
fallback: info.fallback,
|
|
138
|
+
loading: info.loading,
|
|
139
|
+
ref,
|
|
140
|
+
...props
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
default: RemoteAppComponent
|
|
146
|
+
};
|
|
147
|
+
} else {
|
|
148
|
+
index.LoggerInstance.debug(
|
|
149
|
+
`createRemoteAppComponent LazyComponent module not found >>>`,
|
|
150
|
+
{ name: moduleName, module: m, exportName }
|
|
151
|
+
);
|
|
152
|
+
throw Error(
|
|
153
|
+
`Make sure that ${moduleName} has the correct export when export is ${String(
|
|
154
|
+
exportName
|
|
155
|
+
)}`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function createRemoteAppComponentFactory(RemoteApp) {
|
|
165
|
+
const createLazyRemoteComponent = createLazyRemoteComponentFactory(RemoteApp);
|
|
166
|
+
return function createRemoteAppComponent(info) {
|
|
167
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
168
|
+
return React.forwardRef((props, ref) => {
|
|
169
|
+
return /* @__PURE__ */ React.createElement(
|
|
170
|
+
bridgeBase.ErrorBoundary,
|
|
171
|
+
{
|
|
172
|
+
FallbackComponent: info.fallback
|
|
173
|
+
},
|
|
174
|
+
/* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref }))
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function createDeprecatedRemoteComponentFactory(createFn) {
|
|
180
|
+
return function createRemoteComponent(info) {
|
|
181
|
+
index.LoggerInstance.warn(
|
|
182
|
+
`createRemoteComponent is deprecated, please use createRemoteAppComponent instead!`
|
|
183
|
+
);
|
|
184
|
+
return createFn(info);
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
exports.RemoteAppWrapper = RemoteAppWrapper;
|
|
188
|
+
exports.createBridgeComponent = createBridgeComponent;
|
|
189
|
+
exports.createDeprecatedRemoteComponentFactory = createDeprecatedRemoteComponentFactory;
|
|
190
|
+
exports.createRemoteAppComponentFactory = createRemoteAppComponentFactory;
|