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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
-
import { a as LoadRemoteComponentProps } from '../../../component-loader-
|
|
3
|
+
import { a as LoadRemoteComponentProps } from '../../../component-loader-28ad0083.js';
|
|
4
4
|
|
|
5
5
|
declare module 'react/jsx-runtime' {
|
|
6
6
|
namespace JSX {
|
|
@@ -48,6 +48,26 @@ function applySharedModules(bundle, resolve) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
// src/shared/error.ts
|
|
52
|
+
var RemoteComponentsError = class extends Error {
|
|
53
|
+
constructor(message, options) {
|
|
54
|
+
super(message, options);
|
|
55
|
+
this.code = "REMOTE_COMPONENTS_ERROR";
|
|
56
|
+
this.name = "RemoteComponentsError";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
function multipleRemoteComponentsError(url) {
|
|
60
|
+
return new Error(
|
|
61
|
+
`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.`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
function failedToFetchRemoteComponentError(url, error) {
|
|
65
|
+
return new RemoteComponentsError(
|
|
66
|
+
`Failed to fetch Remote Component from "${url}". Is the URL correct and accessible?`,
|
|
67
|
+
{ cause: error instanceof Error ? error : new Error(String(error)) }
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
51
71
|
// src/shared/webpack/next-client-pages-loader.ts
|
|
52
72
|
function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
53
73
|
const self = globalThis;
|
|
@@ -86,8 +106,8 @@ function nextClientPagesLoader(bundle, route, styleContainer = document.head) {
|
|
|
86
106
|
(key) => key.includes("/next/dist/client/page-loader.js")
|
|
87
107
|
) ?? ""] ?? -1;
|
|
88
108
|
if (!(componentLoaderChunk && appLoaderChunk)) {
|
|
89
|
-
throw new
|
|
90
|
-
`Next.js client pages loader not found in bundle "${bundle}"
|
|
109
|
+
throw new RemoteComponentsError(
|
|
110
|
+
`Next.js client pages loader not found in bundle "${bundle}".`
|
|
91
111
|
);
|
|
92
112
|
}
|
|
93
113
|
const __NEXT_P_ORIGINAL = self.__NEXT_P;
|
|
@@ -311,11 +331,11 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
311
331
|
scriptResolve(void 0);
|
|
312
332
|
script.remove();
|
|
313
333
|
};
|
|
314
|
-
script.onerror = (
|
|
334
|
+
script.onerror = () => {
|
|
315
335
|
URL.revokeObjectURL(scriptUrl);
|
|
316
336
|
scriptReject(
|
|
317
|
-
new
|
|
318
|
-
`Failed to load script
|
|
337
|
+
new RemoteComponentsError(
|
|
338
|
+
`Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
|
|
319
339
|
)
|
|
320
340
|
);
|
|
321
341
|
script.remove();
|
|
@@ -357,11 +377,11 @@ function createModuleRequire(runtime) {
|
|
|
357
377
|
if (bundle && moduleId) {
|
|
358
378
|
return handleTurbopackModule(bundle, moduleId, id);
|
|
359
379
|
}
|
|
360
|
-
throw new Error(`Module ${id} not found
|
|
380
|
+
throw new Error(`Module "${id}" not found.`);
|
|
361
381
|
} catch (requireError) {
|
|
362
382
|
if (typeof self.__original_webpack_require__ !== "function") {
|
|
363
|
-
throw new
|
|
364
|
-
`Module ${id} not found in remote component bundle ${bundle}
|
|
383
|
+
throw new RemoteComponentsError(
|
|
384
|
+
`Module "${id}" not found in remote component bundle "${bundle}".`,
|
|
365
385
|
{
|
|
366
386
|
cause: requireError instanceof Error ? requireError : void 0
|
|
367
387
|
}
|
|
@@ -370,8 +390,8 @@ function createModuleRequire(runtime) {
|
|
|
370
390
|
try {
|
|
371
391
|
return self.__original_webpack_require__(id);
|
|
372
392
|
} catch (originalError) {
|
|
373
|
-
throw new
|
|
374
|
-
`Module ${id} not found in remote component bundle ${bundle}
|
|
393
|
+
throw new RemoteComponentsError(
|
|
394
|
+
`Module "${id}" not found in remote component bundle "${bundle}".`,
|
|
375
395
|
{ cause: originalError instanceof Error ? originalError : void 0 }
|
|
376
396
|
);
|
|
377
397
|
}
|
|
@@ -662,7 +682,9 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
662
682
|
return self.__webpack_chunk_load__?.(bundleUrl, bundle);
|
|
663
683
|
}
|
|
664
684
|
}
|
|
665
|
-
throw new Error(
|
|
685
|
+
throw new Error(
|
|
686
|
+
`Failed to load Turbopack chunk "${url}" for module "${id}". Check the URL is correct.`
|
|
687
|
+
);
|
|
666
688
|
},
|
|
667
689
|
// global
|
|
668
690
|
g: self.__remote_components_turbopack_global__[bundle],
|
|
@@ -694,8 +716,8 @@ async function loadScripts(scripts) {
|
|
|
694
716
|
};
|
|
695
717
|
newScript.onerror = () => {
|
|
696
718
|
reject(
|
|
697
|
-
new
|
|
698
|
-
`Failed to load script ${script.src} for
|
|
719
|
+
new RemoteComponentsError(
|
|
720
|
+
`Failed to load <script src="${script.src}"> for Remote Component. Check the URL is correct.`
|
|
699
721
|
)
|
|
700
722
|
);
|
|
701
723
|
};
|
|
@@ -843,7 +865,10 @@ async function loadRemoteComponent({
|
|
|
843
865
|
} catch (error) {
|
|
844
866
|
return {
|
|
845
867
|
component: null,
|
|
846
|
-
error:
|
|
868
|
+
error: new RemoteComponentsError(
|
|
869
|
+
`Failed to load remote component "${name}".`,
|
|
870
|
+
{ cause: error instanceof Error ? error : new Error(String(error)) }
|
|
871
|
+
)
|
|
847
872
|
};
|
|
848
873
|
}
|
|
849
874
|
}
|
|
@@ -859,7 +884,9 @@ async function loadRSCComponent(rscName, data) {
|
|
|
859
884
|
createFromReadableStream = _createFromReadableStream;
|
|
860
885
|
}
|
|
861
886
|
if (typeof createFromReadableStream !== "function") {
|
|
862
|
-
throw new
|
|
887
|
+
throw new RemoteComponentsError(
|
|
888
|
+
'Failed to import "react-server-dom-webpack". Is Next.js installed correctly?'
|
|
889
|
+
);
|
|
863
890
|
}
|
|
864
891
|
const stream = createRSCStream(rscName, data);
|
|
865
892
|
const component = createFromReadableStream(stream);
|
|
@@ -868,8 +895,8 @@ async function loadRSCComponent(rscName, data) {
|
|
|
868
895
|
function loadNextPagesComponent(bundle, route, nextData, name, container) {
|
|
869
896
|
const { Component, App } = nextClientPagesLoader(bundle, route, container);
|
|
870
897
|
if (!Component) {
|
|
871
|
-
throw new
|
|
872
|
-
`Remote
|
|
898
|
+
throw new RemoteComponentsError(
|
|
899
|
+
`Remote Component "${name}" is trying to load the component for route "${route}" but it is not available.`
|
|
873
900
|
);
|
|
874
901
|
}
|
|
875
902
|
const component = App ? React.createElement(App, { Component, ...nextData.props }) : React.createElement(Component, nextData.props);
|
|
@@ -1333,7 +1360,6 @@ function RemoteComponent({
|
|
|
1333
1360
|
}
|
|
1334
1361
|
}, [src]);
|
|
1335
1362
|
useEffect(() => {
|
|
1336
|
-
let mounted = true;
|
|
1337
1363
|
if (src && src !== prevSrcRef.current) {
|
|
1338
1364
|
prevSrcRef.current = src;
|
|
1339
1365
|
startTransition(async () => {
|
|
@@ -1349,9 +1375,31 @@ function RemoteComponent({
|
|
|
1349
1375
|
};
|
|
1350
1376
|
const res = await fetch(url, fetchInit);
|
|
1351
1377
|
if (!res.ok) {
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
);
|
|
1378
|
+
let error = failedToFetchRemoteComponentError(url.href, {
|
|
1379
|
+
cause: new Error(`${res.status} ${res.statusText}`)
|
|
1380
|
+
});
|
|
1381
|
+
try {
|
|
1382
|
+
const body = await res.text();
|
|
1383
|
+
const parser2 = new DOMParser();
|
|
1384
|
+
const doc2 = parser2.parseFromString(body, "text/html");
|
|
1385
|
+
const errorTemplate = doc2.querySelector(
|
|
1386
|
+
"template[data-next-error-message]"
|
|
1387
|
+
);
|
|
1388
|
+
const errorMessage = errorTemplate?.getAttribute(
|
|
1389
|
+
"data-next-error-message"
|
|
1390
|
+
);
|
|
1391
|
+
const errorStack = errorTemplate?.getAttribute(
|
|
1392
|
+
"data-next-error-stack"
|
|
1393
|
+
);
|
|
1394
|
+
if (errorMessage) {
|
|
1395
|
+
error = new RemoteComponentsError(errorMessage);
|
|
1396
|
+
if (errorStack) {
|
|
1397
|
+
error.stack = errorStack;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
} catch {
|
|
1401
|
+
}
|
|
1402
|
+
throw error;
|
|
1355
1403
|
}
|
|
1356
1404
|
const remoteHtml = await res.text();
|
|
1357
1405
|
htmlRef.current = remoteHtml;
|
|
@@ -1359,6 +1407,9 @@ function RemoteComponent({
|
|
|
1359
1407
|
}
|
|
1360
1408
|
const parser = new DOMParser();
|
|
1361
1409
|
const doc = parser.parseFromString(html, "text/html");
|
|
1410
|
+
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`)) {
|
|
1411
|
+
throw multipleRemoteComponentsError(url.href);
|
|
1412
|
+
}
|
|
1362
1413
|
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
|
|
1363
1414
|
doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
|
|
1364
1415
|
doc.querySelector("div#__next");
|
|
@@ -1380,7 +1431,9 @@ function RemoteComponent({
|
|
|
1380
1431
|
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
1381
1432
|
remoteSharedEl?.remove();
|
|
1382
1433
|
if (!component || !(rsc || nextData)) {
|
|
1383
|
-
throw new
|
|
1434
|
+
throw new RemoteComponentsError(
|
|
1435
|
+
`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>?`
|
|
1436
|
+
);
|
|
1384
1437
|
}
|
|
1385
1438
|
applyOriginToNodes(doc, url);
|
|
1386
1439
|
const links = Array.from(
|
|
@@ -1472,6 +1525,15 @@ function RemoteComponent({
|
|
|
1472
1525
|
};
|
|
1473
1526
|
componentHydrationHtml.current = Array.from(doc.querySelectorAll("link,style")).map((link) => link.outerHTML).join("") + component.innerHTML;
|
|
1474
1527
|
const userShared = await shared;
|
|
1528
|
+
if ("__remote_components_missing_shared__" in userShared) {
|
|
1529
|
+
userShared.__remote_components_missing_shared__().catch((e) => {
|
|
1530
|
+
throw e;
|
|
1531
|
+
});
|
|
1532
|
+
} else if ("__remote_components_missing_shared__" in remoteShared) {
|
|
1533
|
+
throw new RemoteComponentsError(
|
|
1534
|
+
remoteShared.__remote_components_missing_shared__
|
|
1535
|
+
);
|
|
1536
|
+
}
|
|
1475
1537
|
const result = await loadRemoteComponent({
|
|
1476
1538
|
url: new URL(url, location.origin),
|
|
1477
1539
|
name: remoteName,
|
|
@@ -1516,15 +1578,10 @@ function RemoteComponent({
|
|
|
1516
1578
|
setRemoteComponent(result.component);
|
|
1517
1579
|
}
|
|
1518
1580
|
} catch (error) {
|
|
1519
|
-
|
|
1520
|
-
setRemoteComponent(error);
|
|
1521
|
-
}
|
|
1581
|
+
setRemoteComponent(error);
|
|
1522
1582
|
}
|
|
1523
1583
|
});
|
|
1524
1584
|
}
|
|
1525
|
-
return () => {
|
|
1526
|
-
mounted = false;
|
|
1527
|
-
};
|
|
1528
1585
|
}, [
|
|
1529
1586
|
url,
|
|
1530
1587
|
src,
|
|
@@ -1703,7 +1760,7 @@ var routerImpl = async () => {
|
|
|
1703
1760
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1704
1761
|
async function tryImportShared() {
|
|
1705
1762
|
try {
|
|
1706
|
-
const { shared } = await import("
|
|
1763
|
+
const { shared } = await import("remote-components/shared/host/app");
|
|
1707
1764
|
return shared;
|
|
1708
1765
|
} catch {
|
|
1709
1766
|
return {};
|