@module-federation/bridge-react 2.8.1 → 2.8.2

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/dist/base.cjs.js CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const createHelpers = require("./createHelpers-19BP0xtB.js");
4
- const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-DBTxuAYf.js");
4
+ const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-DeTbkGlM.js");
5
5
  const lazyUtils = require("./utils-5dGErM3C.js");
6
6
  const dataFetchUtils = require("./data-fetch-utils.cjs.js");
7
- const prefetch = require("./prefetch-QJLnti7A.js");
7
+ const prefetch = require("./prefetch-CfMDdqO-.js");
8
8
  const createRemoteAppComponent = createHelpers.createRemoteAppComponentFactory(createHelpers.RemoteAppWrapper);
9
9
  const createRemoteComponent = createHelpers.createDeprecatedRemoteComponentFactory(
10
10
  createRemoteAppComponent
package/dist/base.es.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { c as createRemoteAppComponentFactory, a as createDeprecatedRemoteComponentFactory, R as RemoteAppWrapper } from "./createHelpers-BSHeKyd-.mjs";
2
2
  import { b } from "./createHelpers-BSHeKyd-.mjs";
3
- import { a, c, b as b2, l } from "./lazy-load-component-plugin-DlagtX0O.mjs";
3
+ import { a, c, b as b2, l } from "./lazy-load-component-plugin-DQFjLSsW.mjs";
4
4
  import { C, a as a2, E, c as c2, b as b3, d, g, r, s } from "./utils-BBP3hEeV.mjs";
5
5
  import { callDataFetch } from "./data-fetch-utils.es.js";
6
- import { p } from "./prefetch-BzCq3MT3.mjs";
6
+ import { p } from "./prefetch-BJZbf9LF.mjs";
7
7
  const createRemoteAppComponent = createRemoteAppComponentFactory(RemoteAppWrapper);
8
8
  const createRemoteComponent = createDeprecatedRemoteComponentFactory(
9
9
  createRemoteAppComponent
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const lazyUtils = require("./utils-5dGErM3C.js");
4
- const prefetch = require("./prefetch-QJLnti7A.js");
4
+ const prefetch = require("./prefetch-CfMDdqO-.js");
5
5
  async function callDataFetch() {
6
6
  const dataFetch = globalThis[lazyUtils.DATA_FETCH_FUNCTION];
7
7
  if (dataFetch) {
@@ -1,7 +1,7 @@
1
1
  import { y as DATA_FETCH_FUNCTION } from "./utils-BBP3hEeV.mjs";
2
2
  import { C, a, c, b, d, g, r } from "./utils-BBP3hEeV.mjs";
3
- import { d as dataFetchFunction } from "./prefetch-BzCq3MT3.mjs";
4
- import { i, p } from "./prefetch-BzCq3MT3.mjs";
3
+ import { d as dataFetchFunction } from "./prefetch-BJZbf9LF.mjs";
4
+ import { i, p } from "./prefetch-BJZbf9LF.mjs";
5
5
  async function callDataFetch() {
6
6
  const dataFetch = globalThis[DATA_FETCH_FUNCTION];
7
7
  if (dataFetch) {
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-DBTxuAYf.js");
3
+ const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-DeTbkGlM.js");
4
4
  const lazyUtils = require("./utils-5dGErM3C.js");
5
5
  const dataFetchUtils = require("./data-fetch-utils.cjs.js");
6
- const prefetch = require("./prefetch-QJLnti7A.js");
6
+ const prefetch = require("./prefetch-CfMDdqO-.js");
7
7
  exports.autoFetchDataPlugin = lazyLoadComponentPlugin.autoFetchData;
8
8
  exports.collectSSRAssets = lazyLoadComponentPlugin.collectSSRAssets;
9
9
  exports.createLazyComponent = lazyLoadComponentPlugin.createLazyComponent;
@@ -1,7 +1,7 @@
1
- import { a, c, b, l } from "./lazy-load-component-plugin-DlagtX0O.mjs";
1
+ import { a, c, b, l } from "./lazy-load-component-plugin-DQFjLSsW.mjs";
2
2
  import { C, a as a2, E, c as c2, b as b2, d, f, g, r, s } from "./utils-BBP3hEeV.mjs";
3
3
  import { callDataFetch } from "./data-fetch-utils.es.js";
4
- import { p } from "./prefetch-BzCq3MT3.mjs";
4
+ import { p } from "./prefetch-BJZbf9LF.mjs";
5
5
  export {
6
6
  C as CacheSize,
7
7
  a2 as CacheTime,
package/dist/index.cjs.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const createHelpers = require("./createHelpers-19BP0xtB.js");
4
- const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-DBTxuAYf.js");
4
+ const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-DeTbkGlM.js");
5
5
  const lazyUtils = require("./utils-5dGErM3C.js");
6
6
  const dataFetchUtils = require("./data-fetch-utils.cjs.js");
7
7
  const React = require("react");
8
8
  const ReactRouterDOM = require("react-router-dom");
9
9
  const index = require("./index-DbjGCKOr.js");
10
- const prefetch = require("./prefetch-QJLnti7A.js");
10
+ const prefetch = require("./prefetch-CfMDdqO-.js");
11
11
  function _interopNamespaceDefault(e2) {
12
12
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
13
13
  if (e2) {
package/dist/index.es.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { R as RemoteAppWrapper, c as createRemoteAppComponentFactory, a as createDeprecatedRemoteComponentFactory } from "./createHelpers-BSHeKyd-.mjs";
2
2
  import { b } from "./createHelpers-BSHeKyd-.mjs";
3
- import { a, c, b as b2, l } from "./lazy-load-component-plugin-DlagtX0O.mjs";
3
+ import { a, c, b as b2, l } from "./lazy-load-component-plugin-DQFjLSsW.mjs";
4
4
  import { C, a as a2, E, c as c2, b as b3, d, g, r, s } from "./utils-BBP3hEeV.mjs";
5
5
  import { callDataFetch } from "./data-fetch-utils.es.js";
6
6
  import React__default, { forwardRef, useContext, useState, useEffect } from "react";
7
7
  import * as ReactRouterDOM from "react-router-dom";
8
8
  import { p as pathJoin, L as LoggerInstance } from "./index-Bs2NxD2z.mjs";
9
- import { p } from "./prefetch-BzCq3MT3.mjs";
9
+ import { p } from "./prefetch-BJZbf9LF.mjs";
10
10
  function e() {
11
11
  const t = new PopStateEvent("popstate", { state: window.history.state });
12
12
  window.dispatchEvent(t);
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export declare function HydratedStylesheetAssets({ hrefs }: {
3
+ hrefs: string[];
4
+ }): React.JSX.Element;
@@ -23,6 +23,6 @@ export type CreateLazyComponentOptions<T, E extends keyof T> = {
23
23
  type ReactKey = {
24
24
  key?: React.Key | null;
25
25
  };
26
- export declare function collectSSRAssets(options: IProps): ReactNode[];
26
+ export declare function collectSSRAssets(options: IProps): React.ReactNode[];
27
27
  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) => React.JSX.Element;
28
28
  export {};
@@ -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-BJZbf9LF.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,5 +1,5 @@
1
1
  "use strict";
2
- const prefetch = require("./prefetch-QJLnti7A.js");
2
+ const prefetch = require("./prefetch-CfMDdqO-.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
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-DeTbkGlM.js");
4
+ require("./prefetch-CfMDdqO-.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-DQFjLSsW.mjs";
2
+ import "./prefetch-BJZbf9LF.mjs";
3
3
  export {
4
4
  l as default,
5
5
  l2 as lazyLoadComponentPlugin
@@ -621,21 +621,46 @@ const runtimeDescMap = {
621
621
  ...runtimeDescMap
622
622
  });
623
623
  const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
624
+ const esmRemoteEntryLoadErrorMessages = [
625
+ "Failed to fetch dynamically imported module",
626
+ "Importing a module script failed",
627
+ "error loading dynamically imported module"
628
+ ];
629
+ function isEsmRemoteEntryLoadError(err) {
630
+ if (!(err instanceof TypeError)) return false;
631
+ return esmRemoteEntryLoadErrorMessages.some((loadErrorMessage) => err.message.includes(loadErrorMessage));
632
+ }
624
633
  function isEsmRemoteType(type) {
625
634
  return type === "esm" || type === "module";
626
635
  }
627
- async function loadEsmEntry({ entry, remoteEntryExports }) {
636
+ async function loadEsmEntry({ entry, remoteEntryExports, name, getEntryUrl }) {
628
637
  return new Promise((resolve, reject) => {
638
+ const rejectEntry = (loadError) => {
639
+ if (isEsmRemoteEntryLoadError(loadError)) {
640
+ const originalMsg = loadError instanceof Error ? loadError.message : String(loadError);
641
+ try {
642
+ error(RUNTIME_008, runtimeDescMap, {
643
+ remoteName: name,
644
+ resourceUrl: url
645
+ }, originalMsg);
646
+ } catch (runtimeError) {
647
+ reject(runtimeError);
648
+ return;
649
+ }
650
+ }
651
+ reject(loadError);
652
+ };
653
+ const url = getEntryUrl ? getEntryUrl(entry) : entry;
629
654
  try {
630
- if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${entry}")${importCallback}`)([resolve, reject]);
655
+ if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${url}")${importCallback}`)([resolve, rejectEntry]);
631
656
  else import(
632
657
  /* webpackIgnore: true */
633
658
  /* @vite-ignore */
634
- entry
635
- ).then(resolve).catch(reject);
659
+ url
660
+ ).then(resolve).catch(rejectEntry);
636
661
  else resolve(remoteEntryExports);
637
662
  } catch (e) {
638
- error(`Failed to load ESM entry from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
663
+ error(`Failed to load ESM entry from "${url}". ${e instanceof Error ? e.message : String(e)}`);
639
664
  }
640
665
  });
641
666
  }
@@ -693,7 +718,9 @@ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEnt
693
718
  const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
694
719
  if (isEsmRemoteType(type)) return loadEsmEntry({
695
720
  entry,
696
- remoteEntryExports
721
+ remoteEntryExports,
722
+ name,
723
+ getEntryUrl
697
724
  });
698
725
  if (type === "system") return loadSystemJsEntry({
699
726
  entry,
@@ -622,21 +622,46 @@ const runtimeDescMap = {
622
622
  ...runtimeDescMap
623
623
  });
624
624
  const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
625
+ const esmRemoteEntryLoadErrorMessages = [
626
+ "Failed to fetch dynamically imported module",
627
+ "Importing a module script failed",
628
+ "error loading dynamically imported module"
629
+ ];
630
+ function isEsmRemoteEntryLoadError(err) {
631
+ if (!(err instanceof TypeError)) return false;
632
+ return esmRemoteEntryLoadErrorMessages.some((loadErrorMessage) => err.message.includes(loadErrorMessage));
633
+ }
625
634
  function isEsmRemoteType(type) {
626
635
  return type === "esm" || type === "module";
627
636
  }
628
- async function loadEsmEntry({ entry, remoteEntryExports }) {
637
+ async function loadEsmEntry({ entry, remoteEntryExports, name, getEntryUrl }) {
629
638
  return new Promise((resolve, reject) => {
639
+ const rejectEntry = (loadError) => {
640
+ if (isEsmRemoteEntryLoadError(loadError)) {
641
+ const originalMsg = loadError instanceof Error ? loadError.message : String(loadError);
642
+ try {
643
+ error(RUNTIME_008, runtimeDescMap, {
644
+ remoteName: name,
645
+ resourceUrl: url
646
+ }, originalMsg);
647
+ } catch (runtimeError) {
648
+ reject(runtimeError);
649
+ return;
650
+ }
651
+ }
652
+ reject(loadError);
653
+ };
654
+ const url = getEntryUrl ? getEntryUrl(entry) : entry;
630
655
  try {
631
- if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${entry}")${importCallback}`)([resolve, reject]);
656
+ if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${url}")${importCallback}`)([resolve, rejectEntry]);
632
657
  else import(
633
658
  /* webpackIgnore: true */
634
659
  /* @vite-ignore */
635
- entry
636
- ).then(resolve).catch(reject);
660
+ url
661
+ ).then(resolve).catch(rejectEntry);
637
662
  else resolve(remoteEntryExports);
638
663
  } catch (e) {
639
- error(`Failed to load ESM entry from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
664
+ error(`Failed to load ESM entry from "${url}". ${e instanceof Error ? e.message : String(e)}`);
640
665
  }
641
666
  });
642
667
  }
@@ -694,7 +719,9 @@ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEnt
694
719
  const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
695
720
  if (isEsmRemoteType(type)) return loadEsmEntry({
696
721
  entry,
697
- remoteEntryExports
722
+ remoteEntryExports,
723
+ name,
724
+ getEntryUrl
698
725
  });
699
726
  if (type === "system") return loadSystemJsEntry({
700
727
  entry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/bridge-react",
3
- "version": "2.8.1",
3
+ "version": "2.8.2",
4
4
  "sideEffects": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -147,7 +147,7 @@
147
147
  }
148
148
  },
149
149
  "dependencies": {
150
- "@module-federation/sdk": "2.8.1"
150
+ "@module-federation/sdk": "2.8.2"
151
151
  },
152
152
  "peerDependencies": {
153
153
  "react": ">=16.9.0",
@@ -179,9 +179,9 @@
179
179
  "typescript": "7.0.2",
180
180
  "vite": "^5.4.21",
181
181
  "hono": "4.12.26",
182
- "@module-federation/runtime": "2.8.1",
183
- "@module-federation/bridge-shared": "2.8.1",
184
- "@module-federation/runtime-core": "2.8.1"
182
+ "@module-federation/runtime": "2.8.2",
183
+ "@module-federation/bridge-shared": "2.8.2",
184
+ "@module-federation/runtime-core": "2.8.2"
185
185
  },
186
186
  "scripts": {
187
187
  "dev": "vite",