remote-components 0.0.32 → 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 +105 -28
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +105 -28
- 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 +35 -17
- 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 +34 -17
- 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 +86 -29
- 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 +86 -29
- 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
|
@@ -74,6 +74,26 @@ function applySharedModules(bundle, resolve) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
// src/shared/error.ts
|
|
78
|
+
var RemoteComponentsError = class extends Error {
|
|
79
|
+
constructor(message, options) {
|
|
80
|
+
super(message, options);
|
|
81
|
+
this.code = "REMOTE_COMPONENTS_ERROR";
|
|
82
|
+
this.name = "RemoteComponentsError";
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function multipleRemoteComponentsError(url) {
|
|
86
|
+
return new Error(
|
|
87
|
+
`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.`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
function failedToFetchRemoteComponentError(url, error) {
|
|
91
|
+
return new RemoteComponentsError(
|
|
92
|
+
`Failed to fetch Remote Component from "${url}". Is the URL correct and accessible?`,
|
|
93
|
+
{ cause: error instanceof Error ? error : new Error(String(error)) }
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
77
97
|
// src/shared/webpack/next-client-pages-loader.ts
|
|
78
98
|
function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
79
99
|
const self = globalThis;
|
|
@@ -112,8 +132,8 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
|
112
132
|
(key) => key.includes("/next/dist/client/page-loader.js")
|
|
113
133
|
) ?? ""] ?? -1;
|
|
114
134
|
if (!(componentLoaderChunk && appLoaderChunk)) {
|
|
115
|
-
throw new
|
|
116
|
-
`Next.js client pages loader not found in bundle "${bundle}"
|
|
135
|
+
throw new RemoteComponentsError(
|
|
136
|
+
`Next.js client pages loader not found in bundle "${bundle}".`
|
|
117
137
|
);
|
|
118
138
|
}
|
|
119
139
|
const __NEXT_P_ORIGINAL = self.__NEXT_P;
|
|
@@ -337,11 +357,11 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
337
357
|
scriptResolve(void 0);
|
|
338
358
|
script.remove();
|
|
339
359
|
};
|
|
340
|
-
script.onerror = (
|
|
360
|
+
script.onerror = () => {
|
|
341
361
|
URL.revokeObjectURL(scriptUrl);
|
|
342
362
|
scriptReject(
|
|
343
|
-
new
|
|
344
|
-
`Failed to load script
|
|
363
|
+
new RemoteComponentsError(
|
|
364
|
+
`Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
|
|
345
365
|
)
|
|
346
366
|
);
|
|
347
367
|
script.remove();
|
|
@@ -383,11 +403,11 @@ function createModuleRequire(runtime) {
|
|
|
383
403
|
if (bundle && moduleId) {
|
|
384
404
|
return handleTurbopackModule(bundle, moduleId, id);
|
|
385
405
|
}
|
|
386
|
-
throw new Error(`Module ${id} not found
|
|
406
|
+
throw new Error(`Module "${id}" not found.`);
|
|
387
407
|
} catch (requireError) {
|
|
388
408
|
if (typeof self.__original_webpack_require__ !== "function") {
|
|
389
|
-
throw new
|
|
390
|
-
`Module ${id} not found in remote component bundle ${bundle}
|
|
409
|
+
throw new RemoteComponentsError(
|
|
410
|
+
`Module "${id}" not found in remote component bundle "${bundle}".`,
|
|
391
411
|
{
|
|
392
412
|
cause: requireError instanceof Error ? requireError : void 0
|
|
393
413
|
}
|
|
@@ -396,8 +416,8 @@ function createModuleRequire(runtime) {
|
|
|
396
416
|
try {
|
|
397
417
|
return self.__original_webpack_require__(id);
|
|
398
418
|
} catch (originalError) {
|
|
399
|
-
throw new
|
|
400
|
-
`Module ${id} not found in remote component bundle ${bundle}
|
|
419
|
+
throw new RemoteComponentsError(
|
|
420
|
+
`Module "${id}" not found in remote component bundle "${bundle}".`,
|
|
401
421
|
{ cause: originalError instanceof Error ? originalError : void 0 }
|
|
402
422
|
);
|
|
403
423
|
}
|
|
@@ -688,7 +708,9 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
688
708
|
return self.__webpack_chunk_load__?.(bundleUrl, bundle);
|
|
689
709
|
}
|
|
690
710
|
}
|
|
691
|
-
throw new Error(
|
|
711
|
+
throw new Error(
|
|
712
|
+
`Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
|
|
713
|
+
);
|
|
692
714
|
},
|
|
693
715
|
// global
|
|
694
716
|
g: self.__remote_components_turbopack_global__[bundle],
|
|
@@ -720,8 +742,8 @@ async function loadScripts(scripts) {
|
|
|
720
742
|
};
|
|
721
743
|
newScript.onerror = () => {
|
|
722
744
|
reject(
|
|
723
|
-
new
|
|
724
|
-
`Failed to load script ${script.src} for
|
|
745
|
+
new RemoteComponentsError(
|
|
746
|
+
`Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
|
|
725
747
|
)
|
|
726
748
|
);
|
|
727
749
|
};
|
|
@@ -869,7 +891,10 @@ async function loadRemoteComponent({
|
|
|
869
891
|
} catch (error) {
|
|
870
892
|
return {
|
|
871
893
|
component: null,
|
|
872
|
-
error:
|
|
894
|
+
error: new RemoteComponentsError(
|
|
895
|
+
`Failed to load remote component "${name}".`,
|
|
896
|
+
{ cause: error instanceof Error ? error : new Error(String(error)) }
|
|
897
|
+
)
|
|
873
898
|
};
|
|
874
899
|
}
|
|
875
900
|
}
|
|
@@ -885,7 +910,9 @@ async function loadRSCComponent(rscName, data) {
|
|
|
885
910
|
createFromReadableStream = _createFromReadableStream;
|
|
886
911
|
}
|
|
887
912
|
if (typeof createFromReadableStream !== "function") {
|
|
888
|
-
throw new
|
|
913
|
+
throw new RemoteComponentsError(
|
|
914
|
+
'Failed to import "react-server-dom-webpack". Is Next.js installed correctly?'
|
|
915
|
+
);
|
|
889
916
|
}
|
|
890
917
|
const stream = createRSCStream(rscName, data);
|
|
891
918
|
const component = createFromReadableStream(stream);
|
|
@@ -894,8 +921,8 @@ async function loadRSCComponent(rscName, data) {
|
|
|
894
921
|
function loadNextPagesComponent(bundle, route, nextData, name, container) {
|
|
895
922
|
const { Component, App } = nextClientPagesLoader(bundle, route, container);
|
|
896
923
|
if (!Component) {
|
|
897
|
-
throw new
|
|
898
|
-
`Remote
|
|
924
|
+
throw new RemoteComponentsError(
|
|
925
|
+
`Remote Component "${name}" is trying to load the component for route "${route}" but it is not available.`
|
|
899
926
|
);
|
|
900
927
|
}
|
|
901
928
|
const component = App ? React.createElement(App, { Component, ...nextData.props }) : React.createElement(Component, nextData.props);
|
|
@@ -1359,7 +1386,6 @@ function RemoteComponent({
|
|
|
1359
1386
|
}
|
|
1360
1387
|
}, [src]);
|
|
1361
1388
|
(0, import_react.useEffect)(() => {
|
|
1362
|
-
let mounted = true;
|
|
1363
1389
|
if (src && src !== prevSrcRef.current) {
|
|
1364
1390
|
prevSrcRef.current = src;
|
|
1365
1391
|
(0, import_react.startTransition)(async () => {
|
|
@@ -1375,9 +1401,31 @@ function RemoteComponent({
|
|
|
1375
1401
|
};
|
|
1376
1402
|
const res = await fetch(url, fetchInit);
|
|
1377
1403
|
if (!res.ok) {
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
);
|
|
1404
|
+
let error = failedToFetchRemoteComponentError(url.href, {
|
|
1405
|
+
cause: new Error(`${res.status} ${res.statusText}`)
|
|
1406
|
+
});
|
|
1407
|
+
try {
|
|
1408
|
+
const body = await res.text();
|
|
1409
|
+
const parser2 = new DOMParser();
|
|
1410
|
+
const doc2 = parser2.parseFromString(body, "text/html");
|
|
1411
|
+
const errorTemplate = doc2.querySelector(
|
|
1412
|
+
"template[data-next-error-message]"
|
|
1413
|
+
);
|
|
1414
|
+
const errorMessage = errorTemplate?.getAttribute(
|
|
1415
|
+
"data-next-error-message"
|
|
1416
|
+
);
|
|
1417
|
+
const errorStack = errorTemplate?.getAttribute(
|
|
1418
|
+
"data-next-error-stack"
|
|
1419
|
+
);
|
|
1420
|
+
if (errorMessage) {
|
|
1421
|
+
error = new RemoteComponentsError(errorMessage);
|
|
1422
|
+
if (errorStack) {
|
|
1423
|
+
error.stack = errorStack;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
} catch {
|
|
1427
|
+
}
|
|
1428
|
+
throw error;
|
|
1381
1429
|
}
|
|
1382
1430
|
const remoteHtml = await res.text();
|
|
1383
1431
|
htmlRef.current = remoteHtml;
|
|
@@ -1385,6 +1433,9 @@ function RemoteComponent({
|
|
|
1385
1433
|
}
|
|
1386
1434
|
const parser = new DOMParser();
|
|
1387
1435
|
const doc = parser.parseFromString(html, "text/html");
|
|
1436
|
+
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`)) {
|
|
1437
|
+
throw multipleRemoteComponentsError(url.href);
|
|
1438
|
+
}
|
|
1388
1439
|
const component = doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) ?? // fallback to the first element with the data-bundle and data-route attributes when not using a named remote component
|
|
1389
1440
|
doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
|
|
1390
1441
|
doc.querySelector("div#__next");
|
|
@@ -1406,7 +1457,9 @@ function RemoteComponent({
|
|
|
1406
1457
|
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
1407
1458
|
remoteSharedEl?.remove();
|
|
1408
1459
|
if (!component || !(rsc || nextData)) {
|
|
1409
|
-
throw new
|
|
1460
|
+
throw new RemoteComponentsError(
|
|
1461
|
+
`Remote Component not found on ${url.href}.${remoteName !== "__vercel_remote_component" ? `The name for the <RemoteComponent> is "${remoteName}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
|
|
1462
|
+
);
|
|
1410
1463
|
}
|
|
1411
1464
|
applyOriginToNodes(doc, url);
|
|
1412
1465
|
const links = Array.from(
|
|
@@ -1498,6 +1551,15 @@ function RemoteComponent({
|
|
|
1498
1551
|
};
|
|
1499
1552
|
componentHydrationHtml.current = Array.from(doc.querySelectorAll("link,style")).map((link) => link.outerHTML).join("") + component.innerHTML;
|
|
1500
1553
|
const userShared = await shared;
|
|
1554
|
+
if ("__remote_components_missing_shared__" in userShared) {
|
|
1555
|
+
userShared.__remote_components_missing_shared__().catch((e) => {
|
|
1556
|
+
throw e;
|
|
1557
|
+
});
|
|
1558
|
+
} else if ("__remote_components_missing_shared__" in remoteShared) {
|
|
1559
|
+
throw new RemoteComponentsError(
|
|
1560
|
+
remoteShared.__remote_components_missing_shared__
|
|
1561
|
+
);
|
|
1562
|
+
}
|
|
1501
1563
|
const result = await loadRemoteComponent({
|
|
1502
1564
|
url: new URL(url, location.origin),
|
|
1503
1565
|
name: remoteName,
|
|
@@ -1542,15 +1604,10 @@ function RemoteComponent({
|
|
|
1542
1604
|
setRemoteComponent(result.component);
|
|
1543
1605
|
}
|
|
1544
1606
|
} catch (error) {
|
|
1545
|
-
|
|
1546
|
-
setRemoteComponent(error);
|
|
1547
|
-
}
|
|
1607
|
+
setRemoteComponent(error);
|
|
1548
1608
|
}
|
|
1549
1609
|
});
|
|
1550
1610
|
}
|
|
1551
|
-
return () => {
|
|
1552
|
-
mounted = false;
|
|
1553
|
-
};
|
|
1554
1611
|
}, [
|
|
1555
1612
|
url,
|
|
1556
1613
|
src,
|
|
@@ -1729,7 +1786,7 @@ var routerImpl = async () => {
|
|
|
1729
1786
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1730
1787
|
async function tryImportShared() {
|
|
1731
1788
|
try {
|
|
1732
|
-
const { shared } = await import("
|
|
1789
|
+
const { shared } = await import("remote-components/shared/host/app");
|
|
1733
1790
|
return shared;
|
|
1734
1791
|
} catch {
|
|
1735
1792
|
return {};
|