remote-components 0.0.46 → 0.0.48
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-26b1f55e.d.ts → component-loader-1838f572.d.ts} +62 -8
- package/dist/html/host.cjs +214 -76
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +214 -76
- package/dist/html/host.js.map +1 -1
- package/dist/html/remote.cjs.map +1 -1
- package/dist/html/remote.js.map +1 -1
- package/dist/internal/next/host/app-router-client.cjs +6 -6
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +1 -1
- package/dist/internal/next/host/app-router-client.js +1 -1
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/next/host/app-router-compat.cjs +5 -5
- package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
- package/dist/internal/next/host/app-router-compat.js +1 -1
- package/dist/internal/next/host/app-router-compat.js.map +1 -1
- package/dist/internal/shared/client/polyfill.cjs +2 -2
- package/dist/internal/shared/client/polyfill.cjs.map +1 -1
- package/dist/internal/shared/client/polyfill.js +1 -1
- package/dist/internal/shared/client/polyfill.js.map +1 -1
- package/dist/internal/shared/client/remote-component.cjs +48 -1
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +2 -2
- package/dist/internal/shared/client/remote-component.js +48 -1
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +1 -6
- 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 +1 -6
- package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.cjs +22 -5
- package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +30 -14
- package/dist/internal/shared/ssr/fetch-with-hooks.js +22 -5
- package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs +62 -0
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs.map +1 -0
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.d.ts +14 -0
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js +37 -0
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js.map +1 -0
- package/dist/internal/shared/utils/abort.cjs +38 -0
- package/dist/internal/shared/utils/abort.cjs.map +1 -0
- package/dist/internal/shared/utils/abort.d.ts +7 -0
- package/dist/internal/shared/utils/abort.js +14 -0
- package/dist/internal/shared/utils/abort.js.map +1 -0
- package/dist/internal/shared/{logger.cjs → utils/logger.cjs} +5 -0
- package/dist/internal/shared/utils/logger.cjs.map +1 -0
- package/dist/internal/shared/{logger.d.ts → utils/logger.d.ts} +3 -2
- package/dist/internal/shared/{logger.js → utils/logger.js} +4 -0
- package/dist/internal/shared/utils/logger.js.map +1 -0
- package/dist/internal/shared/utils.cjs +2 -9
- package/dist/internal/shared/utils.cjs.map +1 -1
- package/dist/internal/shared/utils.d.ts +0 -2
- package/dist/internal/shared/utils.js +1 -5
- package/dist/internal/shared/utils.js.map +1 -1
- package/dist/next/config.cjs +4 -2
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +4 -2
- package/dist/next/config.js.map +1 -1
- package/dist/next/host/app-router-server.d.ts +1 -1
- package/dist/next/host/client/index.cjs +91 -24
- 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 +91 -24
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-client.d.ts +1 -1
- package/dist/next/host/pages-router-server.d.ts +1 -1
- package/dist/next/index.d.ts +1 -1
- package/dist/next/proxy.cjs +128 -19
- package/dist/next/proxy.cjs.map +1 -1
- package/dist/next/proxy.d.ts +34 -6
- package/dist/next/proxy.js +125 -18
- package/dist/next/proxy.js.map +1 -1
- package/dist/react/index.cjs +91 -24
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +91 -24
- package/dist/react/index.js.map +1 -1
- package/dist/shared/host/proxy.cjs +79 -0
- package/dist/shared/host/proxy.cjs.map +1 -0
- package/dist/shared/host/proxy.d.ts +29 -0
- package/dist/shared/host/proxy.js +54 -0
- package/dist/shared/host/proxy.js.map +1 -0
- package/dist/shared/remote/proxy.cjs +71 -0
- package/dist/shared/remote/proxy.cjs.map +1 -0
- package/dist/shared/remote/proxy.d.ts +38 -0
- package/dist/shared/remote/proxy.js +45 -0
- package/dist/shared/remote/proxy.js.map +1 -0
- package/dist/{types-6e4ba234.d.ts → types-cbe44b51.d.ts} +61 -7
- package/dist/webpack.cjs +274 -0
- package/dist/webpack.cjs.map +1 -0
- package/dist/webpack.d.ts +14 -0
- package/dist/webpack.js +247 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +18 -1
- package/dist/internal/shared/logger.cjs.map +0 -1
- package/dist/internal/shared/logger.js.map +0 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { L as LoadRemoteComponentProps, O as OnRequestHook, a as OnResponseHook } from '../component-loader-
|
|
2
|
+
import { L as LoadRemoteComponentProps, O as OnRequestHook, a as OnResponseHook } from '../component-loader-1838f572.js';
|
|
3
|
+
export { H as HookOptions } from '../component-loader-1838f572.js';
|
|
3
4
|
import 'react';
|
|
4
5
|
|
|
5
6
|
declare module 'react/jsx-runtime' {
|
package/dist/react/index.js
CHANGED
|
@@ -95,6 +95,9 @@ function logDebug(location2, message) {
|
|
|
95
95
|
console.debug(`[${PREFIX}:${location2}]: ${message}`);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
+
function logInfo(location2, message) {
|
|
99
|
+
console.info(`[${PREFIX}:${location2}]: ${message}`);
|
|
100
|
+
}
|
|
98
101
|
function logWarn(location2, message) {
|
|
99
102
|
console.warn(`[${PREFIX}:${location2}]: ${message}`);
|
|
100
103
|
}
|
|
@@ -106,18 +109,6 @@ function logError(location2, message, cause) {
|
|
|
106
109
|
);
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
// src/shared/utils/index.ts
|
|
110
|
-
function escapeString(str) {
|
|
111
|
-
return str.replace(/[^a-z0-9]/g, "_");
|
|
112
|
-
}
|
|
113
|
-
var attrToProp = {
|
|
114
|
-
fetchpriority: "fetchPriority",
|
|
115
|
-
crossorigin: "crossOrigin",
|
|
116
|
-
imagesrcset: "imageSrcSet",
|
|
117
|
-
imagesizes: "imageSizes",
|
|
118
|
-
srcset: "srcSet"
|
|
119
|
-
};
|
|
120
|
-
|
|
121
112
|
// src/shared/client/polyfill.tsx
|
|
122
113
|
import { jsx } from "react/jsx-runtime";
|
|
123
114
|
function applyBundleUrlToSrc(bundle, src) {
|
|
@@ -589,6 +580,62 @@ async function loadScripts(scripts) {
|
|
|
589
580
|
);
|
|
590
581
|
}
|
|
591
582
|
|
|
583
|
+
// src/shared/utils/abort.ts
|
|
584
|
+
function isAbortError(error) {
|
|
585
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
586
|
+
return true;
|
|
587
|
+
}
|
|
588
|
+
if (error !== null && typeof error === "object" && "name" in error && error.name === "AbortError" && "message" in error && typeof error.message === "string") {
|
|
589
|
+
const e = error;
|
|
590
|
+
return typeof e.code === "number" || e.constructor?.name === "DOMException";
|
|
591
|
+
}
|
|
592
|
+
return false;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// src/shared/ssr/fetch-with-protected-rc-fallback.ts
|
|
596
|
+
var RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
597
|
+
async function fetchWithProtectedRcFallback(url, init) {
|
|
598
|
+
try {
|
|
599
|
+
const res = await fetch(url, init);
|
|
600
|
+
return res;
|
|
601
|
+
} catch (error) {
|
|
602
|
+
if (isAbortError(error)) {
|
|
603
|
+
throw error;
|
|
604
|
+
}
|
|
605
|
+
if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
|
|
606
|
+
logInfo(
|
|
607
|
+
"FetchRemoteComponent",
|
|
608
|
+
"Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
|
|
609
|
+
);
|
|
610
|
+
const proxiedRes = await fetch(
|
|
611
|
+
`${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`,
|
|
612
|
+
init?.signal ? { signal: init.signal } : void 0
|
|
613
|
+
);
|
|
614
|
+
if (proxiedRes.status === 200) {
|
|
615
|
+
return proxiedRes;
|
|
616
|
+
} else {
|
|
617
|
+
logError(
|
|
618
|
+
"FetchRemoteComponent",
|
|
619
|
+
`Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
throw error;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// src/shared/utils/index.ts
|
|
628
|
+
function escapeString(str) {
|
|
629
|
+
return str.replace(/[^a-z0-9]/g, "_");
|
|
630
|
+
}
|
|
631
|
+
var attrToProp = {
|
|
632
|
+
fetchpriority: "fetchPriority",
|
|
633
|
+
crossorigin: "crossOrigin",
|
|
634
|
+
imagesrcset: "imageSrcSet",
|
|
635
|
+
imagesizes: "imageSizes",
|
|
636
|
+
srcset: "srcSet"
|
|
637
|
+
};
|
|
638
|
+
|
|
592
639
|
// src/shared/client/const.ts
|
|
593
640
|
var DEFAULT_ROUTE = "/";
|
|
594
641
|
var RUNTIME_WEBPACK = "webpack";
|
|
@@ -642,7 +689,7 @@ function createChunkLoader(runtime) {
|
|
|
642
689
|
}
|
|
643
690
|
logDebug("ChunkLoader", `Fetching chunk from: "${url}"`);
|
|
644
691
|
self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
|
|
645
|
-
|
|
692
|
+
fetchWithProtectedRcFallback(url).then((res) => res.text()).then((code) => {
|
|
646
693
|
const hasTurbopack = code.includes("globalThis.TURBOPACK") || code.includes("self.TURBOPACK");
|
|
647
694
|
if (hasTurbopack) {
|
|
648
695
|
return handleTurbopackChunk(code, bundle ?? "", url);
|
|
@@ -1540,13 +1587,28 @@ function remoteFetchHeaders() {
|
|
|
1540
1587
|
}
|
|
1541
1588
|
|
|
1542
1589
|
// src/shared/ssr/fetch-with-hooks.ts
|
|
1543
|
-
async function fetchWithHooks(url,
|
|
1544
|
-
const {
|
|
1545
|
-
|
|
1590
|
+
async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
1591
|
+
const {
|
|
1592
|
+
onRequest,
|
|
1593
|
+
onResponse,
|
|
1594
|
+
abortController = new AbortController()
|
|
1595
|
+
} = options;
|
|
1596
|
+
const signal = abortController.signal;
|
|
1597
|
+
const hookOptions = {
|
|
1598
|
+
signal,
|
|
1599
|
+
abort: (reason) => abortController.abort(reason)
|
|
1600
|
+
};
|
|
1601
|
+
const init = {
|
|
1602
|
+
method: "GET",
|
|
1603
|
+
headers: remoteFetchHeaders(),
|
|
1604
|
+
signal,
|
|
1605
|
+
...additionalInit
|
|
1606
|
+
};
|
|
1607
|
+
let res = await onRequest?.(url, init, hookOptions);
|
|
1546
1608
|
if (!res) {
|
|
1547
|
-
res = await
|
|
1609
|
+
res = await fetchWithProtectedRcFallback(url, init);
|
|
1548
1610
|
}
|
|
1549
|
-
const transformedRes = await onResponse?.(url, res);
|
|
1611
|
+
const transformedRes = await onResponse?.(url, res, hookOptions);
|
|
1550
1612
|
if (transformedRes) {
|
|
1551
1613
|
res = transformedRes;
|
|
1552
1614
|
}
|
|
@@ -1753,18 +1815,18 @@ function RemoteComponent({
|
|
|
1753
1815
|
);
|
|
1754
1816
|
if (!html && src) {
|
|
1755
1817
|
const fetchInit = {
|
|
1756
|
-
method: "GET",
|
|
1757
|
-
headers: remoteFetchHeaders(),
|
|
1758
1818
|
credentials
|
|
1759
1819
|
};
|
|
1820
|
+
const abortController = new AbortController();
|
|
1760
1821
|
const res = await fetchWithHooks(url, fetchInit, {
|
|
1761
1822
|
onRequest,
|
|
1762
|
-
onResponse
|
|
1823
|
+
onResponse,
|
|
1824
|
+
abortController
|
|
1763
1825
|
});
|
|
1764
|
-
if (!res.ok) {
|
|
1826
|
+
if (!res || !res.ok) {
|
|
1765
1827
|
let error = failedToFetchRemoteComponentError(
|
|
1766
1828
|
url.href,
|
|
1767
|
-
res
|
|
1829
|
+
res ?? new Response(null, { status: 0 })
|
|
1768
1830
|
);
|
|
1769
1831
|
try {
|
|
1770
1832
|
const body = await res.text();
|
|
@@ -1785,7 +1847,9 @@ function RemoteComponent({
|
|
|
1785
1847
|
error.stack = errorStack;
|
|
1786
1848
|
}
|
|
1787
1849
|
}
|
|
1788
|
-
} catch {
|
|
1850
|
+
} catch (parseError) {
|
|
1851
|
+
if (isAbortError(parseError))
|
|
1852
|
+
throw parseError;
|
|
1789
1853
|
}
|
|
1790
1854
|
throw error;
|
|
1791
1855
|
}
|
|
@@ -2057,6 +2121,9 @@ function RemoteComponent({
|
|
|
2057
2121
|
}
|
|
2058
2122
|
}
|
|
2059
2123
|
} catch (error) {
|
|
2124
|
+
if (isAbortError(error)) {
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2060
2127
|
setRemoteComponent(error);
|
|
2061
2128
|
onError?.(error);
|
|
2062
2129
|
}
|