remote-components 0.0.47 → 0.0.49
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 +165 -70
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +165 -70
- package/dist/html/host.js.map +1 -1
- package/dist/internal/next/host/app-router-client.cjs +13 -50
- 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 +14 -51
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/next/host/remote-component-links.cjs +96 -0
- package/dist/internal/next/host/remote-component-links.cjs.map +1 -0
- package/dist/internal/next/host/remote-component-links.d.ts +25 -0
- package/dist/internal/next/host/remote-component-links.js +72 -0
- package/dist/internal/next/host/remote-component-links.js.map +1 -0
- package/dist/internal/shared/client/remote-component.cjs +17 -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 +17 -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.d.ts +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.cjs +13 -3
- package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +24 -13
- package/dist/internal/shared/ssr/fetch-with-hooks.js +13 -3
- package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs +6 -1
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.d.ts +3 -0
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js +6 -1
- package/dist/internal/shared/ssr/fetch-with-protected-rc-fallback.js.map +1 -1
- 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/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 +41 -8
- 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 +41 -8
- 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.map +1 -1
- package/dist/next/proxy.js.map +1 -1
- package/dist/react/index.cjs +41 -8
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +41 -8
- package/dist/react/index.js.map +1 -1
- 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 +9 -1
package/dist/html/host.js
CHANGED
|
@@ -248,19 +248,40 @@ var init_shared_modules = __esm({
|
|
|
248
248
|
}
|
|
249
249
|
});
|
|
250
250
|
|
|
251
|
+
// src/shared/utils/abort.ts
|
|
252
|
+
function isAbortError(error) {
|
|
253
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
if (error !== null && typeof error === "object" && "name" in error && error.name === "AbortError" && "message" in error && typeof error.message === "string") {
|
|
257
|
+
const e = error;
|
|
258
|
+
return typeof e.code === "number" || e.constructor?.name === "DOMException";
|
|
259
|
+
}
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
var init_abort = __esm({
|
|
263
|
+
"src/shared/utils/abort.ts"() {
|
|
264
|
+
"use strict";
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
251
268
|
// src/shared/ssr/fetch-with-protected-rc-fallback.ts
|
|
252
269
|
async function fetchWithProtectedRcFallback(url, init) {
|
|
253
270
|
try {
|
|
254
271
|
const res = await fetch(url, init);
|
|
255
272
|
return res;
|
|
256
273
|
} catch (error) {
|
|
274
|
+
if (isAbortError(error)) {
|
|
275
|
+
throw error;
|
|
276
|
+
}
|
|
257
277
|
if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== new URL(url).origin) {
|
|
258
278
|
logInfo(
|
|
259
279
|
"FetchRemoteComponent",
|
|
260
280
|
"Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
|
|
261
281
|
);
|
|
262
282
|
const proxiedRes = await fetch(
|
|
263
|
-
`${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}
|
|
283
|
+
`${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${url}`,
|
|
284
|
+
init?.signal ? { signal: init.signal } : void 0
|
|
264
285
|
);
|
|
265
286
|
if (proxiedRes.status === 200) {
|
|
266
287
|
return proxiedRes;
|
|
@@ -278,6 +299,7 @@ var RC_PROTECTED_REMOTE_FETCH_PATHNAME;
|
|
|
278
299
|
var init_fetch_with_protected_rc_fallback = __esm({
|
|
279
300
|
"src/shared/ssr/fetch-with-protected-rc-fallback.ts"() {
|
|
280
301
|
"use strict";
|
|
302
|
+
init_abort();
|
|
281
303
|
init_logger();
|
|
282
304
|
RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
283
305
|
}
|
|
@@ -1678,17 +1700,27 @@ function remoteFetchHeaders() {
|
|
|
1678
1700
|
// src/shared/ssr/fetch-with-hooks.ts
|
|
1679
1701
|
init_fetch_with_protected_rc_fallback();
|
|
1680
1702
|
async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
1681
|
-
const {
|
|
1703
|
+
const {
|
|
1704
|
+
onRequest,
|
|
1705
|
+
onResponse,
|
|
1706
|
+
abortController = new AbortController()
|
|
1707
|
+
} = options;
|
|
1708
|
+
const signal = abortController.signal;
|
|
1709
|
+
const hookOptions = {
|
|
1710
|
+
signal,
|
|
1711
|
+
abort: (reason) => abortController.abort(reason)
|
|
1712
|
+
};
|
|
1682
1713
|
const init = {
|
|
1683
1714
|
method: "GET",
|
|
1684
1715
|
headers: remoteFetchHeaders(),
|
|
1716
|
+
signal,
|
|
1685
1717
|
...additionalInit
|
|
1686
1718
|
};
|
|
1687
|
-
let res = await onRequest?.(url, init);
|
|
1719
|
+
let res = await onRequest?.(url, init, hookOptions);
|
|
1688
1720
|
if (!res) {
|
|
1689
1721
|
res = await fetchWithProtectedRcFallback(url, init);
|
|
1690
1722
|
}
|
|
1691
|
-
const transformedRes = await onResponse?.(url, res);
|
|
1723
|
+
const transformedRes = await onResponse?.(url, res, hookOptions);
|
|
1692
1724
|
if (transformedRes) {
|
|
1693
1725
|
res = transformedRes;
|
|
1694
1726
|
}
|
|
@@ -1697,8 +1729,87 @@ async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
|
1697
1729
|
|
|
1698
1730
|
// src/html/host/index.tsx
|
|
1699
1731
|
init_utils();
|
|
1732
|
+
init_abort();
|
|
1700
1733
|
init_logger();
|
|
1701
1734
|
|
|
1735
|
+
// src/html/host/attach-styles.ts
|
|
1736
|
+
init_error();
|
|
1737
|
+
async function attachStyles({
|
|
1738
|
+
doc,
|
|
1739
|
+
component,
|
|
1740
|
+
links,
|
|
1741
|
+
signal,
|
|
1742
|
+
baseUrl,
|
|
1743
|
+
remoteComponentSrc,
|
|
1744
|
+
root
|
|
1745
|
+
}) {
|
|
1746
|
+
const appendedLinks = [];
|
|
1747
|
+
let abortReject = null;
|
|
1748
|
+
const abortPromise = new Promise((_, reject) => {
|
|
1749
|
+
abortReject = reject;
|
|
1750
|
+
});
|
|
1751
|
+
const abortHandler = () => {
|
|
1752
|
+
for (const link of appendedLinks) {
|
|
1753
|
+
link.onload = null;
|
|
1754
|
+
link.onerror = null;
|
|
1755
|
+
link.remove();
|
|
1756
|
+
}
|
|
1757
|
+
abortReject?.(new DOMException("Aborted", "AbortError"));
|
|
1758
|
+
};
|
|
1759
|
+
signal?.addEventListener("abort", abortHandler, { once: true });
|
|
1760
|
+
try {
|
|
1761
|
+
await Promise.all(
|
|
1762
|
+
Array.from(links).filter((link) => !component.contains(link)).map((link) => {
|
|
1763
|
+
const newLink = document.createElement("link");
|
|
1764
|
+
appendedLinks.push(newLink);
|
|
1765
|
+
const loadPromise = new Promise((resolve, reject) => {
|
|
1766
|
+
if (link.rel === "stylesheet") {
|
|
1767
|
+
newLink.onload = () => resolve();
|
|
1768
|
+
newLink.onerror = () => reject(
|
|
1769
|
+
new RemoteComponentsError(
|
|
1770
|
+
`Failed to load <link href="${link.href}"> for Remote Component. Check the URL is correct.`
|
|
1771
|
+
)
|
|
1772
|
+
);
|
|
1773
|
+
} else {
|
|
1774
|
+
resolve();
|
|
1775
|
+
}
|
|
1776
|
+
});
|
|
1777
|
+
for (const attr of link.attributes) {
|
|
1778
|
+
if (attr.name === "href") {
|
|
1779
|
+
newLink.setAttribute(
|
|
1780
|
+
attr.name,
|
|
1781
|
+
new URL(attr.value, baseUrl ?? location.origin).href
|
|
1782
|
+
);
|
|
1783
|
+
} else {
|
|
1784
|
+
newLink.setAttribute(attr.name, attr.value);
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
if (remoteComponentSrc) {
|
|
1788
|
+
newLink.setAttribute(
|
|
1789
|
+
"data-remote-component-src",
|
|
1790
|
+
remoteComponentSrc
|
|
1791
|
+
);
|
|
1792
|
+
}
|
|
1793
|
+
root?.appendChild(newLink);
|
|
1794
|
+
return Promise.race([loadPromise, abortPromise]);
|
|
1795
|
+
})
|
|
1796
|
+
);
|
|
1797
|
+
} finally {
|
|
1798
|
+
signal?.removeEventListener("abort", abortHandler);
|
|
1799
|
+
}
|
|
1800
|
+
const styles = doc.querySelectorAll("style");
|
|
1801
|
+
for (const style of styles) {
|
|
1802
|
+
if (style.parentElement?.tagName.toLowerCase() === "head") {
|
|
1803
|
+
const newStyle = document.createElement("style");
|
|
1804
|
+
newStyle.textContent = style.textContent;
|
|
1805
|
+
if (remoteComponentSrc) {
|
|
1806
|
+
newStyle.setAttribute("data-remote-component-src", remoteComponentSrc);
|
|
1807
|
+
}
|
|
1808
|
+
root?.appendChild(newStyle);
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1702
1813
|
// src/html/host/runtime/index.ts
|
|
1703
1814
|
init_error();
|
|
1704
1815
|
async function getRuntime(type, url, bundle, shared, remoteShared) {
|
|
@@ -1740,6 +1851,8 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1740
1851
|
reactRoot;
|
|
1741
1852
|
onRequest;
|
|
1742
1853
|
onResponse;
|
|
1854
|
+
/** Current AbortController for the loading operation - can be used to cancel loading via controller.abort() */
|
|
1855
|
+
abortController;
|
|
1743
1856
|
static get observedAttributes() {
|
|
1744
1857
|
return ["src", "name", "mode"];
|
|
1745
1858
|
}
|
|
@@ -1750,6 +1863,10 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1750
1863
|
if ((name === "src" || name === "name") && oldValue !== newValue) {
|
|
1751
1864
|
if (this.getAttribute("src")) {
|
|
1752
1865
|
this.load().catch((e) => {
|
|
1866
|
+
if (isAbortError(e)) {
|
|
1867
|
+
this.isLoading = false;
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1753
1870
|
logError("HtmlHost", "Error loading remote component.", e);
|
|
1754
1871
|
const errorEvent = new Event("error", {
|
|
1755
1872
|
bubbles: true,
|
|
@@ -1772,6 +1889,10 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1772
1889
|
});
|
|
1773
1890
|
this.root = newRoot;
|
|
1774
1891
|
this.load().catch((e) => {
|
|
1892
|
+
if (isAbortError(e)) {
|
|
1893
|
+
this.isLoading = false;
|
|
1894
|
+
return;
|
|
1895
|
+
}
|
|
1775
1896
|
logError("HtmlHost", "Error reloading remote component.", e);
|
|
1776
1897
|
const errorEvent = new Event("error", {
|
|
1777
1898
|
bubbles: true,
|
|
@@ -1805,6 +1926,10 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1805
1926
|
this.bundle = "default";
|
|
1806
1927
|
if (this.hasAttribute("src") || this.querySelector("div#__REMOTE_COMPONENT__") || this.hasAttribute("data-ssr")) {
|
|
1807
1928
|
this.load().catch((e) => {
|
|
1929
|
+
if (isAbortError(e)) {
|
|
1930
|
+
this.isLoading = false;
|
|
1931
|
+
return;
|
|
1932
|
+
}
|
|
1808
1933
|
logError("HtmlHost", "Error loading remote component.", e);
|
|
1809
1934
|
const errorEvent = new Event("error", {
|
|
1810
1935
|
bubbles: true,
|
|
@@ -1819,6 +1944,8 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1819
1944
|
}
|
|
1820
1945
|
this.isLoading = true;
|
|
1821
1946
|
const src = this.getAttribute("src");
|
|
1947
|
+
this.abortController = new AbortController();
|
|
1948
|
+
const signal = this.abortController.signal;
|
|
1822
1949
|
const beforeLoadEvent = new Event("beforeload", {
|
|
1823
1950
|
bubbles: true,
|
|
1824
1951
|
composed: true
|
|
@@ -1843,12 +1970,16 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1843
1970
|
};
|
|
1844
1971
|
const res = await fetchWithHooks(url, fetchInit, {
|
|
1845
1972
|
onRequest: this.onRequest,
|
|
1846
|
-
onResponse: this.onResponse
|
|
1973
|
+
onResponse: this.onResponse,
|
|
1974
|
+
abortController: this.abortController
|
|
1847
1975
|
});
|
|
1848
|
-
if (!res.ok) {
|
|
1849
|
-
let error = failedToFetchRemoteComponentError(
|
|
1976
|
+
if (!res || !res.ok) {
|
|
1977
|
+
let error = failedToFetchRemoteComponentError(
|
|
1978
|
+
url.href,
|
|
1979
|
+
res ?? new Response(null, { status: 0 })
|
|
1980
|
+
);
|
|
1850
1981
|
try {
|
|
1851
|
-
const body = await res.text();
|
|
1982
|
+
const body = res ? await res.text() : "";
|
|
1852
1983
|
const parser2 = new DOMParser();
|
|
1853
1984
|
const doc2 = parser2.parseFromString(body, "text/html");
|
|
1854
1985
|
const errorTemplate = doc2.querySelector(
|
|
@@ -1866,7 +1997,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1866
1997
|
error.stack = errorStack;
|
|
1867
1998
|
}
|
|
1868
1999
|
}
|
|
1869
|
-
} catch {
|
|
2000
|
+
} catch (parseError) {
|
|
2001
|
+
if (isAbortError(parseError))
|
|
2002
|
+
throw parseError;
|
|
1870
2003
|
}
|
|
1871
2004
|
throw error;
|
|
1872
2005
|
}
|
|
@@ -1977,64 +2110,26 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1977
2110
|
const removable = Array.from(this.childNodes);
|
|
1978
2111
|
const links = doc.querySelectorAll("link[href]");
|
|
1979
2112
|
const remoteComponentSrc = this.getAttribute("src");
|
|
1980
|
-
const
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
};
|
|
1991
|
-
newLink.onerror = () => {
|
|
1992
|
-
reject(
|
|
1993
|
-
new RemoteComponentsError(
|
|
1994
|
-
`Failed to load <link href="${link.href}"> for Remote Component. Check the URL is correct.`
|
|
1995
|
-
)
|
|
1996
|
-
);
|
|
1997
|
-
};
|
|
1998
|
-
} else {
|
|
1999
|
-
resolve();
|
|
2000
|
-
}
|
|
2001
|
-
for (const attr of link.attributes) {
|
|
2002
|
-
if (attr.name === "href") {
|
|
2003
|
-
newLink.setAttribute(
|
|
2004
|
-
attr.name,
|
|
2005
|
-
new URL(attr.value, url ?? location.origin).href
|
|
2006
|
-
);
|
|
2007
|
-
} else {
|
|
2008
|
-
newLink.setAttribute(attr.name, attr.value);
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
|
-
if (remoteComponentSrc) {
|
|
2012
|
-
newLink.setAttribute(
|
|
2013
|
-
"data-remote-component-src",
|
|
2014
|
-
remoteComponentSrc
|
|
2015
|
-
);
|
|
2016
|
-
}
|
|
2017
|
-
this.root?.appendChild(newLink);
|
|
2018
|
-
});
|
|
2019
|
-
})
|
|
2020
|
-
);
|
|
2021
|
-
const styles = doc.querySelectorAll("style");
|
|
2022
|
-
styles.forEach((style) => {
|
|
2023
|
-
if (style.parentElement?.tagName.toLowerCase() === "head") {
|
|
2024
|
-
const newStyle = document.createElement("style");
|
|
2025
|
-
newStyle.textContent = style.textContent;
|
|
2026
|
-
if (remoteComponentSrc) {
|
|
2027
|
-
newStyle.setAttribute(
|
|
2028
|
-
"data-remote-component-src",
|
|
2029
|
-
remoteComponentSrc
|
|
2030
|
-
);
|
|
2031
|
-
}
|
|
2032
|
-
this.root?.appendChild(newStyle);
|
|
2033
|
-
}
|
|
2034
|
-
});
|
|
2035
|
-
};
|
|
2113
|
+
const doAttachStyles = () => attachStyles({
|
|
2114
|
+
doc,
|
|
2115
|
+
component,
|
|
2116
|
+
links,
|
|
2117
|
+
signal: void 0,
|
|
2118
|
+
// Effects run after load, no abort needed
|
|
2119
|
+
baseUrl: url?.href,
|
|
2120
|
+
remoteComponentSrc,
|
|
2121
|
+
root: this.root ?? null
|
|
2122
|
+
});
|
|
2036
2123
|
if (!this.reactRoot) {
|
|
2037
|
-
await
|
|
2124
|
+
await attachStyles({
|
|
2125
|
+
doc,
|
|
2126
|
+
component,
|
|
2127
|
+
links,
|
|
2128
|
+
signal,
|
|
2129
|
+
baseUrl: url?.href,
|
|
2130
|
+
remoteComponentSrc,
|
|
2131
|
+
root: this.root
|
|
2132
|
+
});
|
|
2038
2133
|
}
|
|
2039
2134
|
applyOriginToNodes(doc, url ?? new URL(location.href));
|
|
2040
2135
|
if (!this.reactRoot) {
|
|
@@ -2189,8 +2284,8 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2189
2284
|
doCleanup();
|
|
2190
2285
|
applyReset();
|
|
2191
2286
|
if (!initial) {
|
|
2192
|
-
|
|
2193
|
-
logError("HtmlHost", "Error attaching
|
|
2287
|
+
doAttachStyles().catch((e) => {
|
|
2288
|
+
logError("HtmlHost", "Error attaching styles.", e);
|
|
2194
2289
|
});
|
|
2195
2290
|
}
|
|
2196
2291
|
this.isLoading = false;
|
|
@@ -2242,8 +2337,8 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2242
2337
|
doCleanup();
|
|
2243
2338
|
if (!initial) {
|
|
2244
2339
|
applyReset();
|
|
2245
|
-
|
|
2246
|
-
logError("HtmlHost", "Error attaching
|
|
2340
|
+
doAttachStyles().catch((e) => {
|
|
2341
|
+
logError("HtmlHost", "Error attaching styles.", e);
|
|
2247
2342
|
});
|
|
2248
2343
|
}
|
|
2249
2344
|
remoteComponent.isLoading = false;
|