remote-components 0.0.31 → 0.0.33
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/{component-loader-e5513139.d.ts → component-loader-28ad0083.d.ts} +1 -0
- package/dist/html/host.cjs +152 -56
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +152 -56
- package/dist/html/host.js.map +1 -1
- package/dist/internal/next/host/app-router-client.cjs +6 -2
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +2 -2
- package/dist/internal/next/host/app-router-client.js +6 -2
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/next/remote/render-client.cjs +13 -3
- package/dist/internal/next/remote/render-client.cjs.map +1 -1
- package/dist/internal/next/remote/render-client.js +13 -3
- package/dist/internal/next/remote/render-client.js.map +1 -1
- package/dist/internal/next/remote/render-server.cjs +22 -3
- package/dist/internal/next/remote/render-server.cjs.map +1 -1
- package/dist/internal/next/remote/render-server.js +23 -4
- package/dist/internal/next/remote/render-server.js.map +1 -1
- package/dist/internal/shared/client/remote-component.cjs +82 -45
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +9 -2
- package/dist/internal/shared/client/remote-component.js +81 -45
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/error.cjs +50 -0
- package/dist/internal/shared/error.cjs.map +1 -0
- package/dist/internal/shared/error.d.ts +10 -0
- package/dist/internal/shared/error.js +24 -0
- package/dist/internal/shared/error.js.map +1 -0
- package/dist/internal/shared/ssr/dom-flight.cjs +8 -1
- package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.d.ts +2 -1
- package/dist/internal/shared/ssr/dom-flight.js +8 -1
- package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +48 -5
- package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.d.ts +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.js +52 -5
- package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
- package/dist/internal/webpack/next-client-pages-loader.cjs +3 -2
- package/dist/internal/webpack/next-client-pages-loader.cjs.map +1 -1
- package/dist/internal/webpack/next-client-pages-loader.js +3 -2
- package/dist/internal/webpack/next-client-pages-loader.js.map +1 -1
- package/dist/next/config.cjs +26 -9
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +26 -9
- package/dist/next/config.js.map +1 -1
- package/dist/next/host/client/index.cjs +133 -57
- package/dist/next/host/client/index.cjs.map +1 -1
- package/dist/next/host/client/index.d.ts +1 -1
- package/dist/next/host/client/index.js +133 -57
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-client.cjs +1 -1
- package/dist/next/host/pages-router-client.cjs.map +1 -1
- package/dist/next/host/pages-router-client.js +1 -1
- package/dist/next/host/pages-router-client.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs +4 -3
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.js +4 -3
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/index.cjs +4 -2
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.js +4 -2
- package/dist/next/index.js.map +1 -1
- package/dist/next/remote/pages-router.cjs +1 -1
- package/dist/next/remote/pages-router.cjs.map +1 -1
- package/dist/next/remote/pages-router.js +1 -1
- package/dist/next/remote/pages-router.js.map +1 -1
- package/dist/react/index.cjs +42 -11
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +46 -11
- package/dist/react/index.js.map +1 -1
- package/dist/shared/host/app.cjs +36 -0
- package/dist/shared/host/app.cjs.map +1 -0
- package/dist/shared/host/app.d.ts +3 -0
- package/dist/shared/host/app.js +12 -0
- package/dist/shared/host/app.js.map +1 -0
- package/dist/shared/host/pages.cjs +36 -0
- package/dist/shared/host/pages.cjs.map +1 -0
- package/dist/shared/host/pages.d.ts +3 -0
- package/dist/shared/host/pages.js +12 -0
- package/dist/shared/host/pages.js.map +1 -0
- package/dist/shared/remote/app.cjs +32 -0
- package/dist/shared/remote/app.cjs.map +1 -0
- package/dist/shared/remote/app.d.ts +3 -0
- package/dist/shared/remote/app.js +8 -0
- package/dist/shared/remote/app.js.map +1 -0
- package/dist/shared/remote/pages.cjs +32 -0
- package/dist/shared/remote/pages.cjs.map +1 -0
- package/dist/shared/remote/pages.d.ts +3 -0
- package/dist/shared/remote/pages.js +8 -0
- package/dist/shared/remote/pages.js.map +1 -0
- package/dist/shared/remote/wrapper.cjs +48 -0
- package/dist/shared/remote/wrapper.cjs.map +1 -0
- package/dist/shared/remote/wrapper.d.ts +2 -0
- package/dist/shared/remote/wrapper.js +25 -0
- package/dist/shared/remote/wrapper.js.map +1 -0
- package/dist/{types-b8210fd3.d.ts → types-7c207455.d.ts} +1 -1
- package/dist/{types-280a3640.d.ts → types-e4a3fa37.d.ts} +1 -0
- package/package.json +37 -1
package/dist/html/host.js
CHANGED
|
@@ -40,6 +40,32 @@ var init_shared_modules = __esm({
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
// src/shared/error.ts
|
|
44
|
+
function multipleRemoteComponentsError(url) {
|
|
45
|
+
return new Error(
|
|
46
|
+
`Multiple Remote Components found at "${url}". When a page exposes multiple Remote Components you must specify the "name" prop to select which one to load.`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
function failedToFetchRemoteComponentError(url, error) {
|
|
50
|
+
return new RemoteComponentsError(
|
|
51
|
+
`Failed to fetch Remote Component from "${url}". Is the URL correct and accessible?`,
|
|
52
|
+
{ cause: error instanceof Error ? error : new Error(String(error)) }
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
var RemoteComponentsError;
|
|
56
|
+
var init_error = __esm({
|
|
57
|
+
"src/shared/error.ts"() {
|
|
58
|
+
"use strict";
|
|
59
|
+
RemoteComponentsError = class extends Error {
|
|
60
|
+
constructor(message, options) {
|
|
61
|
+
super(message, options);
|
|
62
|
+
this.code = "REMOTE_COMPONENTS_ERROR";
|
|
63
|
+
this.name = "RemoteComponentsError";
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
43
69
|
// src/shared/webpack/next-client-pages-loader.ts
|
|
44
70
|
function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
45
71
|
const self = globalThis;
|
|
@@ -78,8 +104,8 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
|
78
104
|
(key) => key.includes("/next/dist/client/page-loader.js")
|
|
79
105
|
) ?? ""] ?? -1;
|
|
80
106
|
if (!(componentLoaderChunk && appLoaderChunk)) {
|
|
81
|
-
throw new
|
|
82
|
-
`Next.js client pages loader not found in bundle "${bundle}"
|
|
107
|
+
throw new RemoteComponentsError(
|
|
108
|
+
`Next.js client pages loader not found in bundle "${bundle}".`
|
|
83
109
|
);
|
|
84
110
|
}
|
|
85
111
|
const __NEXT_P_ORIGINAL = self.__NEXT_P;
|
|
@@ -154,6 +180,7 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
|
154
180
|
var init_next_client_pages_loader = __esm({
|
|
155
181
|
"src/shared/webpack/next-client-pages-loader.ts"() {
|
|
156
182
|
"use strict";
|
|
183
|
+
init_error();
|
|
157
184
|
}
|
|
158
185
|
});
|
|
159
186
|
|
|
@@ -312,11 +339,11 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
312
339
|
scriptResolve(void 0);
|
|
313
340
|
script.remove();
|
|
314
341
|
};
|
|
315
|
-
script.onerror = (
|
|
342
|
+
script.onerror = () => {
|
|
316
343
|
URL.revokeObjectURL(scriptUrl);
|
|
317
344
|
scriptReject(
|
|
318
|
-
new
|
|
319
|
-
`Failed to load script
|
|
345
|
+
new RemoteComponentsError(
|
|
346
|
+
`Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
|
|
320
347
|
)
|
|
321
348
|
);
|
|
322
349
|
script.remove();
|
|
@@ -358,11 +385,11 @@ function createModuleRequire(runtime) {
|
|
|
358
385
|
if (bundle && moduleId) {
|
|
359
386
|
return handleTurbopackModule(bundle, moduleId, id);
|
|
360
387
|
}
|
|
361
|
-
throw new Error(`Module ${id} not found
|
|
388
|
+
throw new Error(`Module "${id}" not found.`);
|
|
362
389
|
} catch (requireError) {
|
|
363
390
|
if (typeof self.__original_webpack_require__ !== "function") {
|
|
364
|
-
throw new
|
|
365
|
-
`Module ${id} not found in remote component bundle ${bundle}
|
|
391
|
+
throw new RemoteComponentsError(
|
|
392
|
+
`Module "${id}" not found in remote component bundle "${bundle}".`,
|
|
366
393
|
{
|
|
367
394
|
cause: requireError instanceof Error ? requireError : void 0
|
|
368
395
|
}
|
|
@@ -371,8 +398,8 @@ function createModuleRequire(runtime) {
|
|
|
371
398
|
try {
|
|
372
399
|
return self.__original_webpack_require__(id);
|
|
373
400
|
} catch (originalError) {
|
|
374
|
-
throw new
|
|
375
|
-
`Module ${id} not found in remote component bundle ${bundle}
|
|
401
|
+
throw new RemoteComponentsError(
|
|
402
|
+
`Module "${id}" not found in remote component bundle "${bundle}".`,
|
|
376
403
|
{ cause: originalError instanceof Error ? originalError : void 0 }
|
|
377
404
|
);
|
|
378
405
|
}
|
|
@@ -502,7 +529,6 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
502
529
|
}
|
|
503
530
|
const exports = {};
|
|
504
531
|
const moduleExports = { exports };
|
|
505
|
-
const exportNames = /* @__PURE__ */ new Set();
|
|
506
532
|
if (!self.__remote_components_turbopack_modules__) {
|
|
507
533
|
self.__remote_components_turbopack_modules__ = {};
|
|
508
534
|
}
|
|
@@ -538,31 +564,53 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
538
564
|
};
|
|
539
565
|
}
|
|
540
566
|
},
|
|
541
|
-
//
|
|
542
|
-
s(
|
|
543
|
-
let mod =
|
|
544
|
-
if (
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
567
|
+
// esm
|
|
568
|
+
s(bindings, esmId) {
|
|
569
|
+
let mod = exports;
|
|
570
|
+
if (typeof esmId === "string" || typeof esmId === "number") {
|
|
571
|
+
if (!self.__remote_components_turbopack_modules__) {
|
|
572
|
+
self.__remote_components_turbopack_modules__ = {};
|
|
573
|
+
}
|
|
574
|
+
if (!self.__remote_components_turbopack_modules__[bundle]) {
|
|
575
|
+
self.__remote_components_turbopack_modules__[bundle] = {};
|
|
576
|
+
}
|
|
577
|
+
if (!self.__remote_components_turbopack_modules__[bundle][esmId]) {
|
|
578
|
+
self.__remote_components_turbopack_modules__[bundle][esmId] = {};
|
|
579
|
+
}
|
|
580
|
+
mod = self.__remote_components_turbopack_modules__[bundle][esmId];
|
|
581
|
+
}
|
|
582
|
+
Object.defineProperty(mod, "__esModule", { value: true });
|
|
583
|
+
if (Array.isArray(bindings)) {
|
|
584
|
+
let i = 0;
|
|
585
|
+
while (i < bindings.length) {
|
|
586
|
+
const propName = bindings[i++];
|
|
587
|
+
const tagOrFunc = bindings[i++];
|
|
588
|
+
if (typeof tagOrFunc === "number") {
|
|
589
|
+
Object.defineProperty(mod, propName, {
|
|
590
|
+
value: bindings[i++],
|
|
591
|
+
enumerable: true,
|
|
592
|
+
writable: false
|
|
593
|
+
});
|
|
594
|
+
} else {
|
|
595
|
+
const getterFn = tagOrFunc;
|
|
596
|
+
if (typeof bindings[i] === "function") {
|
|
597
|
+
const setterFn = bindings[i++];
|
|
598
|
+
Object.defineProperty(mod, propName, {
|
|
599
|
+
get: getterFn,
|
|
600
|
+
set: setterFn,
|
|
601
|
+
enumerable: true
|
|
602
|
+
});
|
|
603
|
+
} else {
|
|
604
|
+
Object.defineProperty(mod, propName, {
|
|
605
|
+
get: getterFn,
|
|
606
|
+
enumerable: true
|
|
607
|
+
});
|
|
556
608
|
}
|
|
557
609
|
}
|
|
558
610
|
}
|
|
559
611
|
}
|
|
560
|
-
for (const [key, value] of Object.entries(mod)) {
|
|
561
|
-
exports[key] = value;
|
|
562
|
-
exportNames.add(key);
|
|
563
|
-
}
|
|
564
612
|
},
|
|
565
|
-
// import
|
|
613
|
+
// import
|
|
566
614
|
i(importId) {
|
|
567
615
|
let mod;
|
|
568
616
|
if (typeof importId === "string") {
|
|
@@ -586,7 +634,10 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
586
634
|
} else {
|
|
587
635
|
mod = self.__webpack_require__?.(`[${bundle}] ${importId}`);
|
|
588
636
|
}
|
|
589
|
-
if (
|
|
637
|
+
if (typeof mod !== "object") {
|
|
638
|
+
mod = { default: mod };
|
|
639
|
+
} else if (!("default" in mod) && // eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
640
|
+
mod.toString() !== "[object Module]") {
|
|
590
641
|
try {
|
|
591
642
|
mod.default = mod;
|
|
592
643
|
} catch {
|
|
@@ -605,7 +656,7 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
605
656
|
return self.__webpack_require__?.(`[${bundle}] ${vid}`);
|
|
606
657
|
});
|
|
607
658
|
} else {
|
|
608
|
-
exports
|
|
659
|
+
moduleExports.exports = value;
|
|
609
660
|
}
|
|
610
661
|
},
|
|
611
662
|
// async module initializer
|
|
@@ -639,7 +690,9 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
639
690
|
return self.__webpack_chunk_load__?.(bundleUrl, bundle);
|
|
640
691
|
}
|
|
641
692
|
}
|
|
642
|
-
throw new Error(
|
|
693
|
+
throw new Error(
|
|
694
|
+
`Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
|
|
695
|
+
);
|
|
643
696
|
},
|
|
644
697
|
// global
|
|
645
698
|
g: self.__remote_components_turbopack_global__[bundle],
|
|
@@ -649,11 +702,6 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
649
702
|
moduleExports,
|
|
650
703
|
exports
|
|
651
704
|
);
|
|
652
|
-
for (const name of exportNames) {
|
|
653
|
-
if (typeof exports[name] === "function") {
|
|
654
|
-
exports[name] = exports[name]();
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
705
|
if (self.__remote_components_turbopack_modules__[bundle][moduleId] !== moduleExports.exports) {
|
|
658
706
|
self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
|
|
659
707
|
}
|
|
@@ -662,6 +710,7 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
662
710
|
var init_webpack_adapter = __esm({
|
|
663
711
|
"src/shared/client/webpack-adapter.ts"() {
|
|
664
712
|
"use strict";
|
|
713
|
+
init_error();
|
|
665
714
|
init_const();
|
|
666
715
|
}
|
|
667
716
|
});
|
|
@@ -885,10 +934,14 @@ async function webpackRuntime(bundle, shared, remoteShared) {
|
|
|
885
934
|
const remoteBundle = match?.groups?.bundle;
|
|
886
935
|
const id = match?.groups?.id;
|
|
887
936
|
if (!(id && remoteBundle)) {
|
|
888
|
-
throw new
|
|
937
|
+
throw new RemoteComponentsError(
|
|
938
|
+
`Remote Component module "${remoteId}" not found. Did you forget to wrap the Next.js config with \`withRemoteComponents\` on both host and remote?`
|
|
939
|
+
);
|
|
889
940
|
}
|
|
890
941
|
if (typeof self.__remote_webpack_require__?.[remoteBundle] !== "function") {
|
|
891
|
-
throw new
|
|
942
|
+
throw new RemoteComponentsError(
|
|
943
|
+
`Remote Components are not available in "${remoteBundle}". Did you forget to wrap the Next.js config with \`withRemoteComponents\` on both host and remote?`
|
|
944
|
+
);
|
|
892
945
|
}
|
|
893
946
|
return self.__remote_webpack_require__[remoteBundle](id);
|
|
894
947
|
};
|
|
@@ -910,8 +963,8 @@ async function webpackRuntime(bundle, shared, remoteShared) {
|
|
|
910
963
|
};
|
|
911
964
|
newScript.onerror = () => {
|
|
912
965
|
reject(
|
|
913
|
-
new
|
|
914
|
-
`Failed to load script ${script.src} for
|
|
966
|
+
new RemoteComponentsError(
|
|
967
|
+
`Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
|
|
915
968
|
)
|
|
916
969
|
);
|
|
917
970
|
newScript.remove();
|
|
@@ -971,6 +1024,7 @@ async function webpackRuntime(bundle, shared, remoteShared) {
|
|
|
971
1024
|
var init_webpack = __esm({
|
|
972
1025
|
"src/html/host/runtime/webpack.ts"() {
|
|
973
1026
|
"use strict";
|
|
1027
|
+
init_error();
|
|
974
1028
|
init_shared_modules();
|
|
975
1029
|
init_next_client_pages_loader();
|
|
976
1030
|
init_polyfill();
|
|
@@ -1038,6 +1092,7 @@ import { hydrateRoot } from "react-dom/client";
|
|
|
1038
1092
|
// src/shared/client/component-loader.ts
|
|
1039
1093
|
init_shared_modules();
|
|
1040
1094
|
init_next_client_pages_loader();
|
|
1095
|
+
init_error();
|
|
1041
1096
|
init_webpack_adapter();
|
|
1042
1097
|
import * as React from "react";
|
|
1043
1098
|
import * as ReactDOM from "react-dom";
|
|
@@ -1045,6 +1100,9 @@ import * as ReactDOMClient from "react-dom/client";
|
|
|
1045
1100
|
import * as JSXDevRuntime from "react/jsx-dev-runtime";
|
|
1046
1101
|
import * as JSXRuntime from "react/jsx-runtime";
|
|
1047
1102
|
|
|
1103
|
+
// src/shared/client/script-loader.ts
|
|
1104
|
+
init_error();
|
|
1105
|
+
|
|
1048
1106
|
// src/shared/client/rsc.ts
|
|
1049
1107
|
import { ReadableStream } from "web-streams-polyfill";
|
|
1050
1108
|
function fixPayload(payload) {
|
|
@@ -1114,6 +1172,7 @@ function createRSCStream(rscName, data) {
|
|
|
1114
1172
|
// src/shared/client/remote-component.ts
|
|
1115
1173
|
init_webpack_adapter();
|
|
1116
1174
|
init_const();
|
|
1175
|
+
init_error();
|
|
1117
1176
|
|
|
1118
1177
|
// src/html/host/index.tsx
|
|
1119
1178
|
init_utils();
|
|
@@ -1193,7 +1252,11 @@ function applyOriginToNodes(doc, url) {
|
|
|
1193
1252
|
}
|
|
1194
1253
|
}
|
|
1195
1254
|
|
|
1255
|
+
// src/html/host/index.tsx
|
|
1256
|
+
init_error();
|
|
1257
|
+
|
|
1196
1258
|
// src/html/host/runtime/index.ts
|
|
1259
|
+
init_error();
|
|
1197
1260
|
async function getRuntime(type, url, bundle, shared, remoteShared) {
|
|
1198
1261
|
if (typeof globalThis.process === "undefined") {
|
|
1199
1262
|
globalThis.process = {
|
|
@@ -1207,7 +1270,9 @@ async function getRuntime(type, url, bundle, shared, remoteShared) {
|
|
|
1207
1270
|
const { turbopackRuntime: turbopackRuntime2 } = await Promise.resolve().then(() => (init_turbopack(), turbopack_exports));
|
|
1208
1271
|
return turbopackRuntime2(url, bundle, shared, remoteShared);
|
|
1209
1272
|
}
|
|
1210
|
-
throw new
|
|
1273
|
+
throw new RemoteComponentsError(
|
|
1274
|
+
`Remote Components runtime "${type}" is not supported. Supported runtimes are "webpack" and "turbopack".`
|
|
1275
|
+
);
|
|
1211
1276
|
}
|
|
1212
1277
|
|
|
1213
1278
|
// src/html/host/index.tsx
|
|
@@ -1232,9 +1297,6 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1232
1297
|
if (this.getAttribute("src")) {
|
|
1233
1298
|
this.load().catch((e) => {
|
|
1234
1299
|
console.error(e);
|
|
1235
|
-
throw new Error(
|
|
1236
|
-
`Failed to load remote component: ${this.bundle ?? this.name ?? this.getAttribute("src")}`
|
|
1237
|
-
);
|
|
1238
1300
|
});
|
|
1239
1301
|
}
|
|
1240
1302
|
} else if (name === "mode" && oldValue !== newValue && this.root) {
|
|
@@ -1246,7 +1308,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1246
1308
|
});
|
|
1247
1309
|
this.root = newRoot;
|
|
1248
1310
|
this.load().catch((e) => {
|
|
1249
|
-
|
|
1311
|
+
console.error(e);
|
|
1250
1312
|
});
|
|
1251
1313
|
}
|
|
1252
1314
|
}
|
|
@@ -1280,14 +1342,14 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1280
1342
|
}
|
|
1281
1343
|
if (this.hasAttribute("src") || this.querySelector("div#__REMOTE_COMPONENT__") || this.hasAttribute("data-ssr")) {
|
|
1282
1344
|
this.load().catch((e) => {
|
|
1283
|
-
|
|
1345
|
+
console.error(e);
|
|
1284
1346
|
});
|
|
1285
1347
|
}
|
|
1286
1348
|
this.isLoading = true;
|
|
1287
1349
|
const src = this.getAttribute("src");
|
|
1288
1350
|
const remoteComponentChild = this.querySelector("div#__REMOTE_COMPONENT__") || this.querySelector("div[data-bundle][data-route]");
|
|
1289
1351
|
if (!src && !remoteComponentChild) {
|
|
1290
|
-
throw new
|
|
1352
|
+
throw new RemoteComponentsError('"src" attribute is required');
|
|
1291
1353
|
}
|
|
1292
1354
|
let url = null;
|
|
1293
1355
|
let html = this.innerHTML;
|
|
@@ -1305,14 +1367,41 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1305
1367
|
};
|
|
1306
1368
|
const res = await fetch(url, fetchInit);
|
|
1307
1369
|
if (!res.ok) {
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
);
|
|
1370
|
+
let error = failedToFetchRemoteComponentError(url.href, {
|
|
1371
|
+
cause: new Error(`${res.status} ${res.statusText}`)
|
|
1372
|
+
});
|
|
1373
|
+
try {
|
|
1374
|
+
const body = await res.text();
|
|
1375
|
+
const parser2 = new DOMParser();
|
|
1376
|
+
const doc2 = parser2.parseFromString(body, "text/html");
|
|
1377
|
+
const errorTemplate = doc2.querySelector(
|
|
1378
|
+
"template[data-next-error-message]"
|
|
1379
|
+
);
|
|
1380
|
+
const errorMessage = errorTemplate?.getAttribute(
|
|
1381
|
+
"data-next-error-message"
|
|
1382
|
+
);
|
|
1383
|
+
const errorStack = errorTemplate?.getAttribute(
|
|
1384
|
+
"data-next-error-stack"
|
|
1385
|
+
);
|
|
1386
|
+
if (errorMessage) {
|
|
1387
|
+
error = new RemoteComponentsError(errorMessage);
|
|
1388
|
+
if (errorStack) {
|
|
1389
|
+
error.stack = errorStack;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
} catch {
|
|
1393
|
+
}
|
|
1394
|
+
throw error;
|
|
1311
1395
|
}
|
|
1312
1396
|
html = await res.text();
|
|
1313
1397
|
}
|
|
1314
1398
|
const parser = new DOMParser();
|
|
1315
1399
|
const doc = parser.parseFromString(html, "text/html");
|
|
1400
|
+
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(`div[data-bundle][data-route][id^="${this.name}"]`)) {
|
|
1401
|
+
throw multipleRemoteComponentsError(
|
|
1402
|
+
url?.href ?? (this.getAttribute("src") || "unknown")
|
|
1403
|
+
);
|
|
1404
|
+
}
|
|
1316
1405
|
const component = doc.querySelector(`div[data-bundle][data-route][id^="${this.name}"]`) ?? // fallback to the first element with the data-bundle and data-route attributes when not using a named remote component
|
|
1317
1406
|
doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
|
|
1318
1407
|
doc.querySelector("div#__next");
|
|
@@ -1352,8 +1441,15 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1352
1441
|
);
|
|
1353
1442
|
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
1354
1443
|
remoteSharedEl?.parentElement?.removeChild(remoteSharedEl);
|
|
1444
|
+
if ("__remote_components_missing_shared__" in remoteShared) {
|
|
1445
|
+
throw new RemoteComponentsError(
|
|
1446
|
+
remoteShared.__remote_components_missing_shared__
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1355
1449
|
if (!component || !(rsc || nextData)) {
|
|
1356
|
-
throw new
|
|
1450
|
+
throw new RemoteComponentsError(
|
|
1451
|
+
`Remote Component not found on ${src}.${this.name !== "__vercel_remote_component" ? ` The name for the <RemoteComponent> is "${this.name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
|
|
1452
|
+
);
|
|
1357
1453
|
}
|
|
1358
1454
|
const removable = Array.from(this.childNodes);
|
|
1359
1455
|
const links = doc.querySelectorAll("link[href]");
|
|
@@ -1371,8 +1467,8 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1371
1467
|
};
|
|
1372
1468
|
newLink.onerror = () => {
|
|
1373
1469
|
reject(
|
|
1374
|
-
new
|
|
1375
|
-
`Failed to load link ${link.href} for
|
|
1470
|
+
new RemoteComponentsError(
|
|
1471
|
+
`Failed to load <link href="${link.href}"> for Remote Component. Check the URL is correct.`
|
|
1376
1472
|
)
|
|
1377
1473
|
);
|
|
1378
1474
|
};
|