@module-federation/bridge-react 2.8.1 → 2.9.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.
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const prefetch = require("./prefetch-QJLnti7A.js");
2
+ const prefetch = require("./prefetch-CMvAw8F3.js");
3
3
  const lazyUtils = require("./utils-5dGErM3C.js");
4
4
  const React = require("react");
5
5
  const autoFetchData = () => {
@@ -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-BzCq3MT3.mjs";
1
+ import { i as injectDataFetch, p as prefetch } from "./prefetch-xvZIEaJL.mjs";
2
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, Suspense, useEffect } from "react";
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 {
@@ -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-DBTxuAYf.js");
4
- require("./prefetch-QJLnti7A.js");
3
+ const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-CRqjWQ5N.js");
4
+ require("./prefetch-CMvAw8F3.js");
5
5
  exports.default = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
6
6
  exports.lazyLoadComponentPlugin = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
@@ -1,5 +1,5 @@
1
- import { l, l as l2 } from "./lazy-load-component-plugin-DlagtX0O.mjs";
2
- import "./prefetch-BzCq3MT3.mjs";
1
+ import { l, l as l2 } from "./lazy-load-component-plugin-CyRfqVSE.mjs";
2
+ import "./prefetch-xvZIEaJL.mjs";
3
3
  export {
4
4
  l as default,
5
5
  l2 as lazyLoadComponentPlugin