@module-federation/bridge-react 0.0.0-perf-devtools-20260108034446 → 0.0.0-perf-website-code-usage-20260914033703

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 (161) hide show
  1. package/dist/base.cjs.js +4 -4
  2. package/dist/base.d.ts +8 -311
  3. package/dist/base.es.js +11 -11
  4. package/dist/{bridge-base-CPSTBjEp.mjs → bridge-base-CHnL6Q9P.mjs} +63 -103
  5. package/dist/{bridge-base-RStDxH71.js → bridge-base-DSYKAGGD.js} +63 -102
  6. package/dist/{createHelpers-Ui5pt7je.mjs → createHelpers-D3Sg5lKp.mjs} +32 -17
  7. package/dist/{createHelpers-B_L612IN.js → createHelpers-D6thyyLv.js} +30 -15
  8. package/dist/data-fetch-server-middleware.cjs.js +4 -4
  9. package/dist/data-fetch-server-middleware.d.ts +1 -15
  10. package/dist/data-fetch-server-middleware.es.js +2 -2
  11. package/dist/data-fetch-utils.cjs.js +2 -2
  12. package/dist/data-fetch-utils.d.ts +1 -81
  13. package/dist/data-fetch-utils.es.js +7 -7
  14. package/dist/data-fetch.cjs.js +22 -0
  15. package/dist/data-fetch.d.ts +4 -0
  16. package/dist/data-fetch.es.js +22 -0
  17. package/dist/error-boundary.d.ts +17 -0
  18. package/dist/error-boundary.spec.d.ts +1 -0
  19. package/dist/{index-DyQNwY2M.mjs → index-Bs2NxD2z.mjs} +1 -1
  20. package/dist/{index-DRSBaSu3.js → index-DbjGCKOr.js} +2 -2
  21. package/dist/index.cjs.js +27 -6
  22. package/dist/index.d.ts +12 -299
  23. package/dist/index.es.js +34 -13
  24. package/dist/lazy/AwaitDataFetch.d.ts +24 -0
  25. package/dist/lazy/HydratedStylesheetAssets.d.ts +4 -0
  26. package/dist/lazy/constant.d.ts +26 -0
  27. package/dist/lazy/createLazyComponent.d.ts +28 -0
  28. package/dist/lazy/data-fetch/cache.d.ts +34 -0
  29. package/dist/lazy/data-fetch/cache.spec.d.ts +1 -0
  30. package/dist/lazy/data-fetch/call-data-fetch.d.ts +1 -0
  31. package/dist/lazy/data-fetch/data-fetch-server-middleware.d.ts +3 -0
  32. package/{src/lazy/data-fetch/index.ts → dist/lazy/data-fetch/index.d.ts} +1 -11
  33. package/dist/lazy/data-fetch/inject-data-fetch.d.ts +4 -0
  34. package/dist/lazy/data-fetch/prefetch.d.ts +9 -0
  35. package/dist/lazy/data-fetch/runtime-plugin.d.ts +3 -0
  36. package/dist/lazy/index.d.ts +9 -0
  37. package/dist/lazy/logger.d.ts +2 -0
  38. package/dist/lazy/types.d.ts +60 -0
  39. package/dist/lazy/utils.d.ts +48 -0
  40. package/dist/lazy/wrapNoSSR.d.ts +9 -0
  41. package/dist/{lazy-load-component-plugin-BvnyaA6i.js → lazy-load-component-plugin-DSURjnZ0.js} +170 -44
  42. package/dist/{lazy-load-component-plugin-CVcFMRce.mjs → lazy-load-component-plugin-NZphPG7_.mjs} +174 -48
  43. package/dist/lazy-load-component-plugin.cjs.js +2 -2
  44. package/dist/lazy-load-component-plugin.d.ts +2 -16
  45. package/dist/lazy-load-component-plugin.es.js +2 -2
  46. package/dist/lazy-utils.cjs.js +2 -2
  47. package/dist/lazy-utils.d.ts +1 -149
  48. package/dist/lazy-utils.es.js +19 -19
  49. package/dist/logger-DwWkXsWl.mjs +139 -0
  50. package/dist/logger-Dxblx6P-.js +138 -0
  51. package/dist/plugin.d.ts +2 -22
  52. package/dist/plugins/lazy-load-component-plugin.d.ts +12 -0
  53. package/dist/plugins/lazy-load-component-plugin.spec.d.ts +1 -0
  54. package/dist/prefetch-Bxf6DSx_.js +1477 -0
  55. package/dist/prefetch-TKq_EK_q.mjs +1478 -0
  56. package/dist/provider/context.d.ts +3 -0
  57. package/dist/provider/plugin.d.ts +7 -0
  58. package/dist/provider/versions/bridge-base.d.ts +5 -0
  59. package/dist/provider/versions/legacy.d.ts +26 -0
  60. package/dist/provider/versions/v18.d.ts +19 -0
  61. package/dist/provider/versions/v19.d.ts +21 -0
  62. package/dist/remote/RemoteAppWrapper.d.ts +7 -0
  63. package/dist/remote/base-component/create.d.ts +9 -0
  64. package/dist/remote/base-component/index.d.ts +5 -0
  65. package/dist/remote/createHelpers.d.ts +17 -0
  66. package/dist/remote/router-component/component.d.ts +8 -0
  67. package/dist/remote/router-component/create.d.ts +9 -0
  68. package/dist/remote/router-component/index.d.ts +5 -0
  69. package/dist/router/default.d.ts +7 -0
  70. package/dist/router/v5.d.ts +4 -0
  71. package/dist/router/v6.d.ts +7 -0
  72. package/dist/router/v7.d.ts +6 -0
  73. package/dist/router-v5.cjs.js +5 -3
  74. package/dist/router-v5.d.ts +1 -18
  75. package/dist/router-v5.es.js +5 -3
  76. package/dist/router-v6.cjs.js +1 -1
  77. package/dist/router-v6.d.ts +1 -20
  78. package/dist/router-v6.es.js +1 -1
  79. package/dist/router-v7.cjs.js +5 -3
  80. package/dist/router-v7.d.ts +1 -20
  81. package/dist/router-v7.es.js +5 -3
  82. package/dist/router.cjs.js +1 -1
  83. package/dist/router.d.ts +1 -20
  84. package/dist/router.es.js +1 -1
  85. package/dist/shared/size-limited-cache.d.ts +29 -0
  86. package/dist/shared/size-limited-cache.spec.d.ts +1 -0
  87. package/dist/size-limited-cache.cjs.js +82 -0
  88. package/dist/size-limited-cache.d.ts +1 -0
  89. package/dist/size-limited-cache.es.js +82 -0
  90. package/dist/types.d.ts +137 -0
  91. package/dist/utils/index.d.ts +4 -0
  92. package/dist/utils-5dGErM3C.js +588 -0
  93. package/dist/utils-BBP3hEeV.mjs +589 -0
  94. package/dist/v18.cjs.js +1 -1
  95. package/dist/v18.d.ts +3 -114
  96. package/dist/v18.es.js +1 -1
  97. package/dist/v19.cjs.js +1 -1
  98. package/dist/v19.d.ts +3 -115
  99. package/dist/v19.es.js +1 -1
  100. package/package.json +35 -14
  101. package/CHANGELOG.md +0 -735
  102. package/__tests__/bridge.spec.tsx +0 -160
  103. package/__tests__/createLazyComponent.spec.tsx +0 -209
  104. package/__tests__/prefetch.spec.ts +0 -156
  105. package/__tests__/router.spec.tsx +0 -82
  106. package/__tests__/setupTests.ts +0 -8
  107. package/__tests__/util.ts +0 -36
  108. package/dist/index.esm-BWaKho-8.js +0 -491
  109. package/dist/index.esm-CPwSeCvw.mjs +0 -492
  110. package/dist/prefetch-CK3EZdY4.mjs +0 -1273
  111. package/dist/prefetch-MiXeF8KH.js +0 -1272
  112. package/dist/utils-dUgb9Jkm.mjs +0 -2016
  113. package/dist/utils-tM9yE73c.js +0 -2015
  114. package/jest.config.ts +0 -21
  115. package/project.json +0 -23
  116. package/src/base.ts +0 -50
  117. package/src/index.ts +0 -50
  118. package/src/lazy/AwaitDataFetch.tsx +0 -215
  119. package/src/lazy/constant.ts +0 -30
  120. package/src/lazy/createLazyComponent.tsx +0 -411
  121. package/src/lazy/data-fetch/cache.ts +0 -291
  122. package/src/lazy/data-fetch/call-data-fetch.ts +0 -13
  123. package/src/lazy/data-fetch/data-fetch-server-middleware.ts +0 -196
  124. package/src/lazy/data-fetch/inject-data-fetch.ts +0 -109
  125. package/src/lazy/data-fetch/prefetch.ts +0 -112
  126. package/src/lazy/data-fetch/runtime-plugin.ts +0 -115
  127. package/src/lazy/index.ts +0 -35
  128. package/src/lazy/logger.ts +0 -6
  129. package/src/lazy/types.ts +0 -75
  130. package/src/lazy/utils.ts +0 -372
  131. package/src/lazy/wrapNoSSR.tsx +0 -10
  132. package/src/modern-app-env.d.ts +0 -2
  133. package/src/plugins/lazy-load-component-plugin.spec.ts +0 -21
  134. package/src/plugins/lazy-load-component-plugin.ts +0 -57
  135. package/src/provider/context.tsx +0 -4
  136. package/src/provider/plugin.ts +0 -22
  137. package/src/provider/versions/bridge-base.tsx +0 -150
  138. package/src/provider/versions/legacy.ts +0 -87
  139. package/src/provider/versions/v18.ts +0 -47
  140. package/src/provider/versions/v19.ts +0 -48
  141. package/src/remote/RemoteAppWrapper.tsx +0 -108
  142. package/src/remote/base-component/create.tsx +0 -23
  143. package/src/remote/base-component/index.tsx +0 -10
  144. package/src/remote/createHelpers.tsx +0 -130
  145. package/src/remote/router-component/component.tsx +0 -104
  146. package/src/remote/router-component/create.tsx +0 -23
  147. package/src/remote/router-component/index.tsx +0 -10
  148. package/src/router/default.tsx +0 -73
  149. package/src/router/v5.tsx +0 -43
  150. package/src/router/v6.tsx +0 -74
  151. package/src/router/v7.tsx +0 -75
  152. package/src/types.ts +0 -147
  153. package/src/utils/index.ts +0 -44
  154. package/src/v18.ts +0 -9
  155. package/src/v19.ts +0 -9
  156. package/tsconfig.json +0 -42
  157. package/tsconfig.node.json +0 -11
  158. package/tsconfig.spec.json +0 -26
  159. package/vite.config.ts +0 -112
  160. package/vitest.config.ts +0 -27
  161. /package/{src/remote/base-component/component.tsx → dist/remote/base-component/component.d.ts} +0 -0
@@ -0,0 +1,60 @@
1
+ import { MF_DATA_FETCH_TYPE, MF_DATA_FETCH_STATUS } from './constant';
2
+ import type { SizeLimitedCache } from '../shared/size-limited-cache';
3
+ export type dataFetchFunctionOptions = [
4
+ id?: string,
5
+ data?: unknown,
6
+ downgrade?: boolean
7
+ ];
8
+ declare global {
9
+ var _mfSSRDowngrade: string[] | true | undefined;
10
+ var __MF_DATA_FETCH_MAP__: MF_DATA_FETCH_MAP | undefined;
11
+ var FEDERATION_SERVER_QUERY: Record<string, unknown> | undefined;
12
+ var FEDERATION_SSR: boolean | undefined;
13
+ var _mfFSHref: string | undefined;
14
+ var _mfDataFetch: Array<dataFetchFunctionOptions> | undefined;
15
+ var __MF_DATA_FETCH_CACHE__: MF_DATA_FETCH_CACHE | undefined;
16
+ }
17
+ export interface CacheItem<T> {
18
+ data: T;
19
+ timestamp: number;
20
+ isRevalidating?: boolean;
21
+ }
22
+ export type DataFetchParams = {
23
+ isDowngrade: boolean;
24
+ _id?: string;
25
+ } & Record<string, unknown>;
26
+ export type DataFetch<T> = (params: DataFetchParams) => Promise<T>;
27
+ export type MF_DATA_FETCH_MAP_VALUE_PROMISE_SET = [
28
+ Promise<unknown>,
29
+ ((data: unknown) => void)?,
30
+ ((err: unknown) => void)?
31
+ ];
32
+ export type MF_DATA_FETCH_MAP_VALUE = [
33
+ [
34
+ () => Promise<DataFetch<unknown>>,
35
+ MF_DATA_FETCH_TYPE,
36
+ Promise<DataFetch<unknown>>?
37
+ ],
38
+ MF_DATA_FETCH_MAP_VALUE_PROMISE_SET?,
39
+ MF_DATA_FETCH_STATUS?
40
+ ];
41
+ export type MF_DATA_FETCH_MAP = Record<string, MF_DATA_FETCH_MAP_VALUE>;
42
+ export type MF_SSR_DOWNGRADE = string[] | true | undefined;
43
+ export type NoSSRRemoteInfo = {
44
+ name: string;
45
+ version: string;
46
+ ssrPublicPath: string;
47
+ ssrRemoteEntry: string;
48
+ globalName: string;
49
+ };
50
+ export interface CacheConfig {
51
+ maxSize?: number;
52
+ unstable_shouldDisable?: ({ request, }: {
53
+ request: Request;
54
+ }) => boolean | Promise<boolean>;
55
+ }
56
+ export type MF_DATA_FETCH_CACHE = {
57
+ cacheStore?: SizeLimitedCache<string, Map<string, CacheItem<any>>>;
58
+ tagKeyMap?: Map<string, Set<string>>;
59
+ cacheConfig?: CacheConfig;
60
+ };
@@ -0,0 +1,48 @@
1
+ import type { GlobalModuleInfo } from '@module-federation/sdk';
2
+ import type { DataFetchParams, MF_DATA_FETCH_MAP, NoSSRRemoteInfo, MF_SSR_DOWNGRADE, MF_DATA_FETCH_CACHE } from './types';
3
+ import type { ModuleFederation } from '@module-federation/runtime';
4
+ export declare const getDataFetchInfo: ({ name, alias, id, remoteSnapshot, }: {
5
+ id: string;
6
+ name: string;
7
+ remoteSnapshot: GlobalModuleInfo[string];
8
+ alias?: string;
9
+ }) => {
10
+ dataFetchName: string;
11
+ dataFetchId: string;
12
+ dataFetchKey: string;
13
+ } | undefined;
14
+ export declare function initDataFetchMap(): void;
15
+ export declare function getDataFetchItem(id: string): import("./types").MF_DATA_FETCH_MAP_VALUE;
16
+ export declare function getDataFetchMap(): MF_DATA_FETCH_MAP;
17
+ export declare function getDataFetchCache(): MF_DATA_FETCH_CACHE;
18
+ export declare const flushDataFetch: () => void;
19
+ export declare function setDataFetchItemLoadedStatus(id: string): void;
20
+ export declare const wrapDataFetchId: (id?: string) => string;
21
+ export declare const getDataFetchIdWithErrorMsgs: (errMsgs: string) => string | undefined;
22
+ export declare function fetchData(id: string, params: DataFetchParams, remoteInfo?: NoSSRRemoteInfo): Promise<unknown | undefined>;
23
+ export declare function getDataFetchMapKey(dataFetchInfo?: ReturnType<typeof getDataFetchInfo>, hostInfo?: {
24
+ name: string;
25
+ version?: string;
26
+ }): string | undefined;
27
+ export declare function loadDataFetchModule(instance: ModuleFederation, id: string): Promise<(params: DataFetchParams) => Promise<unknown>>;
28
+ export declare function isDataLoaderExpose(exposeKey: string): boolean;
29
+ export declare function getDowngradeTag(): MF_SSR_DOWNGRADE;
30
+ export declare function callAllDowngrade(): void;
31
+ export declare function callDowngrade(id: string, params?: DataFetchParams, remoteInfo?: NoSSRRemoteInfo): Promise<unknown>;
32
+ export declare function isCSROnly(): boolean;
33
+ export declare function isServerEnv(): boolean;
34
+ export declare function setSSREnv({ fetchServerQuery, }: {
35
+ fetchServerQuery?: Record<string, unknown>;
36
+ }): void;
37
+ export declare function getLoadedRemoteInfos(id: string, instance: ModuleFederation | null): {
38
+ alias?: string;
39
+ name: string;
40
+ version?: string;
41
+ buildVersion?: string;
42
+ entry: string;
43
+ type: import("@module-federation/sdk").RemoteEntryType;
44
+ entryGlobalName: string;
45
+ shareScope: string | string[];
46
+ snapshot: import("@module-federation/sdk").ManifestProvider | import("@module-federation/sdk").PureEntryProvider | import("@module-federation/sdk").ModuleInfo | undefined;
47
+ expose: string;
48
+ } | undefined;
@@ -0,0 +1,9 @@
1
+ import { createLazyComponent } from './createLazyComponent';
2
+ import type { CreateLazyComponentOptions } from './createLazyComponent';
3
+ export declare function wrapNoSSR<T, E extends keyof T>(createLazyComponentFn: typeof createLazyComponent<T, E>): (options: Omit<CreateLazyComponentOptions<T, E>, 'noSSR'>) => (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? {
4
+ key?: React.Key | null;
5
+ } : Parameters<T[E]>[0] & {
6
+ key?: React.Key | null;
7
+ } : {
8
+ key?: React.Key | null;
9
+ }) => import("node_modules/@types/react").JSX.Element;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
- const prefetch = require("./prefetch-MiXeF8KH.js");
3
- const lazyUtils = require("./utils-tM9yE73c.js");
2
+ const prefetch = require("./prefetch-Bxf6DSx_.js");
3
+ const lazyUtils = require("./utils-5dGErM3C.js");
4
4
  const React = require("react");
5
5
  const autoFetchData = () => {
6
6
  lazyUtils.initDataFetchMap();
@@ -70,6 +70,142 @@ const autoFetchData = () => {
70
70
  }
71
71
  };
72
72
  };
73
+ const EMPTY_HREFS = /* @__PURE__ */ new Set();
74
+ const stylesheetStores = /* @__PURE__ */ new WeakMap();
75
+ function isActiveStylesheet(link) {
76
+ const rel = link.rel.toLowerCase().split(/\s+/u);
77
+ const media = link.media.trim().toLowerCase();
78
+ const type = link.type.trim().toLowerCase().split(";", 1)[0].trim();
79
+ return rel.includes("stylesheet") && !rel.includes("alternate") && !link.disabled && !link.hasAttribute("disabled") && (!media || media === "all") && (!type || type === "text/css");
80
+ }
81
+ function collectHeadStylesheetHrefs(document) {
82
+ var _a;
83
+ const hrefs = /* @__PURE__ */ new Set();
84
+ (_a = document.head) == null ? void 0 : _a.querySelectorAll("link[href]").forEach((link) => {
85
+ if (isActiveStylesheet(link)) {
86
+ hrefs.add(link.href);
87
+ }
88
+ });
89
+ return hrefs;
90
+ }
91
+ function haveSameHrefs(current, next) {
92
+ if (current.size !== next.size) {
93
+ return false;
94
+ }
95
+ for (const href of current) {
96
+ if (!next.has(href)) {
97
+ return false;
98
+ }
99
+ }
100
+ return true;
101
+ }
102
+ function observeHead(store) {
103
+ store.observer.disconnect();
104
+ const { document, head, observer } = store;
105
+ if (head) {
106
+ observer.observe(head, {
107
+ attributes: true,
108
+ attributeFilter: ["disabled", "href", "media", "rel", "type"],
109
+ childList: true,
110
+ subtree: true
111
+ });
112
+ }
113
+ if (document.documentElement) {
114
+ observer.observe(document.documentElement, { childList: true });
115
+ }
116
+ }
117
+ function refreshHeadStylesheets(store) {
118
+ if (!store.subscribers.size) {
119
+ return;
120
+ }
121
+ const head = store.document.head;
122
+ if (head !== store.head) {
123
+ store.head = head;
124
+ observeHead(store);
125
+ }
126
+ const hrefs = collectHeadStylesheetHrefs(store.document);
127
+ if (haveSameHrefs(store.hrefs, hrefs)) {
128
+ return;
129
+ }
130
+ store.hrefs = hrefs;
131
+ store.subscribers.forEach((subscriber) => subscriber(hrefs));
132
+ }
133
+ function getStylesheetStore(document) {
134
+ var _a;
135
+ const current = stylesheetStores.get(document);
136
+ if (current) {
137
+ return current;
138
+ }
139
+ const MutationObserver = ((_a = document.defaultView) == null ? void 0 : _a.MutationObserver) ?? globalThis.MutationObserver;
140
+ let store;
141
+ const observer = new MutationObserver(() => refreshHeadStylesheets(store));
142
+ store = {
143
+ document,
144
+ head: document.head,
145
+ hrefs: collectHeadStylesheetHrefs(document),
146
+ observer,
147
+ subscribers: /* @__PURE__ */ new Set()
148
+ };
149
+ observeHead(store);
150
+ stylesheetStores.set(document, store);
151
+ return store;
152
+ }
153
+ function subscribeToHeadStylesheets(document, subscriber) {
154
+ const store = getStylesheetStore(document);
155
+ let subscribed = true;
156
+ store.subscribers.add(subscriber);
157
+ subscriber(store.hrefs);
158
+ return () => {
159
+ if (!subscribed) {
160
+ return;
161
+ }
162
+ subscribed = false;
163
+ store.subscribers.delete(subscriber);
164
+ if (!store.subscribers.size) {
165
+ store.observer.disconnect();
166
+ if (stylesheetStores.get(document) === store) {
167
+ stylesheetStores.delete(document);
168
+ }
169
+ }
170
+ };
171
+ }
172
+ function resolveHref(href, document) {
173
+ try {
174
+ return new URL(href, document.baseURI).href;
175
+ } catch {
176
+ return href;
177
+ }
178
+ }
179
+ function HydratedStylesheetAssets({ hrefs }) {
180
+ const firstLinkRef = React.useRef(null);
181
+ const ownerDocumentRef = React.useRef(null);
182
+ const [headHrefs, setHeadHrefs] = React.useState(EMPTY_HREFS);
183
+ React.useEffect(() => {
184
+ var _a;
185
+ const link = firstLinkRef.current;
186
+ if (!link) {
187
+ return;
188
+ }
189
+ const ownerDocument = link.ownerDocument;
190
+ ownerDocumentRef.current = ownerDocument;
191
+ if (link.getRootNode() !== ownerDocument || ((_a = ownerDocument.head) == null ? void 0 : _a.contains(link))) {
192
+ return;
193
+ }
194
+ return subscribeToHeadStylesheets(ownerDocument, setHeadHrefs);
195
+ }, []);
196
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, hrefs.map(
197
+ (href, index) => ownerDocumentRef.current && headHrefs.has(resolveHref(href, ownerDocumentRef.current)) ? null : /* @__PURE__ */ React.createElement(
198
+ "link",
199
+ {
200
+ key: href,
201
+ ref: index === 0 ? firstLinkRef : void 0,
202
+ href,
203
+ rel: "stylesheet",
204
+ type: "text/css"
205
+ }
206
+ )
207
+ ));
208
+ }
73
209
  function isPromise(obj) {
74
210
  return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
75
211
  }
@@ -236,65 +372,51 @@ function getTargetModuleInfo(id, instance) {
236
372
  remoteEntry
237
373
  };
238
374
  }
239
- function collectSSRAssets(options) {
375
+ function collectSSRAssetDescriptors(options) {
240
376
  const {
241
377
  id,
242
378
  injectLink = true,
243
379
  injectScript = false
244
380
  } = typeof options === "string" ? { id: options } : options;
245
- const links = [];
246
- const scripts = [];
381
+ const stylesheetHrefs = [];
382
+ const scriptSrcs = [];
247
383
  const instance = options.instance;
248
384
  if (!instance || !injectLink && !injectScript) {
249
- return [...scripts, ...links];
385
+ return { scriptSrcs, stylesheetHrefs };
250
386
  }
251
387
  const moduleAndPublicPath = getTargetModuleInfo(id, instance);
252
388
  if (!moduleAndPublicPath) {
253
- return [...scripts, ...links];
389
+ return { scriptSrcs, stylesheetHrefs };
254
390
  }
255
391
  const { module: targetModule, publicPath, remoteEntry } = moduleAndPublicPath;
256
392
  if (injectLink) {
257
- [...targetModule.assets.css.sync, ...targetModule.assets.css.async].sort().forEach((file, index) => {
258
- links.push(
259
- /* @__PURE__ */ React.createElement(
260
- "link",
261
- {
262
- key: `${file.split(".")[0]}_${index}`,
263
- href: `${publicPath}${file}`,
264
- rel: "stylesheet",
265
- type: "text/css"
266
- }
267
- )
268
- );
393
+ const seenStylesheetHrefs = /* @__PURE__ */ new Set();
394
+ [...targetModule.assets.css.sync, ...targetModule.assets.css.async].sort().forEach((file) => {
395
+ const href = `${publicPath}${file}`;
396
+ if (seenStylesheetHrefs.has(href)) {
397
+ return;
398
+ }
399
+ seenStylesheetHrefs.add(href);
400
+ stylesheetHrefs.push(href);
269
401
  });
270
402
  }
271
403
  if (injectScript) {
272
- scripts.push(
273
- /* @__PURE__ */ React.createElement(
274
- "script",
275
- {
276
- async: true,
277
- key: remoteEntry.split(".")[0],
278
- src: `${publicPath}${remoteEntry}`,
279
- crossOrigin: "anonymous"
280
- }
281
- )
282
- );
283
- [...targetModule.assets.js.sync].sort().forEach((file, index) => {
284
- scripts.push(
285
- /* @__PURE__ */ React.createElement(
286
- "script",
287
- {
288
- key: `${file.split(".")[0]}_${index}`,
289
- async: true,
290
- src: `${publicPath}${file}`,
291
- crossOrigin: "anonymous"
292
- }
293
- )
294
- );
404
+ scriptSrcs.push(`${publicPath}${remoteEntry}`);
405
+ [...targetModule.assets.js.sync].sort().forEach((file) => {
406
+ scriptSrcs.push(`${publicPath}${file}`);
295
407
  });
296
408
  }
297
- return [...scripts, ...links];
409
+ return { scriptSrcs, stylesheetHrefs };
410
+ }
411
+ function renderScriptAssets(scriptSrcs) {
412
+ return scriptSrcs.map((src) => /* @__PURE__ */ React.createElement("script", { key: src, async: true, src, crossOrigin: "anonymous" }));
413
+ }
414
+ function collectSSRAssets(options) {
415
+ const { scriptSrcs, stylesheetHrefs } = collectSSRAssetDescriptors(options);
416
+ return [
417
+ ...renderScriptAssets(scriptSrcs),
418
+ ...stylesheetHrefs.map((href) => /* @__PURE__ */ React.createElement("link", { key: href, href, rel: "stylesheet", type: "text/css" }))
419
+ ];
298
420
  }
299
421
  function getServerNeedRemoteInfo(loadedRemoteInfo, id, noSSR) {
300
422
  var _a;
@@ -408,12 +530,16 @@ function createLazyComponent(options) {
408
530
  { name: instance.name, version: instance == null ? void 0 : instance.options.version }
409
531
  ) : void 0;
410
532
  lazyUtils.logger.debug("LazyComponent dataFetchMapKey: ", dataFetchMapKey);
411
- const assets = collectSSRAssets({
533
+ const { scriptSrcs, stylesheetHrefs } = collectSSRAssetDescriptors({
412
534
  id: moduleId,
413
535
  instance,
414
536
  injectLink,
415
537
  injectScript
416
538
  });
539
+ const assets = [
540
+ ...renderScriptAssets(scriptSrcs),
541
+ /* @__PURE__ */ React.createElement(HydratedStylesheetAssets, { key: "stylesheets", hrefs: stylesheetHrefs })
542
+ ];
417
543
  const Com = m[exportName];
418
544
  if (exportName in m && typeof Com === "function") {
419
545
  return {
@@ -1,6 +1,6 @@
1
- import { i as injectDataFetch, p as prefetch } from "./prefetch-CK3EZdY4.mjs";
2
- import { i as initDataFetchMap, j as isDataLoaderExpose, k as getDataFetchInfo, m as getDataFetchMapKey, l as logger, n as getDataFetchItem, o as DATA_FETCH_CLIENT_SUFFIX, p as MF_DATA_FETCH_TYPE, q as isCSROnly, h as loadDataFetchModule, M as MF_DATA_FETCH_STATUS, e as getDataFetchMap, t as isServerEnv, u as getDataFetchIdWithErrorMsgs, v as DATA_FETCH_ERROR_PREFIX, E as ERROR_TYPE, w as wrapDataFetchId, L as LOAD_REMOTE_ERROR_PREFIX, x as DATA_FETCH_FUNCTION, y as getLoadedRemoteInfos, f as fetchData$1, z as setDataFetchItemLoadedStatus, F as FS_HREF } from "./utils-dUgb9Jkm.mjs";
3
- import React__default, { useRef, useState, Suspense, useEffect } from "react";
1
+ import { i as injectDataFetch, p as prefetch } from "./prefetch-TKq_EK_q.mjs";
2
+ import { i as initDataFetchMap, k as isDataLoaderExpose, m as getDataFetchInfo, n as getDataFetchMapKey, l as logger, o as getDataFetchItem, p as DATA_FETCH_CLIENT_SUFFIX, q as MF_DATA_FETCH_TYPE, t as isCSROnly, M as MF_DATA_FETCH_STATUS, j as loadDataFetchModule, e as getDataFetchMap, u as isServerEnv, v as getDataFetchIdWithErrorMsgs, w as DATA_FETCH_ERROR_PREFIX, E as ERROR_TYPE, x as wrapDataFetchId, L as LOAD_REMOTE_ERROR_PREFIX, y as DATA_FETCH_FUNCTION, z as getLoadedRemoteInfos, h as fetchData$1, A as setDataFetchItemLoadedStatus, F as FS_HREF } from "./utils-BBP3hEeV.mjs";
3
+ import React__default, { useRef, useState, useEffect, Suspense } from "react";
4
4
  const autoFetchData = () => {
5
5
  initDataFetchMap();
6
6
  injectDataFetch();
@@ -69,6 +69,142 @@ const autoFetchData = () => {
69
69
  }
70
70
  };
71
71
  };
72
+ const EMPTY_HREFS = /* @__PURE__ */ new Set();
73
+ const stylesheetStores = /* @__PURE__ */ new WeakMap();
74
+ function isActiveStylesheet(link) {
75
+ const rel = link.rel.toLowerCase().split(/\s+/u);
76
+ const media = link.media.trim().toLowerCase();
77
+ const type = link.type.trim().toLowerCase().split(";", 1)[0].trim();
78
+ return rel.includes("stylesheet") && !rel.includes("alternate") && !link.disabled && !link.hasAttribute("disabled") && (!media || media === "all") && (!type || type === "text/css");
79
+ }
80
+ function collectHeadStylesheetHrefs(document) {
81
+ var _a;
82
+ const hrefs = /* @__PURE__ */ new Set();
83
+ (_a = document.head) == null ? void 0 : _a.querySelectorAll("link[href]").forEach((link) => {
84
+ if (isActiveStylesheet(link)) {
85
+ hrefs.add(link.href);
86
+ }
87
+ });
88
+ return hrefs;
89
+ }
90
+ function haveSameHrefs(current, next) {
91
+ if (current.size !== next.size) {
92
+ return false;
93
+ }
94
+ for (const href of current) {
95
+ if (!next.has(href)) {
96
+ return false;
97
+ }
98
+ }
99
+ return true;
100
+ }
101
+ function observeHead(store) {
102
+ store.observer.disconnect();
103
+ const { document, head, observer } = store;
104
+ if (head) {
105
+ observer.observe(head, {
106
+ attributes: true,
107
+ attributeFilter: ["disabled", "href", "media", "rel", "type"],
108
+ childList: true,
109
+ subtree: true
110
+ });
111
+ }
112
+ if (document.documentElement) {
113
+ observer.observe(document.documentElement, { childList: true });
114
+ }
115
+ }
116
+ function refreshHeadStylesheets(store) {
117
+ if (!store.subscribers.size) {
118
+ return;
119
+ }
120
+ const head = store.document.head;
121
+ if (head !== store.head) {
122
+ store.head = head;
123
+ observeHead(store);
124
+ }
125
+ const hrefs = collectHeadStylesheetHrefs(store.document);
126
+ if (haveSameHrefs(store.hrefs, hrefs)) {
127
+ return;
128
+ }
129
+ store.hrefs = hrefs;
130
+ store.subscribers.forEach((subscriber) => subscriber(hrefs));
131
+ }
132
+ function getStylesheetStore(document) {
133
+ var _a;
134
+ const current = stylesheetStores.get(document);
135
+ if (current) {
136
+ return current;
137
+ }
138
+ const MutationObserver = ((_a = document.defaultView) == null ? void 0 : _a.MutationObserver) ?? globalThis.MutationObserver;
139
+ let store;
140
+ const observer = new MutationObserver(() => refreshHeadStylesheets(store));
141
+ store = {
142
+ document,
143
+ head: document.head,
144
+ hrefs: collectHeadStylesheetHrefs(document),
145
+ observer,
146
+ subscribers: /* @__PURE__ */ new Set()
147
+ };
148
+ observeHead(store);
149
+ stylesheetStores.set(document, store);
150
+ return store;
151
+ }
152
+ function subscribeToHeadStylesheets(document, subscriber) {
153
+ const store = getStylesheetStore(document);
154
+ let subscribed = true;
155
+ store.subscribers.add(subscriber);
156
+ subscriber(store.hrefs);
157
+ return () => {
158
+ if (!subscribed) {
159
+ return;
160
+ }
161
+ subscribed = false;
162
+ store.subscribers.delete(subscriber);
163
+ if (!store.subscribers.size) {
164
+ store.observer.disconnect();
165
+ if (stylesheetStores.get(document) === store) {
166
+ stylesheetStores.delete(document);
167
+ }
168
+ }
169
+ };
170
+ }
171
+ function resolveHref(href, document) {
172
+ try {
173
+ return new URL(href, document.baseURI).href;
174
+ } catch {
175
+ return href;
176
+ }
177
+ }
178
+ function HydratedStylesheetAssets({ hrefs }) {
179
+ const firstLinkRef = useRef(null);
180
+ const ownerDocumentRef = useRef(null);
181
+ const [headHrefs, setHeadHrefs] = useState(EMPTY_HREFS);
182
+ useEffect(() => {
183
+ var _a;
184
+ const link = firstLinkRef.current;
185
+ if (!link) {
186
+ return;
187
+ }
188
+ const ownerDocument = link.ownerDocument;
189
+ ownerDocumentRef.current = ownerDocument;
190
+ if (link.getRootNode() !== ownerDocument || ((_a = ownerDocument.head) == null ? void 0 : _a.contains(link))) {
191
+ return;
192
+ }
193
+ return subscribeToHeadStylesheets(ownerDocument, setHeadHrefs);
194
+ }, []);
195
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, hrefs.map(
196
+ (href, index) => ownerDocumentRef.current && headHrefs.has(resolveHref(href, ownerDocumentRef.current)) ? null : /* @__PURE__ */ React__default.createElement(
197
+ "link",
198
+ {
199
+ key: href,
200
+ ref: index === 0 ? firstLinkRef : void 0,
201
+ href,
202
+ rel: "stylesheet",
203
+ type: "text/css"
204
+ }
205
+ )
206
+ ));
207
+ }
72
208
  function isPromise(obj) {
73
209
  return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
74
210
  }
@@ -235,65 +371,51 @@ function getTargetModuleInfo(id, instance) {
235
371
  remoteEntry
236
372
  };
237
373
  }
238
- function collectSSRAssets(options) {
374
+ function collectSSRAssetDescriptors(options) {
239
375
  const {
240
376
  id,
241
377
  injectLink = true,
242
378
  injectScript = false
243
379
  } = typeof options === "string" ? { id: options } : options;
244
- const links = [];
245
- const scripts = [];
380
+ const stylesheetHrefs = [];
381
+ const scriptSrcs = [];
246
382
  const instance = options.instance;
247
383
  if (!instance || !injectLink && !injectScript) {
248
- return [...scripts, ...links];
384
+ return { scriptSrcs, stylesheetHrefs };
249
385
  }
250
386
  const moduleAndPublicPath = getTargetModuleInfo(id, instance);
251
387
  if (!moduleAndPublicPath) {
252
- return [...scripts, ...links];
388
+ return { scriptSrcs, stylesheetHrefs };
253
389
  }
254
390
  const { module: targetModule, publicPath, remoteEntry } = moduleAndPublicPath;
255
391
  if (injectLink) {
256
- [...targetModule.assets.css.sync, ...targetModule.assets.css.async].sort().forEach((file, index) => {
257
- links.push(
258
- /* @__PURE__ */ React__default.createElement(
259
- "link",
260
- {
261
- key: `${file.split(".")[0]}_${index}`,
262
- href: `${publicPath}${file}`,
263
- rel: "stylesheet",
264
- type: "text/css"
265
- }
266
- )
267
- );
392
+ const seenStylesheetHrefs = /* @__PURE__ */ new Set();
393
+ [...targetModule.assets.css.sync, ...targetModule.assets.css.async].sort().forEach((file) => {
394
+ const href = `${publicPath}${file}`;
395
+ if (seenStylesheetHrefs.has(href)) {
396
+ return;
397
+ }
398
+ seenStylesheetHrefs.add(href);
399
+ stylesheetHrefs.push(href);
268
400
  });
269
401
  }
270
402
  if (injectScript) {
271
- scripts.push(
272
- /* @__PURE__ */ React__default.createElement(
273
- "script",
274
- {
275
- async: true,
276
- key: remoteEntry.split(".")[0],
277
- src: `${publicPath}${remoteEntry}`,
278
- crossOrigin: "anonymous"
279
- }
280
- )
281
- );
282
- [...targetModule.assets.js.sync].sort().forEach((file, index) => {
283
- scripts.push(
284
- /* @__PURE__ */ React__default.createElement(
285
- "script",
286
- {
287
- key: `${file.split(".")[0]}_${index}`,
288
- async: true,
289
- src: `${publicPath}${file}`,
290
- crossOrigin: "anonymous"
291
- }
292
- )
293
- );
403
+ scriptSrcs.push(`${publicPath}${remoteEntry}`);
404
+ [...targetModule.assets.js.sync].sort().forEach((file) => {
405
+ scriptSrcs.push(`${publicPath}${file}`);
294
406
  });
295
407
  }
296
- return [...scripts, ...links];
408
+ return { scriptSrcs, stylesheetHrefs };
409
+ }
410
+ function renderScriptAssets(scriptSrcs) {
411
+ return scriptSrcs.map((src) => /* @__PURE__ */ React__default.createElement("script", { key: src, async: true, src, crossOrigin: "anonymous" }));
412
+ }
413
+ function collectSSRAssets(options) {
414
+ const { scriptSrcs, stylesheetHrefs } = collectSSRAssetDescriptors(options);
415
+ return [
416
+ ...renderScriptAssets(scriptSrcs),
417
+ ...stylesheetHrefs.map((href) => /* @__PURE__ */ React__default.createElement("link", { key: href, href, rel: "stylesheet", type: "text/css" }))
418
+ ];
297
419
  }
298
420
  function getServerNeedRemoteInfo(loadedRemoteInfo, id, noSSR) {
299
421
  var _a;
@@ -407,12 +529,16 @@ function createLazyComponent(options) {
407
529
  { name: instance.name, version: instance == null ? void 0 : instance.options.version }
408
530
  ) : void 0;
409
531
  logger.debug("LazyComponent dataFetchMapKey: ", dataFetchMapKey);
410
- const assets = collectSSRAssets({
532
+ const { scriptSrcs, stylesheetHrefs } = collectSSRAssetDescriptors({
411
533
  id: moduleId,
412
534
  instance,
413
535
  injectLink,
414
536
  injectScript
415
537
  });
538
+ const assets = [
539
+ ...renderScriptAssets(scriptSrcs),
540
+ /* @__PURE__ */ React__default.createElement(HydratedStylesheetAssets, { key: "stylesheets", hrefs: stylesheetHrefs })
541
+ ];
416
542
  const Com = m[exportName];
417
543
  if (exportName in m && typeof Com === "function") {
418
544
  return {
@@ -515,8 +641,8 @@ function lazyLoadComponentPlugin() {
515
641
  };
516
642
  }
517
643
  export {
518
- collectSSRAssets as a,
519
- autoFetchData as b,
520
- createLazyComponent as c,
644
+ autoFetchData as a,
645
+ createLazyComponent as b,
646
+ collectSSRAssets as c,
521
647
  lazyLoadComponentPlugin as l
522
648
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-BvnyaA6i.js");
4
- require("./prefetch-MiXeF8KH.js");
3
+ const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-DSURjnZ0.js");
4
+ require("./prefetch-Bxf6DSx_.js");
5
5
  exports.default = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
6
6
  exports.lazyLoadComponentPlugin = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
@@ -1,16 +1,2 @@
1
- import { ModuleFederationRuntimePlugin } from '@module-federation/runtime';
2
-
3
- declare function lazyLoadComponentPlugin(): ModuleFederationRuntimePlugin;
4
- export default lazyLoadComponentPlugin;
5
- export { lazyLoadComponentPlugin }
6
-
7
- export { }
8
-
9
-
10
- declare module '@module-federation/runtime-core' {
11
- interface ModuleFederation {
12
- createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
13
- prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
14
- collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
15
- }
16
- }
1
+ export { default } from './plugins/lazy-load-component-plugin';
2
+ export * from './plugins/lazy-load-component-plugin';