remote-components 0.4.9 → 0.4.11
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/{chunk-6NUHDFSH.js → chunk-3PR3SWYZ.js} +2 -2
- package/dist/{chunk-6NUHDFSH.js.map → chunk-3PR3SWYZ.js.map} +1 -1
- package/dist/{chunk-SELGX4Y2.cjs → chunk-6PZEDIAK.cjs} +2 -2
- package/dist/{chunk-SELGX4Y2.cjs.map → chunk-6PZEDIAK.cjs.map} +1 -1
- package/dist/{chunk-X6SKTJ5N.js → chunk-GR5FN73U.js} +3 -3
- package/dist/{chunk-EZG36EB4.cjs → chunk-HZP4FWPG.cjs} +22 -22
- package/dist/{chunk-ZJW3GQTP.js → chunk-M6ACTSVB.js} +2 -2
- package/dist/{chunk-4XWEMPKO.js → chunk-N6AJM72A.js} +5 -5
- package/dist/{chunk-XPMI4K3U.cjs → chunk-OSSMJQFE.cjs} +19 -19
- package/dist/{chunk-6NAV4SCF.cjs → chunk-PCHSF5LH.cjs} +23 -23
- package/dist/{chunk-T6E2WPAB.js → chunk-RHRDUJ3K.js} +3 -3
- package/dist/{chunk-J42V6HSP.cjs → chunk-RZ224NSH.cjs} +18 -18
- package/dist/{chunk-JYGC7T6L.js → chunk-VFK4HGZT.js} +2 -2
- package/dist/{chunk-VB64GQX7.cjs → chunk-XWRB6CEA.cjs} +3 -3
- package/dist/config/nextjs.cjs +5 -5
- package/dist/config/nextjs.js +1 -1
- package/dist/host/html.cjs +70 -54
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +50 -34
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +11 -11
- package/dist/host/nextjs/app/client-only.js +6 -6
- package/dist/host/nextjs/pages/client-only.cjs +42 -24
- package/dist/host/nextjs/pages/client-only.cjs.map +1 -1
- package/dist/host/nextjs/pages/client-only.d.ts +1 -1
- package/dist/host/nextjs/pages/client-only.js +42 -24
- package/dist/host/nextjs/pages/client-only.js.map +1 -1
- package/dist/host/react.cjs +7 -7
- package/dist/host/react.js +6 -6
- package/dist/internal/host/shared/shared-module-resolver.cjs +1 -1
- package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -1
- package/dist/internal/host/shared/shared-module-resolver.d.ts +4 -3
- package/dist/internal/host/shared/shared-module-resolver.js +1 -1
- package/dist/internal/host/shared/shared-module-resolver.js.map +1 -1
- package/dist/{turbopack-WAERWSWW.js → turbopack-6BSS3SYN.js} +5 -5
- package/dist/turbopack-6BSS3SYN.js.map +1 -0
- package/dist/{turbopack-6BXAJGS5.cjs → turbopack-UMJ7SLJL.cjs} +12 -12
- package/dist/{turbopack-6BXAJGS5.cjs.map → turbopack-UMJ7SLJL.cjs.map} +1 -1
- package/dist/{webpack-ZYOBNVFE.js → webpack-4QYGIVE6.js} +7 -5
- package/dist/webpack-4QYGIVE6.js.map +1 -0
- package/dist/{webpack-VTSF2B2G.cjs → webpack-65BVWX2U.cjs} +13 -11
- package/dist/{webpack-ZYOBNVFE.js.map → webpack-65BVWX2U.cjs.map} +1 -1
- package/package.json +1 -1
- package/dist/turbopack-WAERWSWW.js.map +0 -1
- package/dist/webpack-VTSF2B2G.cjs.map +0 -1
- /package/dist/{chunk-X6SKTJ5N.js.map → chunk-GR5FN73U.js.map} +0 -0
- /package/dist/{chunk-EZG36EB4.cjs.map → chunk-HZP4FWPG.cjs.map} +0 -0
- /package/dist/{chunk-ZJW3GQTP.js.map → chunk-M6ACTSVB.js.map} +0 -0
- /package/dist/{chunk-4XWEMPKO.js.map → chunk-N6AJM72A.js.map} +0 -0
- /package/dist/{chunk-XPMI4K3U.cjs.map → chunk-OSSMJQFE.cjs.map} +0 -0
- /package/dist/{chunk-6NAV4SCF.cjs.map → chunk-PCHSF5LH.cjs.map} +0 -0
- /package/dist/{chunk-T6E2WPAB.js.map → chunk-RHRDUJ3K.js.map} +0 -0
- /package/dist/{chunk-J42V6HSP.cjs.map → chunk-RZ224NSH.cjs.map} +0 -0
- /package/dist/{chunk-JYGC7T6L.js.map → chunk-VFK4HGZT.js.map} +0 -0
- /package/dist/{chunk-VB64GQX7.cjs.map → chunk-XWRB6CEA.cjs.map} +0 -0
package/dist/host/html.cjs
CHANGED
|
@@ -7,16 +7,16 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
require('../chunk-
|
|
12
|
-
require('../chunk-
|
|
13
|
-
require('../chunk-
|
|
10
|
+
var _chunkHZP4FWPGcjs = require('../chunk-HZP4FWPG.cjs');
|
|
11
|
+
require('../chunk-XWRB6CEA.cjs');
|
|
12
|
+
require('../chunk-RZ224NSH.cjs');
|
|
13
|
+
require('../chunk-PCHSF5LH.cjs');
|
|
14
14
|
require('../chunk-3AX5WLZD.cjs');
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var _chunk6PZEDIAKcjs = require('../chunk-6PZEDIAK.cjs');
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
var _chunkZ2SLBFQLcjs = require('../chunk-Z2SLBFQL.cjs');
|
|
@@ -125,10 +125,10 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
|
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
if (type === "webpack") {
|
|
128
|
-
const { webpackRuntime } = await Promise.resolve().then(() => _interopRequireWildcard(require("../webpack-
|
|
128
|
+
const { webpackRuntime } = await Promise.resolve().then(() => _interopRequireWildcard(require("../webpack-65BVWX2U.cjs")));
|
|
129
129
|
return webpackRuntime(bundle, shared, remoteShared, resolveClientUrl);
|
|
130
130
|
} else if (type === "turbopack") {
|
|
131
|
-
const { turbopackRuntime } = await Promise.resolve().then(() => _interopRequireWildcard(require("../turbopack-
|
|
131
|
+
const { turbopackRuntime } = await Promise.resolve().then(() => _interopRequireWildcard(require("../turbopack-UMJ7SLJL.cjs")));
|
|
132
132
|
return turbopackRuntime(
|
|
133
133
|
url,
|
|
134
134
|
bundle,
|
|
@@ -149,15 +149,15 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
|
|
|
149
149
|
var _jsxruntime = require('react/jsx-runtime');
|
|
150
150
|
if (typeof HTMLElement !== "undefined") {
|
|
151
151
|
class RemoteComponent extends HTMLElement {constructor(...args) { super(...args); RemoteComponent.prototype.__init.call(this);RemoteComponent.prototype.__init2.call(this);RemoteComponent.prototype.__init3.call(this);RemoteComponent.prototype.__init4.call(this);RemoteComponent.prototype.__init5.call(this);RemoteComponent.prototype.__init6.call(this);RemoteComponent.prototype.__init7.call(this); }
|
|
152
|
-
__init() {this.name =
|
|
153
|
-
__init2() {this.bundle =
|
|
152
|
+
__init() {this.name = _chunk6PZEDIAKcjs.DEFAULT_COMPONENT_NAME}
|
|
153
|
+
__init2() {this.bundle = _chunk6PZEDIAKcjs.DEFAULT_BUNDLE_NAME}
|
|
154
154
|
|
|
155
155
|
__init3() {this.__next = null}
|
|
156
156
|
__init4() {this.fouc = null}
|
|
157
|
-
__init5() {this.hostState =
|
|
157
|
+
__init5() {this.hostState = _chunkHZP4FWPGcjs.createHostState.call(void 0, )}
|
|
158
158
|
__init6() {this.root = null}
|
|
159
159
|
|
|
160
|
-
__init7() {this.emitter =
|
|
160
|
+
__init7() {this.emitter = _chunkHZP4FWPGcjs.makeEventEmitter.call(void 0, this)}
|
|
161
161
|
|
|
162
162
|
|
|
163
163
|
|
|
@@ -279,10 +279,10 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
279
279
|
let url = null;
|
|
280
280
|
let html = this.innerHTML;
|
|
281
281
|
if (src) {
|
|
282
|
-
url =
|
|
283
|
-
this.name =
|
|
282
|
+
url = _chunkHZP4FWPGcjs.getClientOrServerUrl.call(void 0, src, window.location.href);
|
|
283
|
+
this.name = _chunkHZP4FWPGcjs.resolveNameFromSrc.call(void 0, src, this.name);
|
|
284
284
|
}
|
|
285
|
-
const resolveClientUrl = url ?
|
|
285
|
+
const resolveClientUrl = url ? _chunkHZP4FWPGcjs.bindResolveClientUrl.call(void 0, this.resolveClientUrl, url.href) : void 0;
|
|
286
286
|
if (!remoteComponentChild && url) {
|
|
287
287
|
const fetchInit = {
|
|
288
288
|
credentials: this.credentials || "same-origin"
|
|
@@ -293,7 +293,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
293
293
|
);
|
|
294
294
|
let res;
|
|
295
295
|
try {
|
|
296
|
-
res = await
|
|
296
|
+
res = await _chunkHZP4FWPGcjs.fetchWithHooks.call(void 0, resolvedUrl, fetchInit, {
|
|
297
297
|
onRequest: this.onRequest,
|
|
298
298
|
onResponse: this.onResponse,
|
|
299
299
|
abortController: this.hostState.abortController
|
|
@@ -320,7 +320,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
const effectiveUrl = _nullishCoalesce(url, () => ( new URL(window.location.href)));
|
|
323
|
-
const { doc, parsed } =
|
|
323
|
+
const { doc, parsed } = _chunkHZP4FWPGcjs.preparePipeline.call(void 0, {
|
|
324
324
|
html,
|
|
325
325
|
name: this.name,
|
|
326
326
|
url: effectiveUrl,
|
|
@@ -428,32 +428,47 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
428
428
|
return abandonLoad();
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
|
+
let reactContainer = null;
|
|
431
432
|
if (!this.reactRoot) {
|
|
433
|
+
const container = document.createElement("div");
|
|
434
|
+
container.setAttribute("data-remote-component-root", "");
|
|
435
|
+
container.style.display = "contents";
|
|
436
|
+
reactContainer = container;
|
|
432
437
|
Array.from(component.children).forEach((el) => {
|
|
433
|
-
if (
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
438
|
+
if (el.tagName.toLowerCase() === "script") {
|
|
439
|
+
if (!isRemoteComponent) {
|
|
440
|
+
const newScript = document.createElement("script");
|
|
441
|
+
for (const attr of el.attributes) {
|
|
442
|
+
if (attr.name === "src") {
|
|
443
|
+
const absoluteSrc = new URL(
|
|
444
|
+
attr.value,
|
|
445
|
+
_nullishCoalesce(url, () => ( window.location.origin))
|
|
446
|
+
).href;
|
|
447
|
+
newScript.setAttribute(
|
|
448
|
+
attr.name,
|
|
449
|
+
_nullishCoalesce(_optionalChain([resolveClientUrl, 'optionalCall', _35 => _35(absoluteSrc)]), () => ( absoluteSrc))
|
|
450
|
+
);
|
|
451
|
+
} else {
|
|
452
|
+
newScript.setAttribute(attr.name, attr.value);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
newScript.textContent = el.textContent;
|
|
456
|
+
if (remoteComponentSrc) {
|
|
441
457
|
newScript.setAttribute(
|
|
442
|
-
|
|
443
|
-
|
|
458
|
+
"data-remote-component-src",
|
|
459
|
+
remoteComponentSrc
|
|
444
460
|
);
|
|
445
|
-
} else {
|
|
446
|
-
newScript.setAttribute(attr.name, attr.value);
|
|
447
461
|
}
|
|
462
|
+
_optionalChain([this, 'access', _36 => _36.root, 'optionalAccess', _37 => _37.appendChild, 'call', _38 => _38(newScript)]);
|
|
463
|
+
} else {
|
|
464
|
+
const newEl = el.cloneNode(true);
|
|
465
|
+
for (const attr of el.attributes) {
|
|
466
|
+
if (attr.name.startsWith("on")) {
|
|
467
|
+
newEl.setAttribute(attr.name, attr.value);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
_optionalChain([this, 'access', _39 => _39.root, 'optionalAccess', _40 => _40.appendChild, 'call', _41 => _41(newEl)]);
|
|
448
471
|
}
|
|
449
|
-
newScript.textContent = el.textContent;
|
|
450
|
-
if (remoteComponentSrc) {
|
|
451
|
-
newScript.setAttribute(
|
|
452
|
-
"data-remote-component-src",
|
|
453
|
-
remoteComponentSrc
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
_optionalChain([this, 'access', _36 => _36.root, 'optionalAccess', _37 => _37.appendChild, 'call', _38 => _38(newScript)]);
|
|
457
472
|
} else {
|
|
458
473
|
const newEl = el.cloneNode(true);
|
|
459
474
|
for (const attr of el.attributes) {
|
|
@@ -461,16 +476,17 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
461
476
|
newEl.setAttribute(attr.name, attr.value);
|
|
462
477
|
}
|
|
463
478
|
}
|
|
464
|
-
|
|
479
|
+
container.appendChild(newEl);
|
|
465
480
|
}
|
|
466
481
|
});
|
|
482
|
+
_optionalChain([this, 'access', _42 => _42.root, 'optionalAccess', _43 => _43.appendChild, 'call', _44 => _44(container)]);
|
|
467
483
|
}
|
|
468
484
|
for (const el of removable) {
|
|
469
|
-
_optionalChain([el, 'access',
|
|
485
|
+
_optionalChain([el, 'access', _45 => _45.parentElement, 'optionalAccess', _46 => _46.removeChild, 'call', _47 => _47(el)]);
|
|
470
486
|
}
|
|
471
|
-
_optionalChain([this, 'access',
|
|
487
|
+
_optionalChain([this, 'access', _48 => _48.fallbackSlot, 'optionalAccess', _49 => _49.remove, 'call', _50 => _50()]);
|
|
472
488
|
const applyReset = () => {
|
|
473
|
-
if (this.reset && !_optionalChain([this, 'access',
|
|
489
|
+
if (this.reset && !_optionalChain([this, 'access', _51 => _51.root, 'optionalAccess', _52 => _52.querySelector, 'call', _53 => _53("link[data-remote-components-reset]")])) {
|
|
474
490
|
const allInitial = document.createElement("link");
|
|
475
491
|
allInitial.setAttribute("data-remote-components-reset", "");
|
|
476
492
|
const css = `:host { all: initial; }`;
|
|
@@ -487,9 +503,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
487
503
|
URL.revokeObjectURL(allInitialHref);
|
|
488
504
|
allInitial.removeAttribute("onload");
|
|
489
505
|
};
|
|
490
|
-
_optionalChain([this, 'access',
|
|
491
|
-
} else if (!this.reset && _optionalChain([this, 'access',
|
|
492
|
-
_optionalChain([this, 'access',
|
|
506
|
+
_optionalChain([this, 'access', _54 => _54.root, 'optionalAccess', _55 => _55.prepend, 'call', _56 => _56(allInitial)]);
|
|
507
|
+
} else if (!this.reset && _optionalChain([this, 'access', _57 => _57.root, 'optionalAccess', _58 => _58.querySelector, 'call', _59 => _59("link[data-remote-components-reset]")])) {
|
|
508
|
+
_optionalChain([this, 'access', _60 => _60.root, 'access', _61 => _61.querySelector, 'call', _62 => _62("link[data-remote-components-reset]"), 'optionalAccess', _63 => _63.remove, 'call', _64 => _64()]);
|
|
493
509
|
}
|
|
494
510
|
};
|
|
495
511
|
if (!this.reactRoot) {
|
|
@@ -552,13 +568,13 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
552
568
|
}
|
|
553
569
|
};
|
|
554
570
|
if (rsc) {
|
|
555
|
-
_optionalChain([rsc, 'access',
|
|
556
|
-
const rscName = `__remote_component_rsc_${
|
|
571
|
+
_optionalChain([rsc, 'access', _65 => _65.parentElement, 'optionalAccess', _66 => _66.removeChild, 'call', _67 => _67(rsc)]);
|
|
572
|
+
const rscName = `__remote_component_rsc_${_chunk6PZEDIAKcjs.escapeString.call(void 0,
|
|
557
573
|
url.href
|
|
558
|
-
)}_${
|
|
574
|
+
)}_${_chunk6PZEDIAKcjs.escapeString.call(void 0, this.name)}`;
|
|
559
575
|
const rscClone = document.createElement("script");
|
|
560
576
|
rscClone.id = `${rscName}_rsc`;
|
|
561
|
-
rscClone.textContent = _nullishCoalesce(_optionalChain([rsc, 'access',
|
|
577
|
+
rscClone.textContent = _nullishCoalesce(_optionalChain([rsc, 'access', _68 => _68.textContent, 'optionalAccess', _69 => _69.replace, 'call', _70 => _70(
|
|
562
578
|
new RegExp(`self\\["${this.name}"\\]`, "g"),
|
|
563
579
|
`self["${rscName}"]`
|
|
564
580
|
)]), () => ( ""));
|
|
@@ -568,7 +584,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
568
584
|
name,
|
|
569
585
|
initial
|
|
570
586
|
}) => {
|
|
571
|
-
const stream =
|
|
587
|
+
const stream = _chunkHZP4FWPGcjs.createRSCStream.call(void 0,
|
|
572
588
|
rscName,
|
|
573
589
|
_nullishCoalesce(self[rscName], () => ( [`0:[null]
|
|
574
590
|
`]))
|
|
@@ -613,9 +629,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
613
629
|
return;
|
|
614
630
|
}
|
|
615
631
|
this.reactRoot = _client.hydrateRoot.call(void 0,
|
|
616
|
-
//
|
|
617
|
-
// @ts-expect-error
|
|
618
|
-
this.root,
|
|
632
|
+
// hydrate into the dedicated wrapper (falls back to the ShadowRoot)
|
|
633
|
+
// @ts-expect-error this.root is a ShadowRoot, accepted at runtime
|
|
634
|
+
_nullishCoalesce(reactContainer, () => ( this.root)),
|
|
619
635
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, RemoteComponentFromReadableStream, { initial: true, name: this.name })
|
|
620
636
|
);
|
|
621
637
|
} else if (nextData) {
|
|
@@ -653,9 +669,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
653
669
|
return;
|
|
654
670
|
}
|
|
655
671
|
this.reactRoot = _client.hydrateRoot.call(void 0,
|
|
656
|
-
//
|
|
657
|
-
// @ts-expect-error
|
|
658
|
-
this.root,
|
|
672
|
+
// hydrate into the dedicated wrapper (falls back to the ShadowRoot)
|
|
673
|
+
// @ts-expect-error this.root is a ShadowRoot, accepted at runtime
|
|
674
|
+
_nullishCoalesce(reactContainer, () => ( this.root)),
|
|
659
675
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, RemoteComponentFromNext, { initial: true })
|
|
660
676
|
);
|
|
661
677
|
}
|
package/dist/host/html.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/host/html/index.tsx","../../src/host/html/attach-styles.ts","../../src/host/html/runtime/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiB,uBAAuB;AACjD,SAAS,mBAAmB;;;AC4B5B,eAAsB,aAAa;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuC;AAErC,QAAM,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,SAAS,IAAI,IAAI,KAAK,CAAC,CAAC,EAAE;AAAA,YAClD,OAAO,UAAU;AACf,kBAAI;AACF,sBAAM,MAAM,KAAK,IAAI;AAAA,cACvB,SAAS,GAAP;AACA;AAAA,kBACE;AAAA,kBACA,yDAAyD,IAAI;AAAA,kBAC7D;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAEA,aAAK,QAAQ,KAAK,KAAK,OAAO,EAAE;AAAA,MAClC,OAAO;AACL,aAAK,QAAQ,KAAK,KAAK,OAAO,EAAE;AAAA,MAClC;AAEA,UAAI,cAAc,GAAG;AACnB,aAAK,UAAU,QAAQ;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AAGA,iBAAe,OAAO,oBAAoB,eAAe;AAC3D;AAEO,SAAS,sBACd,UAAkD,CAAC,GACnD;AACA,QAAM,KAAK,aAAa;AACxB,SAAO,QAAQ,OAAO,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAChD,OAAG,kBAAkB,GAAG,IAAI;AAAA,EAC9B,CAAC;AACH","sourcesContent":["import { startTransition, useLayoutEffect } from 'react';\nimport { hydrateRoot } from 'react-dom/client';\nimport { fetchWithHooks } from '#internal/host/server/fetch-with-hooks';\nimport { getClientOrServerUrl } from '#internal/host/server/get-client-or-server-url';\nimport type {\n ConsumeClientConfig,\n ConsumeServerConfig,\n} from '#internal/host/shared/config';\nimport {\n type LifecycleEmitter,\n makeEventEmitter,\n} from '#internal/host/shared/lifecycle';\nimport { preparePipeline } from '#internal/host/shared/pipeline';\nimport type { HostState } from '#internal/host/shared/state';\nimport { createHostState } from '#internal/host/shared/state';\nimport { resolveNameFromSrc } from '#internal/host/utils/resolve-name-from-src';\nimport {\n DEFAULT_BUNDLE_NAME,\n DEFAULT_COMPONENT_NAME,\n} from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { createRSCStream } from '#internal/runtime/rsc';\nimport type { RSCKey } from '#internal/runtime/types';\nimport { bindResolveClientUrl } from '#internal/runtime/url/default-resolve-client-url';\nimport { escapeString } from '#internal/utils';\nimport { isAbortError } from '#internal/utils/abort';\nimport {\n errorFromFailedFetch,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport { logError } from '#internal/utils/logger';\nimport { attachStyles } from './attach-styles';\nimport { getRuntime, type Runtime } from './runtime';\n\nif (typeof HTMLElement !== 'undefined') {\n /**\n * `<remote-component>` custom element — the HTML host implementation.\n *\n * Implements {@link ConsumeClientConfig}\n * via typed property accessors that reflect to/from DOM attributes.\n *\n * {@link ConsumeLifecycleCallbacks} are dispatched as DOM events:\n * `beforeload`, `load`, `error`, `change`.\n */\n class RemoteComponent extends HTMLElement implements ConsumeClientConfig {\n name: string = DEFAULT_COMPONENT_NAME;\n bundle: string = DEFAULT_BUNDLE_NAME;\n fallbackSlot?: HTMLSlotElement;\n __next: HTMLDivElement | null = null;\n fouc: HTMLStyleElement | null = null;\n hostState: HostState = createHostState();\n root?: ShadowRoot | null = null;\n reactRoot?: ReturnType<typeof hydrateRoot>;\n emitter: LifecycleEmitter = makeEventEmitter(this);\n onRequest?: ConsumeServerConfig['onRequest'];\n onResponse?: ConsumeServerConfig['onResponse'];\n resolveClientUrl?: ConsumeClientConfig['resolveClientUrl'];\n\n // -- ConsumeServerConfig property accessors (attribute-reflected) --\n\n get src(): string | URL | undefined {\n return this.getAttribute('src') ?? undefined;\n }\n\n set src(value: string | URL | undefined) {\n if (value == null) {\n this.removeAttribute('src');\n } else {\n this.setAttribute('src', String(value));\n }\n }\n\n /** Always `true` — the HTML host always isolates via Shadow DOM. */\n get isolate(): boolean {\n return true;\n }\n\n get mode(): 'open' | 'closed' | undefined {\n const attr = this.getAttribute('mode');\n return attr === 'closed' ? 'closed' : 'open';\n }\n\n set mode(value: 'open' | 'closed' | undefined) {\n if (value) {\n this.setAttribute('mode', value);\n }\n }\n\n get reset(): boolean | undefined {\n return this.getAttribute('reset') !== null;\n }\n\n set reset(value: boolean | undefined) {\n if (value) {\n this.setAttribute('reset', '');\n } else {\n this.removeAttribute('reset');\n }\n }\n\n get credentials(): RequestCredentials | undefined {\n return (this.getAttribute('credentials') ||\n 'same-origin') as RequestCredentials;\n }\n\n set credentials(value: RequestCredentials | undefined) {\n if (value) {\n this.setAttribute('credentials', value);\n } else {\n this.removeAttribute('credentials');\n }\n }\n\n static get observedAttributes() {\n return ['src', 'name', 'mode'];\n }\n\n attributeChangedCallback(name: string, oldValue: string, newValue: string) {\n if ((name === 'src' || name === 'name') && oldValue !== newValue) {\n if (this.src) {\n this.load().catch((e) => {\n // AbortError is expected when loading is cancelled - don't log or dispatch\n if (isAbortError(e)) {\n return;\n }\n logError('HtmlHost', 'Error loading remote component.', e);\n this.emitter.error(e, this.src);\n this.hostState.stage = 'error';\n });\n }\n } else if (name === 'mode' && oldValue !== newValue && this.root) {\n // changing the shadow DOM mode is not supported\n // we need to recreate the shadow DOM and reload the component\n const newRoot = this.attachShadow({\n mode: newValue === 'closed' ? 'closed' : 'open',\n });\n // move all existing children to the new shadow root\n Array.from(this.root.children).forEach((child) => {\n newRoot.appendChild(child);\n });\n this.root = newRoot;\n // reload the remote component to apply the new shadow DOM\n this.load().catch((e) => {\n // AbortError is expected when loading is cancelled - don't log or dispatch\n if (isAbortError(e)) {\n return;\n }\n logError('HtmlHost', 'Error reloading remote component.', e);\n this.emitter.error(e, this.src);\n });\n }\n }\n\n async load() {\n // wait for the current call stack to finish\n await new Promise((resolve) => {\n (typeof queueMicrotask === 'function'\n ? queueMicrotask\n : requestAnimationFrame)(() => {\n resolve(undefined);\n });\n });\n\n // Abort any in-progress load so the latest src always wins.\n if (this.hostState.stage === 'loading') {\n this.hostState.abortController?.abort();\n this.hostState.stage = 'idle';\n // The aborted load may have already appended partial content to the shadow DOM\n // (styles, component children) before reaching an isCurrentLoad() check.\n // Clear it now so the new load starts from a clean state. Skip this when a\n // React root exists — that means a previous load completed successfully and\n // we'll take the startTransition re-render path instead.\n if (this.root && !this.reactRoot) {\n this.root.innerHTML = '';\n this.fouc = null;\n this.fallbackSlot = document.createElement('slot');\n this.root.appendChild(this.fallbackSlot);\n }\n }\n\n if (!this.root) {\n this.root = this.attachShadow({\n mode: this.mode === 'closed' ? 'closed' : 'open',\n });\n\n // create a slot element to allow the remote component to use the default slot\n this.fallbackSlot = document.createElement('slot');\n this.root.appendChild(this.fallbackSlot);\n }\n\n this.name = this.getAttribute('name') || this.name;\n\n this.hostState.stage = 'loading';\n const src = this.src;\n\n // Create AbortController for this load operation\n this.hostState.abortController = new AbortController();\n const signal = this.hostState.abortController.signal;\n\n // Returns true if this is still the active load — the signal hasn't been\n // aborted by a newer load() call, and the src hasn't changed in the meantime.\n // Checking the signal (not just the src) handles the case where the user\n // cycles back to the same src (e.g. styled → basic → styled): both loads\n // share the same src string, so a src-only check would pass for both,\n // causing double renders.\n const isCurrentLoad = () => !signal.aborted && this.src === src;\n\n // Resets stage to 'idle' for expected cancellations (AbortError). Real\n // errors are thrown and caught by attributeChangedCallback which sets\n // stage to 'error'. Only resets if no newer load() has superseded this\n // one — a new load replaces the abortController so the signal comparison\n // fails, preventing us from clobbering the new load's stage.\n const abandonLoad = () => {\n if (\n this.hostState.abortController?.signal === signal &&\n this.hostState.stage === 'loading'\n ) {\n this.hostState.stage = 'idle';\n }\n };\n\n this.emitter.beforeLoad(src ?? '');\n\n const remoteComponentChild =\n this.querySelector('div#__REMOTE_COMPONENT__') ||\n this.querySelector('div[data-bundle][data-route]');\n\n if (!src && !remoteComponentChild) {\n throw new RemoteComponentsError('\"src\" attribute is required');\n }\n\n let url: URL | null = null;\n let html = this.innerHTML;\n\n if (src) {\n url = getClientOrServerUrl(src, window.location.href);\n this.name = resolveNameFromSrc(src, this.name);\n }\n\n const resolveClientUrl = url\n ? bindResolveClientUrl(this.resolveClientUrl, url.href)\n : undefined;\n\n if (!remoteComponentChild && url) {\n // fetch the remote component\n const fetchInit = {\n credentials: this.credentials || 'same-origin',\n } as RequestInit;\n\n const resolvedUrl = new URL(\n resolveClientUrl?.(url.href) ?? url.href,\n window.location.href,\n );\n let res: Response;\n try {\n res = await fetchWithHooks(resolvedUrl, fetchInit, {\n onRequest: this.onRequest,\n onResponse: this.onResponse,\n abortController: this.hostState.abortController,\n });\n } catch (e) {\n if (isAbortError(e)) {\n return abandonLoad();\n }\n throw e;\n }\n\n if (!res || !res.ok) {\n throw await errorFromFailedFetch(url.href, resolvedUrl, res);\n }\n\n // get the full HTML content as a string - race with abort signal\n try {\n html = await res.text();\n } catch (e) {\n if (isAbortError(e)) {\n return abandonLoad();\n }\n throw e;\n }\n if (!isCurrentLoad()) {\n return abandonLoad();\n }\n }\n\n const effectiveUrl = url ?? new URL(window.location.href);\n const { doc, parsed } = preparePipeline({\n html,\n name: this.name,\n url: effectiveUrl,\n shared: {},\n resolveClientUrl,\n });\n const {\n component,\n name: resolvedName,\n isRemoteComponent,\n metadata: parsedMetadata,\n nextData,\n rsc,\n remoteShared,\n } = parsed;\n\n // when using a Next.js Pages Router remote application in development mode\n // we hide the remote component to prevent flickering\n // until the CSS is loaded for the remote component\n if (nextData && nextData.buildId === 'development' && !this.reactRoot) {\n this.fouc = document.createElement('style');\n this.fouc.textContent = `:host { display: none; }`;\n this.root.appendChild(this.fouc);\n }\n\n this.name = resolvedName;\n this.bundle = parsedMetadata.bundle;\n\n if (url) {\n getNamespace().bundleUrls[this.bundle] = url;\n }\n\n // add remote component metadata information at the custom element\n const metadataEl = document.createElement('script');\n metadataEl.type = 'application/json';\n metadataEl.setAttribute('data-remote-component', '');\n const metadataObj = {\n name: this.name,\n bundle: this.bundle,\n route: parsedMetadata.route,\n runtime: parsedMetadata.runtime,\n };\n metadataEl.textContent = JSON.stringify(metadataObj);\n\n if (\n this.previousElementSibling?.getAttribute('data-remote-component') !==\n null\n ) {\n this.previousElementSibling?.remove();\n }\n this.parentElement?.insertBefore(metadataEl, this);\n\n if (this.hostState.prevIsRemoteComponent) {\n if (this.hostState.prevUrl) {\n const prevUrl = this.hostState.prevUrl;\n const nsUnmount = getNamespace();\n if (nsUnmount.unmountFns[prevUrl.href]) {\n // call unmount() for all registered unmount functions for the previous remote component\n await Promise.all(\n Array.from(nsUnmount.unmountFns[prevUrl.href] ?? []).map(\n async (unmount) => {\n try {\n await unmount(this.root);\n } catch (e) {\n logError(\n 'HtmlHost',\n `Error while calling unmount() for Remote Component from ${prevUrl.href}.`,\n e,\n );\n }\n },\n ),\n );\n if (!isCurrentLoad()) {\n return abandonLoad();\n }\n }\n }\n this.root.innerHTML = '';\n }\n // Dispatch change event if this is not the first load\n if (this.hostState.prevSrc !== undefined) {\n this.emitter.change({\n previousSrc: this.hostState.prevSrc ?? null,\n nextSrc: src ?? null,\n previousName: this.hostState.prevName,\n nextName: this.name,\n });\n }\n\n this.hostState.prevUrl = effectiveUrl;\n this.hostState.prevIsRemoteComponent = isRemoteComponent;\n this.hostState.prevSrc = src;\n this.hostState.prevName = this.name;\n\n // store the original loading content of the custom element\n // this is required to remove the loading content after the remote component is loaded\n const removable = Array.from(this.childNodes);\n\n // reference to all link elements in the remote component\n const links = doc.querySelectorAll<HTMLLinkElement>('link[href]');\n\n const remoteComponentSrc = this.src ? String(this.src) : null;\n\n // Bound function for attaching styles — used both initially and in React effects\n const doAttachStyles = () =>\n attachStyles({\n doc,\n component,\n links,\n signal: undefined, // Effects run after load, no abort needed\n baseUrl: url?.href,\n remoteComponentSrc,\n root: this.root ?? null,\n resolveClientUrl,\n });\n\n if (!this.reactRoot) {\n // ensure all styles are loaded before hydrating to prevent FOUC\n await attachStyles({\n doc,\n component,\n links,\n signal,\n baseUrl: url?.href,\n remoteComponentSrc,\n root: this.root,\n resolveClientUrl,\n });\n if (!isCurrentLoad()) {\n return abandonLoad();\n }\n }\n\n if (!this.reactRoot) {\n // attach the remote component content to the shadow DOM\n Array.from(component.children).forEach((el) => {\n if (!isRemoteComponent && el.tagName.toLowerCase() === 'script') {\n const newScript = document.createElement('script');\n // copy all attributes\n for (const attr of el.attributes) {\n if (attr.name === 'src') {\n const absoluteSrc = new URL(\n attr.value,\n url ?? window.location.origin,\n ).href;\n newScript.setAttribute(\n attr.name,\n resolveClientUrl?.(absoluteSrc) ?? absoluteSrc,\n );\n } else {\n newScript.setAttribute(attr.name, attr.value);\n }\n }\n newScript.textContent = el.textContent;\n if (remoteComponentSrc) {\n newScript.setAttribute(\n 'data-remote-component-src',\n remoteComponentSrc,\n );\n }\n this.root?.appendChild(newScript);\n } else {\n const newEl = el.cloneNode(true) as HTMLElement;\n for (const attr of el.attributes) {\n if (attr.name.startsWith('on')) {\n newEl.setAttribute(attr.name, attr.value);\n }\n }\n this.root?.appendChild(newEl);\n }\n });\n }\n\n // clear the loading content of the shadow DOM root\n for (const el of removable) {\n el.parentElement?.removeChild(el);\n }\n this.fallbackSlot?.remove();\n\n // function to apply the reset styles to the shadow DOM\n const applyReset = () => {\n if (\n this.reset &&\n !this.root?.querySelector('link[data-remote-components-reset]')\n ) {\n // all initial styles to reset inherited styles leaking from the host page\n const allInitial = document.createElement('link');\n allInitial.setAttribute('data-remote-components-reset', '');\n const css = `:host { all: initial; }`;\n const allInitialHref = URL.createObjectURL(\n new Blob([css], { type: 'text/css' }),\n );\n allInitial.href = allInitialHref;\n allInitial.rel = 'stylesheet';\n // we need to revoke the object URL after the stylesheet is loaded to free up memory\n allInitial.onload = () => {\n URL.revokeObjectURL(allInitialHref);\n allInitial.removeAttribute('onload');\n };\n allInitial.onerror = () => {\n URL.revokeObjectURL(allInitialHref);\n allInitial.removeAttribute('onload');\n };\n this.root?.prepend(allInitial);\n } else if (\n !this.reset &&\n this.root?.querySelector('link[data-remote-components-reset]')\n ) {\n this.root\n .querySelector('link[data-remote-components-reset]')\n ?.remove();\n }\n };\n\n // apply the reset styles if required and not already applied\n if (!this.reactRoot) {\n applyReset();\n }\n\n const {\n self,\n createFromReadableStream,\n nextClientPagesLoader,\n preloadScripts,\n } = await getRuntime(\n metadataObj.runtime as Runtime,\n effectiveUrl,\n this.bundle,\n {\n react: async () => (await import('react')).default,\n 'react/jsx-dev-runtime': async () =>\n (await import('react/jsx-dev-runtime')).default,\n 'react/jsx-runtime': async () =>\n (await import('react/jsx-runtime')).default,\n 'react-dom': async () => (await import('react-dom')).default,\n 'react-dom/client': async () =>\n (await import('react-dom/client')).default,\n },\n remoteShared,\n resolveClientUrl,\n );\n if (!isCurrentLoad()) {\n return abandonLoad();\n }\n\n const scripts = isRemoteComponent\n ? component.querySelectorAll<HTMLScriptElement>('script')\n : doc.querySelectorAll<HTMLScriptElement>(\n 'script[src],script[data-src],script[data-remote-component-entrypoint]',\n );\n if (!url) {\n url = new URL(\n component.getAttribute('data-route') ?? '/',\n window.location.href,\n );\n }\n\n await preloadScripts(Array.from(scripts), url, this.bundle, this.name);\n if (!isCurrentLoad()) {\n return abandonLoad();\n }\n\n // remove all script elements from the shadow DOM to prevent re-execution of scripts\n if (isRemoteComponent) {\n Array.from(component.children).forEach((child) => {\n if (child.tagName === 'SCRIPT') {\n child.remove();\n }\n });\n }\n\n // cleanup previous remote component instances when a new remote component is loaded\n // this is required when the src attribute is changed to load a new remote component\n const doCleanup = () => {\n if (this.root && remoteComponentSrc) {\n const selector = `[data-remote-component-src]:not([data-remote-component-src=\"${remoteComponentSrc}\"])`;\n const prevCleanup = [\n ...this.root.querySelectorAll(selector),\n ...document.body.querySelectorAll(selector),\n ] as HTMLElement[];\n\n if (prevCleanup.length > 0) {\n prevCleanup.forEach((prev) => {\n prev.remove();\n });\n }\n }\n };\n\n // using RSC hydration if the RSC flight data is available\n if (rsc) {\n // remove the RSC flight data script element\n rsc.parentElement?.removeChild(rsc);\n\n // reload the RSC flight data script to eval it's content\n const rscName = `__remote_component_rsc_${escapeString(\n url.href,\n )}_${escapeString(this.name)}`;\n const rscClone = document.createElement('script');\n rscClone.id = `${rscName}_rsc`;\n rscClone.textContent =\n rsc.textContent?.replace(\n new RegExp(`self\\\\[\"${this.name}\"\\\\]`, 'g'),\n `self[\"${rscName}\"]`,\n ) ?? '';\n document.body.appendChild(rscClone);\n\n let cache: React.ReactNode;\n // React component to convert the RSC flight data into a React component\n const RemoteComponentFromReadableStream = ({\n name,\n initial,\n }: {\n name: string;\n initial: boolean;\n }) => {\n // convert the RSC flight data array into a ReadableStream\n // get the RSC flight data from the global scope\n // the RSC flight data is stored in an array\n // fallback to an empty RSC payload if the data is not found\n const stream = createRSCStream(\n rscName,\n self[rscName as RSCKey] ?? [`0:[null]\\n`],\n );\n const Component =\n cache ??\n // cache the component to avoid reloading the RSC flight data\n (cache = createFromReadableStream(stream) as React.ReactNode);\n\n useLayoutEffect(() => {\n // clear the RSC flight data from the global scope to free up memory\n if (self[name as RSCKey]) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete self[name as RSCKey];\n }\n const rscScript = document.getElementById(`${name}_rsc`);\n if (rscScript) {\n rscScript.remove();\n }\n\n doCleanup();\n applyReset();\n if (!initial) {\n doAttachStyles().catch((e: unknown) => {\n logError('HtmlHost', 'Error attaching styles.', e);\n });\n }\n if (isCurrentLoad()) {\n this.hostState.stage = 'loaded';\n }\n\n this.emitter.load(this.src ?? '');\n }, [initial, name]);\n\n // React can handle the component reference and will wait for the component to be ready\n return Component;\n };\n\n // when we already have a React root, we just need to render the new component\n if (this.reactRoot) {\n const root = this.reactRoot;\n startTransition(() => {\n root.render(\n <RemoteComponentFromReadableStream\n initial={false}\n name={this.name}\n />,\n );\n });\n return;\n }\n\n // hydrate the remote component using the RSC flight data\n this.reactRoot = hydrateRoot(\n // hydrateRoot expects a document or element, but it works for the shadow DOM too\n // @ts-expect-error support for shadow DOM\n this.root,\n <RemoteComponentFromReadableStream initial name={this.name} />,\n );\n } else if (nextData) {\n // using Next.js client pages loader if the Next.js hydration data is available\n const { Component, App } = nextClientPagesLoader(\n this.bundle,\n nextData.page ?? '/',\n this.root,\n );\n\n // if we have the component, we can hydrate it\n if (Component) {\n const RemoteComponentFromNext = ((\n NextApp: ReturnType<typeof nextClientPagesLoader>['App'],\n NextComponent: NonNullable<\n ReturnType<typeof nextClientPagesLoader>['Component']\n >,\n remoteComponent = this,\n ) =>\n function RemoteComponentNext({ initial }: { initial: boolean }) {\n useLayoutEffect(() => {\n doCleanup();\n if (!initial) {\n applyReset();\n doAttachStyles().catch((e: unknown) => {\n logError('HtmlHost', 'Error attaching styles.', e);\n });\n }\n if (isCurrentLoad()) {\n remoteComponent.hostState.stage = 'loaded';\n }\n\n remoteComponent.emitter.load(remoteComponent.src ?? '');\n }, [initial, remoteComponent]);\n\n return NextApp ? (\n <NextApp Component={NextComponent} {...nextData.props} />\n ) : (\n <NextComponent {...nextData.props} />\n );\n })(App, Component, this);\n\n // when we already have a React root, we just need to render the new component\n if (this.reactRoot) {\n const root = this.reactRoot;\n startTransition(() => {\n root.render(<RemoteComponentFromNext initial={false} />);\n doCleanup();\n if (isCurrentLoad()) {\n this.hostState.stage = 'loaded';\n }\n });\n return;\n }\n\n // hydrate the remote component using the Next.js pages router\n this.reactRoot = hydrateRoot(\n // hydrateRoot expects a document or element, but it works for the shadow DOM too\n // @ts-expect-error support for shadow DOM\n this.root,\n <RemoteComponentFromNext initial />,\n );\n }\n\n // remove the FOUC workaround style element to show the remote component\n // this is only for development mode\n if (this.fouc) {\n this.root.removeChild(this.fouc);\n }\n } else if (getNamespace().mountFns[url.href]) {\n // using script entrypoint when no RSC or Next.js data is available\n await Promise.all(\n Array.from(getNamespace().mountFns[url.href] ?? []).map(\n async (mount) => {\n try {\n await mount(this.root);\n } catch (e) {\n logError(\n 'HtmlHost',\n `Error while calling mount() for Remote Component from ${url.href}.`,\n e,\n );\n }\n },\n ),\n );\n\n this.emitter.load(this.src ?? '');\n } else {\n this.emitter.load(this.src ?? '');\n }\n\n if (isCurrentLoad()) {\n this.hostState.stage = 'loaded';\n }\n }\n }\n\n // register the custom element\n customElements.define('remote-component', RemoteComponent);\n}\n\nexport function registerSharedModules(\n modules: Record<string, () => Promise<unknown>> = {},\n) {\n const ns = getNamespace();\n Object.entries(modules).forEach(([key, value]) => {\n ns.hostSharedModules[key] = value;\n });\n}\n","import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\ninterface AttachStylesOptions {\n /** The parsed document containing link and style elements */\n doc: Document;\n /** The component element to check if links are already contained */\n component: Element;\n /** Links from the document head */\n links: NodeListOf<HTMLLinkElement>;\n /** AbortSignal to cancel loading */\n signal: AbortSignal | undefined;\n /** Base URL for resolving relative hrefs */\n baseUrl: string | undefined;\n /** Source URL to set as data attribute */\n remoteComponentSrc: string | null;\n /** Root element to append styles to (ShadowRoot or Element) */\n root: ShadowRoot | Element | null;\n /** Callback to transform asset URLs before loading */\n resolveClientUrl?: InternalResolveClientUrl;\n}\n\n/**\n * Attaches link and style elements from a remote component document to the shadow root.\n * Handles abort signals efficiently with a single shared listener for all links.\n *\n * @throws DOMException with name 'AbortError' if signal is aborted\n * @throws RemoteComponentsError if a stylesheet fails to load\n */\nexport async function attachStyles({\n doc,\n component,\n links,\n signal,\n baseUrl,\n remoteComponentSrc,\n root,\n resolveClientUrl,\n}: AttachStylesOptions): Promise<void> {\n // Track appended links for cleanup on abort\n const appendedLinks: HTMLLinkElement[] = [];\n\n // Single shared abort promise - avoids N listeners for N links\n let abortReject: ((error: DOMException) => void) | null = null;\n const abortPromise = new Promise<never>((_, reject) => {\n abortReject = reject;\n });\n const abortHandler = () => {\n // Clean up all pending links on abort\n for (const link of appendedLinks) {\n link.onload = null;\n link.onerror = null;\n link.remove();\n }\n abortReject?.(new DOMException('Aborted', 'AbortError'));\n };\n signal?.addEventListener('abort', abortHandler, { once: true });\n\n try {\n // Attach each link element to the shadow DOM to load the styles\n await Promise.all(\n Array.from(links)\n .filter((link) => !component.contains(link))\n .map((link) => {\n const newLink = document.createElement('link');\n appendedLinks.push(newLink);\n\n const loadPromise = new Promise<void>((resolve, reject) => {\n if (link.rel === 'stylesheet') {\n // TODO: needs to be cancellable with a singular listener for the abort signal https://linear.app/vercel/issue/MFES-1253/handle-abortcontroller-clean-up-scenarios\n newLink.onload = () => resolve();\n newLink.onerror = () =>\n reject(\n new RemoteComponentsError(\n `Failed to load <link href=\"${link.href}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n } else {\n resolve();\n }\n });\n\n for (const attr of link.attributes) {\n if (attr.name === 'href') {\n const absoluteHref = new URL(\n attr.value,\n baseUrl ?? location.origin,\n ).href;\n newLink.setAttribute(\n attr.name,\n resolveClientUrl?.(absoluteHref) ?? absoluteHref,\n );\n } else {\n newLink.setAttribute(attr.name, attr.value);\n }\n }\n\n if (remoteComponentSrc) {\n newLink.setAttribute(\n 'data-remote-component-src',\n remoteComponentSrc,\n );\n }\n\n // TODO: needs to be cancellable with a singular listener for the abort signal https://linear.app/vercel/issue/MFES-1253/handle-abortcontroller-clean-up-scenarios\n root?.appendChild(newLink);\n\n // Race each link load against the shared abort promise\n return Promise.race([loadPromise, abortPromise]);\n }),\n );\n } finally {\n signal?.removeEventListener('abort', abortHandler);\n }\n\n // Attach inline styles from the document head\n const styles = doc.querySelectorAll<HTMLStyleElement>('style');\n for (const style of styles) {\n if (style.parentElement?.tagName.toLowerCase() === 'head') {\n const newStyle = document.createElement('style');\n newStyle.textContent = style.textContent;\n\n if (remoteComponentSrc) {\n newStyle.setAttribute('data-remote-component-src', remoteComponentSrc);\n }\n\n root?.appendChild(newStyle);\n }\n }\n}\n","import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { RemoteSharedModules } from '#internal/host/shared/shared-broker';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\nexport type Runtime = 'webpack' | 'turbopack' | 'script' | 'unknown';\n\nexport async function getRuntime(\n type: Runtime,\n url: URL,\n bundle: string,\n shared?: Record<string, () => Promise<unknown>>,\n remoteShared?: RemoteSharedModules,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n // minimally mock process.env for browser environments\n if (typeof globalThis.process === 'undefined') {\n globalThis.process = {\n env: {},\n } as NodeJS.Process;\n }\n\n if (type === 'webpack') {\n const { webpackRuntime } = await import(`./webpack`);\n return webpackRuntime(bundle, shared, remoteShared, resolveClientUrl);\n } else if (type === 'turbopack') {\n const { turbopackRuntime } = await import(`./turbopack`);\n return turbopackRuntime(\n url,\n bundle,\n shared,\n remoteShared,\n resolveClientUrl,\n );\n } else if (type === 'script') {\n const { scriptRuntime } = await import(`./script`);\n return scriptRuntime(resolveClientUrl);\n }\n throw new RemoteComponentsError(\n `Remote Components runtime \"${type}\" is not supported. Supported runtimes are \"webpack\", \"turbopack\", and \"script\".`,\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/host/html/index.tsx","../../src/host/html/attach-styles.ts","../../src/host/html/runtime/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiB,uBAAuB;AACjD,SAAS,mBAAmB;;;AC4B5B,eAAsB,aAAa;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuC;AAErC,QAAM,gBAAmC,CAAC;AAG1C,MAAI,cAAsD;AAC1D,QAAM,eAAe,IAAI,QAAe,CAAC,GAAG,WAAW;AACrD,kBAAc;AAAA,EAChB,CAAC;AACD,QAAM,eAAe,MAAM;AAEzB,eAAW,QAAQ,eAAe;AAChC,WAAK,SAAS;AACd,WAAK,UAAU;AACf,WAAK,OAAO;AAAA,IACd;AACA,kBAAc,IAAI,aAAa,WAAW,YAAY,CAAC;AAAA,EACzD;AACA,UAAQ,iBAAiB,SAAS,cAAc,EAAE,MAAM,KAAK,CAAC;AAE9D,MAAI;AAEF,UAAM,QAAQ;AAAA,MACZ,MAAM,KAAK,KAAK,EACb,OAAO,CAAC,SAAS,CAAC,UAAU,SAAS,IAAI,CAAC,EAC1C,IAAI,CAAC,SAAS;AACb,cAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,sBAAc,KAAK,OAAO;AAE1B,cAAM,cAAc,IAAI,QAAc,CAAC,SAAS,WAAW;AACzD,cAAI,K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AAyD,IAAI;AAAA,kBAC7D;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAEA,aAAK,QAAQ,KAAK,KAAK,OAAO,EAAE;AAAA,MAClC,OAAO;AACL,aAAK,QAAQ,KAAK,KAAK,OAAO,EAAE;AAAA,MAClC;AAEA,UAAI,cAAc,GAAG;AACnB,aAAK,UAAU,QAAQ;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AAGA,iBAAe,OAAO,oBAAoB,eAAe;AAC3D;AAEO,SAAS,sBACd,UAAkD,CAAC,GACnD;AACA,QAAM,KAAK,aAAa;AACxB,SAAO,QAAQ,OAAO,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAChD,OAAG,kBAAkB,GAAG,IAAI;AAAA,EAC9B,CAAC;AACH","sourcesContent":["import { startTransition, useLayoutEffect } from 'react';\nimport { hydrateRoot } from 'react-dom/client';\nimport { fetchWithHooks } from '#internal/host/server/fetch-with-hooks';\nimport { getClientOrServerUrl } from '#internal/host/server/get-client-or-server-url';\nimport type {\n ConsumeClientConfig,\n ConsumeServerConfig,\n} from '#internal/host/shared/config';\nimport {\n type LifecycleEmitter,\n makeEventEmitter,\n} from '#internal/host/shared/lifecycle';\nimport { preparePipeline } from '#internal/host/shared/pipeline';\nimport type { HostState } from '#internal/host/shared/state';\nimport { createHostState } from '#internal/host/shared/state';\nimport { resolveNameFromSrc } from '#internal/host/utils/resolve-name-from-src';\nimport {\n DEFAULT_BUNDLE_NAME,\n DEFAULT_COMPONENT_NAME,\n} from '#internal/runtime/constants';\nimport { getNamespace } from '#internal/runtime/namespace';\nimport { createRSCStream } from '#internal/runtime/rsc';\nimport type { RSCKey } from '#internal/runtime/types';\nimport { bindResolveClientUrl } from '#internal/runtime/url/default-resolve-client-url';\nimport { escapeString } from '#internal/utils';\nimport { isAbortError } from '#internal/utils/abort';\nimport {\n errorFromFailedFetch,\n RemoteComponentsError,\n} from '#internal/utils/error';\nimport { logError } from '#internal/utils/logger';\nimport { attachStyles } from './attach-styles';\nimport { getRuntime, type Runtime } from './runtime';\n\nif (typeof HTMLElement !== 'undefined') {\n /**\n * `<remote-component>` custom element — the HTML host implementation.\n *\n * Implements {@link ConsumeClientConfig}\n * via typed property accessors that reflect to/from DOM attributes.\n *\n * {@link ConsumeLifecycleCallbacks} are dispatched as DOM events:\n * `beforeload`, `load`, `error`, `change`.\n */\n class RemoteComponent extends HTMLElement implements ConsumeClientConfig {\n name: string = DEFAULT_COMPONENT_NAME;\n bundle: string = DEFAULT_BUNDLE_NAME;\n fallbackSlot?: HTMLSlotElement;\n __next: HTMLDivElement | null = null;\n fouc: HTMLStyleElement | null = null;\n hostState: HostState = createHostState();\n root?: ShadowRoot | null = null;\n reactRoot?: ReturnType<typeof hydrateRoot>;\n emitter: LifecycleEmitter = makeEventEmitter(this);\n onRequest?: ConsumeServerConfig['onRequest'];\n onResponse?: ConsumeServerConfig['onResponse'];\n resolveClientUrl?: ConsumeClientConfig['resolveClientUrl'];\n\n // -- ConsumeServerConfig property accessors (attribute-reflected) --\n\n get src(): string | URL | undefined {\n return this.getAttribute('src') ?? undefined;\n }\n\n set src(value: string | URL | undefined) {\n if (value == null) {\n this.removeAttribute('src');\n } else {\n this.setAttribute('src', String(value));\n }\n }\n\n /** Always `true` — the HTML host always isolates via Shadow DOM. */\n get isolate(): boolean {\n return true;\n }\n\n get mode(): 'open' | 'closed' | undefined {\n const attr = this.getAttribute('mode');\n return attr === 'closed' ? 'closed' : 'open';\n }\n\n set mode(value: 'open' | 'closed' | undefined) {\n if (value) {\n this.setAttribute('mode', value);\n }\n }\n\n get reset(): boolean | undefined {\n return this.getAttribute('reset') !== null;\n }\n\n set reset(value: boolean | undefined) {\n if (value) {\n this.setAttribute('reset', '');\n } else {\n this.removeAttribute('reset');\n }\n }\n\n get credentials(): RequestCredentials | undefined {\n return (this.getAttribute('credentials') ||\n 'same-origin') as RequestCredentials;\n }\n\n set credentials(value: RequestCredentials | undefined) {\n if (value) {\n this.setAttribute('credentials', value);\n } else {\n this.removeAttribute('credentials');\n }\n }\n\n static get observedAttributes() {\n return ['src', 'name', 'mode'];\n }\n\n attributeChangedCallback(name: string, oldValue: string, newValue: string) {\n if ((name === 'src' || name === 'name') && oldValue !== newValue) {\n if (this.src) {\n this.load().catch((e) => {\n // AbortError is expected when loading is cancelled - don't log or dispatch\n if (isAbortError(e)) {\n return;\n }\n logError('HtmlHost', 'Error loading remote component.', e);\n this.emitter.error(e, this.src);\n this.hostState.stage = 'error';\n });\n }\n } else if (name === 'mode' && oldValue !== newValue && this.root) {\n // changing the shadow DOM mode is not supported\n // we need to recreate the shadow DOM and reload the component\n const newRoot = this.attachShadow({\n mode: newValue === 'closed' ? 'closed' : 'open',\n });\n // move all existing children to the new shadow root\n Array.from(this.root.children).forEach((child) => {\n newRoot.appendChild(child);\n });\n this.root = newRoot;\n // reload the remote component to apply the new shadow DOM\n this.load().catch((e) => {\n // AbortError is expected when loading is cancelled - don't log or dispatch\n if (isAbortError(e)) {\n return;\n }\n logError('HtmlHost', 'Error reloading remote component.', e);\n this.emitter.error(e, this.src);\n });\n }\n }\n\n async load() {\n // wait for the current call stack to finish\n await new Promise((resolve) => {\n (typeof queueMicrotask === 'function'\n ? queueMicrotask\n : requestAnimationFrame)(() => {\n resolve(undefined);\n });\n });\n\n // Abort any in-progress load so the latest src always wins.\n if (this.hostState.stage === 'loading') {\n this.hostState.abortController?.abort();\n this.hostState.stage = 'idle';\n // The aborted load may have already appended partial content to the shadow DOM\n // (styles, component children) before reaching an isCurrentLoad() check.\n // Clear it now so the new load starts from a clean state. Skip this when a\n // React root exists — that means a previous load completed successfully and\n // we'll take the startTransition re-render path instead.\n if (this.root && !this.reactRoot) {\n this.root.innerHTML = '';\n this.fouc = null;\n this.fallbackSlot = document.createElement('slot');\n this.root.appendChild(this.fallbackSlot);\n }\n }\n\n if (!this.root) {\n this.root = this.attachShadow({\n mode: this.mode === 'closed' ? 'closed' : 'open',\n });\n\n // create a slot element to allow the remote component to use the default slot\n this.fallbackSlot = document.createElement('slot');\n this.root.appendChild(this.fallbackSlot);\n }\n\n this.name = this.getAttribute('name') || this.name;\n\n this.hostState.stage = 'loading';\n const src = this.src;\n\n // Create AbortController for this load operation\n this.hostState.abortController = new AbortController();\n const signal = this.hostState.abortController.signal;\n\n // Returns true if this is still the active load — the signal hasn't been\n // aborted by a newer load() call, and the src hasn't changed in the meantime.\n // Checking the signal (not just the src) handles the case where the user\n // cycles back to the same src (e.g. styled → basic → styled): both loads\n // share the same src string, so a src-only check would pass for both,\n // causing double renders.\n const isCurrentLoad = () => !signal.aborted && this.src === src;\n\n // Resets stage to 'idle' for expected cancellations (AbortError). Real\n // errors are thrown and caught by attributeChangedCallback which sets\n // stage to 'error'. Only resets if no newer load() has superseded this\n // one — a new load replaces the abortController so the signal comparison\n // fails, preventing us from clobbering the new load's stage.\n const abandonLoad = () => {\n if (\n this.hostState.abortController?.signal === signal &&\n this.hostState.stage === 'loading'\n ) {\n this.hostState.stage = 'idle';\n }\n };\n\n this.emitter.beforeLoad(src ?? '');\n\n const remoteComponentChild =\n this.querySelector('div#__REMOTE_COMPONENT__') ||\n this.querySelector('div[data-bundle][data-route]');\n\n if (!src && !remoteComponentChild) {\n throw new RemoteComponentsError('\"src\" attribute is required');\n }\n\n let url: URL | null = null;\n let html = this.innerHTML;\n\n if (src) {\n url = getClientOrServerUrl(src, window.location.href);\n this.name = resolveNameFromSrc(src, this.name);\n }\n\n const resolveClientUrl = url\n ? bindResolveClientUrl(this.resolveClientUrl, url.href)\n : undefined;\n\n if (!remoteComponentChild && url) {\n // fetch the remote component\n const fetchInit = {\n credentials: this.credentials || 'same-origin',\n } as RequestInit;\n\n const resolvedUrl = new URL(\n resolveClientUrl?.(url.href) ?? url.href,\n window.location.href,\n );\n let res: Response;\n try {\n res = await fetchWithHooks(resolvedUrl, fetchInit, {\n onRequest: this.onRequest,\n onResponse: this.onResponse,\n abortController: this.hostState.abortController,\n });\n } catch (e) {\n if (isAbortError(e)) {\n return abandonLoad();\n }\n throw e;\n }\n\n if (!res || !res.ok) {\n throw await errorFromFailedFetch(url.href, resolvedUrl, res);\n }\n\n // get the full HTML content as a string - race with abort signal\n try {\n html = await res.text();\n } catch (e) {\n if (isAbortError(e)) {\n return abandonLoad();\n }\n throw e;\n }\n if (!isCurrentLoad()) {\n return abandonLoad();\n }\n }\n\n const effectiveUrl = url ?? new URL(window.location.href);\n const { doc, parsed } = preparePipeline({\n html,\n name: this.name,\n url: effectiveUrl,\n shared: {},\n resolveClientUrl,\n });\n const {\n component,\n name: resolvedName,\n isRemoteComponent,\n metadata: parsedMetadata,\n nextData,\n rsc,\n remoteShared,\n } = parsed;\n\n // when using a Next.js Pages Router remote application in development mode\n // we hide the remote component to prevent flickering\n // until the CSS is loaded for the remote component\n if (nextData && nextData.buildId === 'development' && !this.reactRoot) {\n this.fouc = document.createElement('style');\n this.fouc.textContent = `:host { display: none; }`;\n this.root.appendChild(this.fouc);\n }\n\n this.name = resolvedName;\n this.bundle = parsedMetadata.bundle;\n\n if (url) {\n getNamespace().bundleUrls[this.bundle] = url;\n }\n\n // add remote component metadata information at the custom element\n const metadataEl = document.createElement('script');\n metadataEl.type = 'application/json';\n metadataEl.setAttribute('data-remote-component', '');\n const metadataObj = {\n name: this.name,\n bundle: this.bundle,\n route: parsedMetadata.route,\n runtime: parsedMetadata.runtime,\n };\n metadataEl.textContent = JSON.stringify(metadataObj);\n\n if (\n this.previousElementSibling?.getAttribute('data-remote-component') !==\n null\n ) {\n this.previousElementSibling?.remove();\n }\n this.parentElement?.insertBefore(metadataEl, this);\n\n if (this.hostState.prevIsRemoteComponent) {\n if (this.hostState.prevUrl) {\n const prevUrl = this.hostState.prevUrl;\n const nsUnmount = getNamespace();\n if (nsUnmount.unmountFns[prevUrl.href]) {\n // call unmount() for all registered unmount functions for the previous remote component\n await Promise.all(\n Array.from(nsUnmount.unmountFns[prevUrl.href] ?? []).map(\n async (unmount) => {\n try {\n await unmount(this.root);\n } catch (e) {\n logError(\n 'HtmlHost',\n `Error while calling unmount() for Remote Component from ${prevUrl.href}.`,\n e,\n );\n }\n },\n ),\n );\n if (!isCurrentLoad()) {\n return abandonLoad();\n }\n }\n }\n this.root.innerHTML = '';\n }\n // Dispatch change event if this is not the first load\n if (this.hostState.prevSrc !== undefined) {\n this.emitter.change({\n previousSrc: this.hostState.prevSrc ?? null,\n nextSrc: src ?? null,\n previousName: this.hostState.prevName,\n nextName: this.name,\n });\n }\n\n this.hostState.prevUrl = effectiveUrl;\n this.hostState.prevIsRemoteComponent = isRemoteComponent;\n this.hostState.prevSrc = src;\n this.hostState.prevName = this.name;\n\n // store the original loading content of the custom element\n // this is required to remove the loading content after the remote component is loaded\n const removable = Array.from(this.childNodes);\n\n // reference to all link elements in the remote component\n const links = doc.querySelectorAll<HTMLLinkElement>('link[href]');\n\n const remoteComponentSrc = this.src ? String(this.src) : null;\n\n // Bound function for attaching styles — used both initially and in React effects\n const doAttachStyles = () =>\n attachStyles({\n doc,\n component,\n links,\n signal: undefined, // Effects run after load, no abort needed\n baseUrl: url?.href,\n remoteComponentSrc,\n root: this.root ?? null,\n resolveClientUrl,\n });\n\n if (!this.reactRoot) {\n // ensure all styles are loaded before hydrating to prevent FOUC\n await attachStyles({\n doc,\n component,\n links,\n signal,\n baseUrl: url?.href,\n remoteComponentSrc,\n root: this.root,\n resolveClientUrl,\n });\n if (!isCurrentLoad()) {\n return abandonLoad();\n }\n }\n\n // React hydrates into this dedicated wrapper, not the ShadowRoot directly.\n // It holds ONLY the remote's server-rendered markup; framework nodes in\n // the ShadowRoot (preload <link>s, RSC flight <script>, reset stylesheet)\n // stay outside it. On a hydration mismatch React's client-render recovery\n // only removes the stale server nodes when the container is a plain\n // Element — inside a ShadowRoot interleaved with non-React nodes the\n // cleanup silently fails and the subtree renders twice (PR #286).\n // `display: contents` keeps the wrapper layout-transparent so content\n // lays out as it did directly in the ShadowRoot.\n let reactContainer: HTMLElement | null = null;\n\n if (!this.reactRoot) {\n const container = document.createElement('div');\n container.setAttribute('data-remote-component-root', '');\n container.style.display = 'contents';\n reactContainer = container;\n\n // attach the remote component content to the shadow DOM\n Array.from(component.children).forEach((el) => {\n if (el.tagName.toLowerCase() === 'script') {\n if (!isRemoteComponent) {\n const newScript = document.createElement('script');\n // copy all attributes\n for (const attr of el.attributes) {\n if (attr.name === 'src') {\n const absoluteSrc = new URL(\n attr.value,\n url ?? window.location.origin,\n ).href;\n newScript.setAttribute(\n attr.name,\n resolveClientUrl?.(absoluteSrc) ?? absoluteSrc,\n );\n } else {\n newScript.setAttribute(attr.name, attr.value);\n }\n }\n newScript.textContent = el.textContent;\n if (remoteComponentSrc) {\n newScript.setAttribute(\n 'data-remote-component-src',\n remoteComponentSrc,\n );\n }\n this.root?.appendChild(newScript);\n } else {\n // remote-component scripts (RSC flight data, entrypoints) are not\n // part of React's hydrated tree — keep them in the ShadowRoot,\n // outside the hydration container.\n const newEl = el.cloneNode(true) as HTMLElement;\n for (const attr of el.attributes) {\n if (attr.name.startsWith('on')) {\n newEl.setAttribute(attr.name, attr.value);\n }\n }\n this.root?.appendChild(newEl);\n }\n } else {\n const newEl = el.cloneNode(true) as HTMLElement;\n for (const attr of el.attributes) {\n if (attr.name.startsWith('on')) {\n newEl.setAttribute(attr.name, attr.value);\n }\n }\n container.appendChild(newEl);\n }\n });\n\n this.root?.appendChild(container);\n }\n\n // clear the loading content of the shadow DOM root\n for (const el of removable) {\n el.parentElement?.removeChild(el);\n }\n this.fallbackSlot?.remove();\n\n // function to apply the reset styles to the shadow DOM\n const applyReset = () => {\n if (\n this.reset &&\n !this.root?.querySelector('link[data-remote-components-reset]')\n ) {\n // all initial styles to reset inherited styles leaking from the host page\n const allInitial = document.createElement('link');\n allInitial.setAttribute('data-remote-components-reset', '');\n const css = `:host { all: initial; }`;\n const allInitialHref = URL.createObjectURL(\n new Blob([css], { type: 'text/css' }),\n );\n allInitial.href = allInitialHref;\n allInitial.rel = 'stylesheet';\n // we need to revoke the object URL after the stylesheet is loaded to free up memory\n allInitial.onload = () => {\n URL.revokeObjectURL(allInitialHref);\n allInitial.removeAttribute('onload');\n };\n allInitial.onerror = () => {\n URL.revokeObjectURL(allInitialHref);\n allInitial.removeAttribute('onload');\n };\n this.root?.prepend(allInitial);\n } else if (\n !this.reset &&\n this.root?.querySelector('link[data-remote-components-reset]')\n ) {\n this.root\n .querySelector('link[data-remote-components-reset]')\n ?.remove();\n }\n };\n\n // apply the reset styles if required and not already applied\n if (!this.reactRoot) {\n applyReset();\n }\n\n const {\n self,\n createFromReadableStream,\n nextClientPagesLoader,\n preloadScripts,\n } = await getRuntime(\n metadataObj.runtime as Runtime,\n effectiveUrl,\n this.bundle,\n {\n react: async () => (await import('react')).default,\n 'react/jsx-dev-runtime': async () =>\n (await import('react/jsx-dev-runtime')).default,\n 'react/jsx-runtime': async () =>\n (await import('react/jsx-runtime')).default,\n 'react-dom': async () => (await import('react-dom')).default,\n 'react-dom/client': async () =>\n (await import('react-dom/client')).default,\n },\n remoteShared,\n resolveClientUrl,\n );\n if (!isCurrentLoad()) {\n return abandonLoad();\n }\n\n const scripts = isRemoteComponent\n ? component.querySelectorAll<HTMLScriptElement>('script')\n : doc.querySelectorAll<HTMLScriptElement>(\n 'script[src],script[data-src],script[data-remote-component-entrypoint]',\n );\n if (!url) {\n url = new URL(\n component.getAttribute('data-route') ?? '/',\n window.location.href,\n );\n }\n\n await preloadScripts(Array.from(scripts), url, this.bundle, this.name);\n if (!isCurrentLoad()) {\n return abandonLoad();\n }\n\n // remove all script elements from the shadow DOM to prevent re-execution of scripts\n if (isRemoteComponent) {\n Array.from(component.children).forEach((child) => {\n if (child.tagName === 'SCRIPT') {\n child.remove();\n }\n });\n }\n\n // cleanup previous remote component instances when a new remote component is loaded\n // this is required when the src attribute is changed to load a new remote component\n const doCleanup = () => {\n if (this.root && remoteComponentSrc) {\n const selector = `[data-remote-component-src]:not([data-remote-component-src=\"${remoteComponentSrc}\"])`;\n const prevCleanup = [\n ...this.root.querySelectorAll(selector),\n ...document.body.querySelectorAll(selector),\n ] as HTMLElement[];\n\n if (prevCleanup.length > 0) {\n prevCleanup.forEach((prev) => {\n prev.remove();\n });\n }\n }\n };\n\n // using RSC hydration if the RSC flight data is available\n if (rsc) {\n // remove the RSC flight data script element\n rsc.parentElement?.removeChild(rsc);\n\n // reload the RSC flight data script to eval it's content\n const rscName = `__remote_component_rsc_${escapeString(\n url.href,\n )}_${escapeString(this.name)}`;\n const rscClone = document.createElement('script');\n rscClone.id = `${rscName}_rsc`;\n rscClone.textContent =\n rsc.textContent?.replace(\n new RegExp(`self\\\\[\"${this.name}\"\\\\]`, 'g'),\n `self[\"${rscName}\"]`,\n ) ?? '';\n document.body.appendChild(rscClone);\n\n let cache: React.ReactNode;\n // React component to convert the RSC flight data into a React component\n const RemoteComponentFromReadableStream = ({\n name,\n initial,\n }: {\n name: string;\n initial: boolean;\n }) => {\n // convert the RSC flight data array into a ReadableStream\n // get the RSC flight data from the global scope\n // the RSC flight data is stored in an array\n // fallback to an empty RSC payload if the data is not found\n const stream = createRSCStream(\n rscName,\n self[rscName as RSCKey] ?? [`0:[null]\\n`],\n );\n const Component =\n cache ??\n // cache the component to avoid reloading the RSC flight data\n (cache = createFromReadableStream(stream) as React.ReactNode);\n\n useLayoutEffect(() => {\n // clear the RSC flight data from the global scope to free up memory\n if (self[name as RSCKey]) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete self[name as RSCKey];\n }\n const rscScript = document.getElementById(`${name}_rsc`);\n if (rscScript) {\n rscScript.remove();\n }\n\n doCleanup();\n applyReset();\n if (!initial) {\n doAttachStyles().catch((e: unknown) => {\n logError('HtmlHost', 'Error attaching styles.', e);\n });\n }\n if (isCurrentLoad()) {\n this.hostState.stage = 'loaded';\n }\n\n this.emitter.load(this.src ?? '');\n }, [initial, name]);\n\n // React can handle the component reference and will wait for the component to be ready\n return Component;\n };\n\n // when we already have a React root, we just need to render the new component\n if (this.reactRoot) {\n const root = this.reactRoot;\n startTransition(() => {\n root.render(\n <RemoteComponentFromReadableStream\n initial={false}\n name={this.name}\n />,\n );\n });\n return;\n }\n\n // hydrate the remote component using the RSC flight data\n this.reactRoot = hydrateRoot(\n // hydrate into the dedicated wrapper (falls back to the ShadowRoot)\n // @ts-expect-error this.root is a ShadowRoot, accepted at runtime\n reactContainer ?? this.root,\n <RemoteComponentFromReadableStream initial name={this.name} />,\n );\n } else if (nextData) {\n // using Next.js client pages loader if the Next.js hydration data is available\n const { Component, App } = nextClientPagesLoader(\n this.bundle,\n nextData.page ?? '/',\n this.root,\n );\n\n // if we have the component, we can hydrate it\n if (Component) {\n const RemoteComponentFromNext = ((\n NextApp: ReturnType<typeof nextClientPagesLoader>['App'],\n NextComponent: NonNullable<\n ReturnType<typeof nextClientPagesLoader>['Component']\n >,\n remoteComponent = this,\n ) =>\n function RemoteComponentNext({ initial }: { initial: boolean }) {\n useLayoutEffect(() => {\n doCleanup();\n if (!initial) {\n applyReset();\n doAttachStyles().catch((e: unknown) => {\n logError('HtmlHost', 'Error attaching styles.', e);\n });\n }\n if (isCurrentLoad()) {\n remoteComponent.hostState.stage = 'loaded';\n }\n\n remoteComponent.emitter.load(remoteComponent.src ?? '');\n }, [initial, remoteComponent]);\n\n return NextApp ? (\n <NextApp Component={NextComponent} {...nextData.props} />\n ) : (\n <NextComponent {...nextData.props} />\n );\n })(App, Component, this);\n\n // when we already have a React root, we just need to render the new component\n if (this.reactRoot) {\n const root = this.reactRoot;\n startTransition(() => {\n root.render(<RemoteComponentFromNext initial={false} />);\n doCleanup();\n if (isCurrentLoad()) {\n this.hostState.stage = 'loaded';\n }\n });\n return;\n }\n\n // hydrate the remote component using the Next.js pages router\n this.reactRoot = hydrateRoot(\n // hydrate into the dedicated wrapper (falls back to the ShadowRoot)\n // @ts-expect-error this.root is a ShadowRoot, accepted at runtime\n reactContainer ?? this.root,\n <RemoteComponentFromNext initial />,\n );\n }\n\n // remove the FOUC workaround style element to show the remote component\n // this is only for development mode\n if (this.fouc) {\n this.root.removeChild(this.fouc);\n }\n } else if (getNamespace().mountFns[url.href]) {\n // using script entrypoint when no RSC or Next.js data is available\n await Promise.all(\n Array.from(getNamespace().mountFns[url.href] ?? []).map(\n async (mount) => {\n try {\n await mount(this.root);\n } catch (e) {\n logError(\n 'HtmlHost',\n `Error while calling mount() for Remote Component from ${url.href}.`,\n e,\n );\n }\n },\n ),\n );\n\n this.emitter.load(this.src ?? '');\n } else {\n this.emitter.load(this.src ?? '');\n }\n\n if (isCurrentLoad()) {\n this.hostState.stage = 'loaded';\n }\n }\n }\n\n // register the custom element\n customElements.define('remote-component', RemoteComponent);\n}\n\nexport function registerSharedModules(\n modules: Record<string, () => Promise<unknown>> = {},\n) {\n const ns = getNamespace();\n Object.entries(modules).forEach(([key, value]) => {\n ns.hostSharedModules[key] = value;\n });\n}\n","import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\ninterface AttachStylesOptions {\n /** The parsed document containing link and style elements */\n doc: Document;\n /** The component element to check if links are already contained */\n component: Element;\n /** Links from the document head */\n links: NodeListOf<HTMLLinkElement>;\n /** AbortSignal to cancel loading */\n signal: AbortSignal | undefined;\n /** Base URL for resolving relative hrefs */\n baseUrl: string | undefined;\n /** Source URL to set as data attribute */\n remoteComponentSrc: string | null;\n /** Root element to append styles to (ShadowRoot or Element) */\n root: ShadowRoot | Element | null;\n /** Callback to transform asset URLs before loading */\n resolveClientUrl?: InternalResolveClientUrl;\n}\n\n/**\n * Attaches link and style elements from a remote component document to the shadow root.\n * Handles abort signals efficiently with a single shared listener for all links.\n *\n * @throws DOMException with name 'AbortError' if signal is aborted\n * @throws RemoteComponentsError if a stylesheet fails to load\n */\nexport async function attachStyles({\n doc,\n component,\n links,\n signal,\n baseUrl,\n remoteComponentSrc,\n root,\n resolveClientUrl,\n}: AttachStylesOptions): Promise<void> {\n // Track appended links for cleanup on abort\n const appendedLinks: HTMLLinkElement[] = [];\n\n // Single shared abort promise - avoids N listeners for N links\n let abortReject: ((error: DOMException) => void) | null = null;\n const abortPromise = new Promise<never>((_, reject) => {\n abortReject = reject;\n });\n const abortHandler = () => {\n // Clean up all pending links on abort\n for (const link of appendedLinks) {\n link.onload = null;\n link.onerror = null;\n link.remove();\n }\n abortReject?.(new DOMException('Aborted', 'AbortError'));\n };\n signal?.addEventListener('abort', abortHandler, { once: true });\n\n try {\n // Attach each link element to the shadow DOM to load the styles\n await Promise.all(\n Array.from(links)\n .filter((link) => !component.contains(link))\n .map((link) => {\n const newLink = document.createElement('link');\n appendedLinks.push(newLink);\n\n const loadPromise = new Promise<void>((resolve, reject) => {\n if (link.rel === 'stylesheet') {\n // TODO: needs to be cancellable with a singular listener for the abort signal https://linear.app/vercel/issue/MFES-1253/handle-abortcontroller-clean-up-scenarios\n newLink.onload = () => resolve();\n newLink.onerror = () =>\n reject(\n new RemoteComponentsError(\n `Failed to load <link href=\"${link.href}\"> for Remote Component. Check the URL is correct.`,\n ),\n );\n } else {\n resolve();\n }\n });\n\n for (const attr of link.attributes) {\n if (attr.name === 'href') {\n const absoluteHref = new URL(\n attr.value,\n baseUrl ?? location.origin,\n ).href;\n newLink.setAttribute(\n attr.name,\n resolveClientUrl?.(absoluteHref) ?? absoluteHref,\n );\n } else {\n newLink.setAttribute(attr.name, attr.value);\n }\n }\n\n if (remoteComponentSrc) {\n newLink.setAttribute(\n 'data-remote-component-src',\n remoteComponentSrc,\n );\n }\n\n // TODO: needs to be cancellable with a singular listener for the abort signal https://linear.app/vercel/issue/MFES-1253/handle-abortcontroller-clean-up-scenarios\n root?.appendChild(newLink);\n\n // Race each link load against the shared abort promise\n return Promise.race([loadPromise, abortPromise]);\n }),\n );\n } finally {\n signal?.removeEventListener('abort', abortHandler);\n }\n\n // Attach inline styles from the document head\n const styles = doc.querySelectorAll<HTMLStyleElement>('style');\n for (const style of styles) {\n if (style.parentElement?.tagName.toLowerCase() === 'head') {\n const newStyle = document.createElement('style');\n newStyle.textContent = style.textContent;\n\n if (remoteComponentSrc) {\n newStyle.setAttribute('data-remote-component-src', remoteComponentSrc);\n }\n\n root?.appendChild(newStyle);\n }\n }\n}\n","import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport type { RemoteSharedModules } from '#internal/host/shared/shared-broker';\nimport { RemoteComponentsError } from '#internal/utils/error';\n\nexport type Runtime = 'webpack' | 'turbopack' | 'script' | 'unknown';\n\nexport async function getRuntime(\n type: Runtime,\n url: URL,\n bundle: string,\n shared?: Record<string, () => Promise<unknown>>,\n remoteShared?: RemoteSharedModules,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n // minimally mock process.env for browser environments\n if (typeof globalThis.process === 'undefined') {\n globalThis.process = {\n env: {},\n } as NodeJS.Process;\n }\n\n if (type === 'webpack') {\n const { webpackRuntime } = await import(`./webpack`);\n return webpackRuntime(bundle, shared, remoteShared, resolveClientUrl);\n } else if (type === 'turbopack') {\n const { turbopackRuntime } = await import(`./turbopack`);\n return turbopackRuntime(\n url,\n bundle,\n shared,\n remoteShared,\n resolveClientUrl,\n );\n } else if (type === 'script') {\n const { scriptRuntime } = await import(`./script`);\n return scriptRuntime(resolveClientUrl);\n }\n throw new RemoteComponentsError(\n `Remote Components runtime \"${type}\" is not supported. Supported runtimes are \"webpack\", \"turbopack\", and \"script\".`,\n );\n}\n"]}
|
package/dist/host/html.js
CHANGED
|
@@ -7,16 +7,16 @@ import {
|
|
|
7
7
|
makeEventEmitter,
|
|
8
8
|
preparePipeline,
|
|
9
9
|
resolveNameFromSrc
|
|
10
|
-
} from "../chunk-
|
|
11
|
-
import "../chunk-
|
|
12
|
-
import "../chunk-
|
|
13
|
-
import "../chunk-
|
|
10
|
+
} from "../chunk-N6AJM72A.js";
|
|
11
|
+
import "../chunk-M6ACTSVB.js";
|
|
12
|
+
import "../chunk-GR5FN73U.js";
|
|
13
|
+
import "../chunk-VFK4HGZT.js";
|
|
14
14
|
import "../chunk-LEKG4YWI.js";
|
|
15
15
|
import {
|
|
16
16
|
DEFAULT_BUNDLE_NAME,
|
|
17
17
|
DEFAULT_COMPONENT_NAME,
|
|
18
18
|
escapeString
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-3PR3SWYZ.js";
|
|
20
20
|
import {
|
|
21
21
|
getNamespace
|
|
22
22
|
} from "../chunk-D5GNZB6O.js";
|
|
@@ -125,10 +125,10 @@ async function getRuntime(type, url, bundle, shared, remoteShared, resolveClient
|
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
if (type === "webpack") {
|
|
128
|
-
const { webpackRuntime } = await import("../webpack-
|
|
128
|
+
const { webpackRuntime } = await import("../webpack-4QYGIVE6.js");
|
|
129
129
|
return webpackRuntime(bundle, shared, remoteShared, resolveClientUrl);
|
|
130
130
|
} else if (type === "turbopack") {
|
|
131
|
-
const { turbopackRuntime } = await import("../turbopack-
|
|
131
|
+
const { turbopackRuntime } = await import("../turbopack-6BSS3SYN.js");
|
|
132
132
|
return turbopackRuntime(
|
|
133
133
|
url,
|
|
134
134
|
bundle,
|
|
@@ -428,32 +428,47 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
428
428
|
return abandonLoad();
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
|
+
let reactContainer = null;
|
|
431
432
|
if (!this.reactRoot) {
|
|
433
|
+
const container = document.createElement("div");
|
|
434
|
+
container.setAttribute("data-remote-component-root", "");
|
|
435
|
+
container.style.display = "contents";
|
|
436
|
+
reactContainer = container;
|
|
432
437
|
Array.from(component.children).forEach((el) => {
|
|
433
|
-
if (
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
438
|
+
if (el.tagName.toLowerCase() === "script") {
|
|
439
|
+
if (!isRemoteComponent) {
|
|
440
|
+
const newScript = document.createElement("script");
|
|
441
|
+
for (const attr of el.attributes) {
|
|
442
|
+
if (attr.name === "src") {
|
|
443
|
+
const absoluteSrc = new URL(
|
|
444
|
+
attr.value,
|
|
445
|
+
url ?? window.location.origin
|
|
446
|
+
).href;
|
|
447
|
+
newScript.setAttribute(
|
|
448
|
+
attr.name,
|
|
449
|
+
resolveClientUrl?.(absoluteSrc) ?? absoluteSrc
|
|
450
|
+
);
|
|
451
|
+
} else {
|
|
452
|
+
newScript.setAttribute(attr.name, attr.value);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
newScript.textContent = el.textContent;
|
|
456
|
+
if (remoteComponentSrc) {
|
|
441
457
|
newScript.setAttribute(
|
|
442
|
-
|
|
443
|
-
|
|
458
|
+
"data-remote-component-src",
|
|
459
|
+
remoteComponentSrc
|
|
444
460
|
);
|
|
445
|
-
} else {
|
|
446
|
-
newScript.setAttribute(attr.name, attr.value);
|
|
447
461
|
}
|
|
462
|
+
this.root?.appendChild(newScript);
|
|
463
|
+
} else {
|
|
464
|
+
const newEl = el.cloneNode(true);
|
|
465
|
+
for (const attr of el.attributes) {
|
|
466
|
+
if (attr.name.startsWith("on")) {
|
|
467
|
+
newEl.setAttribute(attr.name, attr.value);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
this.root?.appendChild(newEl);
|
|
448
471
|
}
|
|
449
|
-
newScript.textContent = el.textContent;
|
|
450
|
-
if (remoteComponentSrc) {
|
|
451
|
-
newScript.setAttribute(
|
|
452
|
-
"data-remote-component-src",
|
|
453
|
-
remoteComponentSrc
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
this.root?.appendChild(newScript);
|
|
457
472
|
} else {
|
|
458
473
|
const newEl = el.cloneNode(true);
|
|
459
474
|
for (const attr of el.attributes) {
|
|
@@ -461,9 +476,10 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
461
476
|
newEl.setAttribute(attr.name, attr.value);
|
|
462
477
|
}
|
|
463
478
|
}
|
|
464
|
-
|
|
479
|
+
container.appendChild(newEl);
|
|
465
480
|
}
|
|
466
481
|
});
|
|
482
|
+
this.root?.appendChild(container);
|
|
467
483
|
}
|
|
468
484
|
for (const el of removable) {
|
|
469
485
|
el.parentElement?.removeChild(el);
|
|
@@ -613,9 +629,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
613
629
|
return;
|
|
614
630
|
}
|
|
615
631
|
this.reactRoot = hydrateRoot(
|
|
616
|
-
//
|
|
617
|
-
// @ts-expect-error
|
|
618
|
-
this.root,
|
|
632
|
+
// hydrate into the dedicated wrapper (falls back to the ShadowRoot)
|
|
633
|
+
// @ts-expect-error this.root is a ShadowRoot, accepted at runtime
|
|
634
|
+
reactContainer ?? this.root,
|
|
619
635
|
/* @__PURE__ */ jsx(RemoteComponentFromReadableStream, { initial: true, name: this.name })
|
|
620
636
|
);
|
|
621
637
|
} else if (nextData) {
|
|
@@ -653,9 +669,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
653
669
|
return;
|
|
654
670
|
}
|
|
655
671
|
this.reactRoot = hydrateRoot(
|
|
656
|
-
//
|
|
657
|
-
// @ts-expect-error
|
|
658
|
-
this.root,
|
|
672
|
+
// hydrate into the dedicated wrapper (falls back to the ShadowRoot)
|
|
673
|
+
// @ts-expect-error this.root is a ShadowRoot, accepted at runtime
|
|
674
|
+
reactContainer ?? this.root,
|
|
659
675
|
/* @__PURE__ */ jsx(RemoteComponentFromNext, { initial: true })
|
|
660
676
|
);
|
|
661
677
|
}
|