remote-components 0.1.0 → 0.1.2
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-76eb1b8b.d.ts → component-loader-21865da3.d.ts} +140 -16
- package/dist/host-config-58cdccea.d.ts +87 -0
- package/dist/html/host.cjs +294 -162
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +294 -162
- package/dist/html/host.js.map +1 -1
- package/dist/internal/next/host/app-router-client.cjs +9 -7
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +32 -19
- package/dist/internal/next/host/app-router-client.js +9 -7
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/next/remote/render-server.cjs.map +1 -1
- package/dist/internal/next/remote/render-server.d.ts +13 -14
- package/dist/internal/next/remote/render-server.js.map +1 -1
- package/dist/internal/shared/client/proxy-through-host.cjs +15 -1
- package/dist/internal/shared/client/proxy-through-host.cjs.map +1 -1
- package/dist/internal/shared/client/proxy-through-host.d.ts +5 -0
- package/dist/internal/shared/client/proxy-through-host.js +15 -1
- package/dist/internal/shared/client/proxy-through-host.js.map +1 -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.map +1 -1
- package/dist/internal/shared/contract/host-state.cjs +38 -0
- package/dist/internal/shared/contract/host-state.cjs.map +1 -0
- package/dist/internal/shared/contract/host-state.d.ts +53 -0
- package/dist/internal/shared/contract/host-state.js +14 -0
- package/dist/internal/shared/contract/host-state.js.map +1 -0
- package/dist/internal/shared/contract/resolve-name-from-src.cjs +40 -0
- package/dist/internal/shared/contract/resolve-name-from-src.cjs.map +1 -0
- package/dist/internal/shared/contract/resolve-name-from-src.d.ts +13 -0
- package/dist/internal/shared/contract/resolve-name-from-src.js +16 -0
- package/dist/internal/shared/contract/resolve-name-from-src.js.map +1 -0
- package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
- 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.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +1 -1
- package/dist/next/host/app-router-server.cjs.map +1 -1
- package/dist/next/host/app-router-server.d.ts +11 -41
- package/dist/next/host/app-router-server.js.map +1 -1
- package/dist/next/host/client/index.cjs +203 -95
- 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 +203 -95
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-client.cjs.map +1 -1
- package/dist/next/host/pages-router-client.d.ts +13 -36
- package/dist/next/host/pages-router-client.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.d.ts +17 -42
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.ts +13 -39
- package/dist/next/index.js.map +1 -1
- package/dist/next/remote/server.d.ts +4 -0
- package/dist/react/index.cjs +203 -95
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +12 -49
- package/dist/react/index.js +203 -95
- package/dist/react/index.js.map +1 -1
- package/dist/{types-cbe44b51.d.ts → types-2b26a246.d.ts} +23 -6
- package/package.json +1 -1
package/dist/html/host.cjs
CHANGED
|
@@ -167,6 +167,33 @@ var init_error = __esm({
|
|
|
167
167
|
}
|
|
168
168
|
});
|
|
169
169
|
|
|
170
|
+
// src/shared/utils/index.ts
|
|
171
|
+
function escapeString(str) {
|
|
172
|
+
return str.replace(/[^a-z0-9]/g, "_");
|
|
173
|
+
}
|
|
174
|
+
var init_utils = __esm({
|
|
175
|
+
"src/shared/utils/index.ts"() {
|
|
176
|
+
"use strict";
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// src/shared/client/const.ts
|
|
181
|
+
function getBundleKey(bundle) {
|
|
182
|
+
return escapeString(bundle);
|
|
183
|
+
}
|
|
184
|
+
var DEFAULT_ROUTE, RUNTIME_WEBPACK, RUNTIME_TURBOPACK, RUNTIME_SCRIPT, REMOTE_COMPONENT_REGEX;
|
|
185
|
+
var init_const = __esm({
|
|
186
|
+
"src/shared/client/const.ts"() {
|
|
187
|
+
"use strict";
|
|
188
|
+
init_utils();
|
|
189
|
+
DEFAULT_ROUTE = "/";
|
|
190
|
+
RUNTIME_WEBPACK = "webpack";
|
|
191
|
+
RUNTIME_TURBOPACK = "turbopack";
|
|
192
|
+
RUNTIME_SCRIPT = "script";
|
|
193
|
+
REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
170
197
|
// src/shared/utils/logger.ts
|
|
171
198
|
function logDebug(location2, message) {
|
|
172
199
|
if (DEBUG) {
|
|
@@ -449,31 +476,6 @@ var init_script_loader = __esm({
|
|
|
449
476
|
}
|
|
450
477
|
});
|
|
451
478
|
|
|
452
|
-
// src/shared/utils/index.ts
|
|
453
|
-
function escapeString(str) {
|
|
454
|
-
return str.replace(/[^a-z0-9]/g, "_");
|
|
455
|
-
}
|
|
456
|
-
var init_utils = __esm({
|
|
457
|
-
"src/shared/utils/index.ts"() {
|
|
458
|
-
"use strict";
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
// src/shared/client/const.ts
|
|
463
|
-
function getBundleKey(bundle) {
|
|
464
|
-
return escapeString(bundle);
|
|
465
|
-
}
|
|
466
|
-
var RUNTIME_WEBPACK, RUNTIME_TURBOPACK, REMOTE_COMPONENT_REGEX;
|
|
467
|
-
var init_const = __esm({
|
|
468
|
-
"src/shared/client/const.ts"() {
|
|
469
|
-
"use strict";
|
|
470
|
-
init_utils();
|
|
471
|
-
RUNTIME_WEBPACK = "webpack";
|
|
472
|
-
RUNTIME_TURBOPACK = "turbopack";
|
|
473
|
-
REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
|
|
477
479
|
// src/shared/client/turbopack-patterns.ts
|
|
478
480
|
var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE, TURBOPACK_GLOBAL_RE;
|
|
479
481
|
var init_turbopack_patterns = __esm({
|
|
@@ -1795,7 +1797,21 @@ function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
|
1795
1797
|
// src/shared/client/proxy-through-host.ts
|
|
1796
1798
|
init_protected_rc_fallback();
|
|
1797
1799
|
function withRemoteSrc(resolveClientUrl, remoteSrc) {
|
|
1798
|
-
|
|
1800
|
+
const remoteOrigin = parseOrigin(remoteSrc);
|
|
1801
|
+
return (url) => {
|
|
1802
|
+
const urlOrigin = parseOrigin(url);
|
|
1803
|
+
if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
|
|
1804
|
+
return void 0;
|
|
1805
|
+
}
|
|
1806
|
+
return resolveClientUrl(remoteSrc, url);
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
function parseOrigin(url) {
|
|
1810
|
+
try {
|
|
1811
|
+
return new URL(url).origin;
|
|
1812
|
+
} catch {
|
|
1813
|
+
return void 0;
|
|
1814
|
+
}
|
|
1799
1815
|
}
|
|
1800
1816
|
var proxyClientRequestsThroughHost = (remoteSrc, url) => {
|
|
1801
1817
|
if (typeof location === "undefined") {
|
|
@@ -1820,6 +1836,102 @@ function bindResolveClientUrl(prop, remoteSrc) {
|
|
|
1820
1836
|
return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
|
|
1821
1837
|
}
|
|
1822
1838
|
|
|
1839
|
+
// src/shared/client/parse-remote-html.ts
|
|
1840
|
+
init_error();
|
|
1841
|
+
init_const();
|
|
1842
|
+
function validateSingleComponent(doc, name, url) {
|
|
1843
|
+
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) || doc.querySelectorAll("remote-component:not([src])").length > 1 && !doc.querySelector(`remote-component[name="${name}"]`)) {
|
|
1844
|
+
throw multipleRemoteComponentsError(url);
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
function findComponentElement(doc, name) {
|
|
1848
|
+
return doc.querySelector(`div[data-bundle][data-route][id^="${name}"]`) ?? doc.querySelector("div[data-bundle][data-route]") ?? doc.querySelector("div#__next") ?? doc.querySelector(`remote-component[name="${name}"]:not([src])`) ?? doc.querySelector("remote-component:not([src])");
|
|
1849
|
+
}
|
|
1850
|
+
function parseNextData(doc) {
|
|
1851
|
+
return JSON.parse(
|
|
1852
|
+
(doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
|
|
1853
|
+
);
|
|
1854
|
+
}
|
|
1855
|
+
function resolveComponentName(component, nextData, fallbackName) {
|
|
1856
|
+
const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
|
|
1857
|
+
const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
|
|
1858
|
+
return { name, isRemoteComponent };
|
|
1859
|
+
}
|
|
1860
|
+
function extractComponentMetadata(component, nextData, name, url) {
|
|
1861
|
+
return {
|
|
1862
|
+
name,
|
|
1863
|
+
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
|
|
1864
|
+
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
|
|
1865
|
+
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
|
|
1866
|
+
};
|
|
1867
|
+
}
|
|
1868
|
+
function extractRemoteShared(doc, name, nextData) {
|
|
1869
|
+
const remoteSharedEl = doc.querySelector(
|
|
1870
|
+
`#${name}_shared[data-remote-components-shared]`
|
|
1871
|
+
);
|
|
1872
|
+
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
1873
|
+
remoteSharedEl?.remove();
|
|
1874
|
+
return remoteShared;
|
|
1875
|
+
}
|
|
1876
|
+
function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
|
|
1877
|
+
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
1878
|
+
throw new RemoteComponentsError(
|
|
1879
|
+
`Remote Component not found on ${url}.${name !== "__vercel_remote_component" ? ` The name for the <RemoteComponent> is "${name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
|
|
1880
|
+
);
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
function extractLinks(doc, component) {
|
|
1884
|
+
return Array.from(doc.querySelectorAll("link[href]")).filter(
|
|
1885
|
+
(link) => !component.contains(link)
|
|
1886
|
+
);
|
|
1887
|
+
}
|
|
1888
|
+
function extractScripts(doc, component, isRemoteComponent) {
|
|
1889
|
+
return Array.from(
|
|
1890
|
+
(isRemoteComponent ? component : doc).querySelectorAll(
|
|
1891
|
+
"script[src],script[data-src]"
|
|
1892
|
+
)
|
|
1893
|
+
);
|
|
1894
|
+
}
|
|
1895
|
+
function parseRemoteComponentDocument(doc, name, url) {
|
|
1896
|
+
validateSingleComponent(doc, name, url.href);
|
|
1897
|
+
const component = findComponentElement(doc, name);
|
|
1898
|
+
const nextData = parseNextData(doc);
|
|
1899
|
+
const { name: resolvedName, isRemoteComponent } = resolveComponentName(
|
|
1900
|
+
component,
|
|
1901
|
+
nextData,
|
|
1902
|
+
name
|
|
1903
|
+
);
|
|
1904
|
+
const rsc = doc.querySelector(`#${resolvedName}_rsc`);
|
|
1905
|
+
const metadata = extractComponentMetadata(
|
|
1906
|
+
component,
|
|
1907
|
+
nextData,
|
|
1908
|
+
resolvedName,
|
|
1909
|
+
url
|
|
1910
|
+
);
|
|
1911
|
+
const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
|
|
1912
|
+
validateComponentFound(
|
|
1913
|
+
component,
|
|
1914
|
+
rsc,
|
|
1915
|
+
nextData,
|
|
1916
|
+
isRemoteComponent,
|
|
1917
|
+
url.href,
|
|
1918
|
+
resolvedName
|
|
1919
|
+
);
|
|
1920
|
+
const links = extractLinks(doc, component);
|
|
1921
|
+
const scripts = extractScripts(doc, component, isRemoteComponent);
|
|
1922
|
+
return {
|
|
1923
|
+
component,
|
|
1924
|
+
name: resolvedName,
|
|
1925
|
+
isRemoteComponent,
|
|
1926
|
+
metadata,
|
|
1927
|
+
nextData,
|
|
1928
|
+
rsc,
|
|
1929
|
+
remoteShared,
|
|
1930
|
+
links,
|
|
1931
|
+
scripts
|
|
1932
|
+
};
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1823
1935
|
// src/shared/client/remote-component.ts
|
|
1824
1936
|
init_error();
|
|
1825
1937
|
|
|
@@ -1910,6 +2022,32 @@ init_script_loader();
|
|
|
1910
2022
|
init_static_loader();
|
|
1911
2023
|
init_webpack_adapter();
|
|
1912
2024
|
|
|
2025
|
+
// src/shared/contract/host-state.ts
|
|
2026
|
+
function createHostState() {
|
|
2027
|
+
return {
|
|
2028
|
+
stage: "idle",
|
|
2029
|
+
prevSrc: void 0,
|
|
2030
|
+
prevUrl: void 0,
|
|
2031
|
+
prevName: void 0,
|
|
2032
|
+
prevIsRemoteComponent: false,
|
|
2033
|
+
abortController: void 0
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
// src/shared/contract/resolve-name-from-src.ts
|
|
2038
|
+
function resolveNameFromSrc(src, defaultName) {
|
|
2039
|
+
if (!src) {
|
|
2040
|
+
return defaultName;
|
|
2041
|
+
}
|
|
2042
|
+
const hash = typeof src === "string" ? src : src.hash;
|
|
2043
|
+
const hashIndex = hash.indexOf("#");
|
|
2044
|
+
if (hashIndex < 0) {
|
|
2045
|
+
return defaultName;
|
|
2046
|
+
}
|
|
2047
|
+
const name = hash.slice(hashIndex + 1);
|
|
2048
|
+
return name || defaultName;
|
|
2049
|
+
}
|
|
2050
|
+
|
|
1913
2051
|
// src/html/host/index.tsx
|
|
1914
2052
|
init_error();
|
|
1915
2053
|
|
|
@@ -1966,6 +2104,15 @@ async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
|
1966
2104
|
return res;
|
|
1967
2105
|
}
|
|
1968
2106
|
|
|
2107
|
+
// src/shared/ssr/get-client-or-server-url.ts
|
|
2108
|
+
function getClientOrServerUrl(src, serverFallback) {
|
|
2109
|
+
const fallback = typeof location !== "undefined" ? location.href : serverFallback;
|
|
2110
|
+
if (!src) {
|
|
2111
|
+
return new URL(fallback);
|
|
2112
|
+
}
|
|
2113
|
+
return typeof src === "string" ? new URL(src, fallback) : src;
|
|
2114
|
+
}
|
|
2115
|
+
|
|
1969
2116
|
// src/html/host/index.tsx
|
|
1970
2117
|
init_utils();
|
|
1971
2118
|
init_abort();
|
|
@@ -2097,42 +2244,76 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2097
2244
|
fallbackSlot;
|
|
2098
2245
|
__next = null;
|
|
2099
2246
|
fouc = null;
|
|
2100
|
-
|
|
2101
|
-
prevIsRemoteComponent = false;
|
|
2102
|
-
prevUrl;
|
|
2103
|
-
prevSrc = null;
|
|
2104
|
-
prevName;
|
|
2247
|
+
hostState = createHostState();
|
|
2105
2248
|
root = null;
|
|
2106
2249
|
reactRoot;
|
|
2107
2250
|
onRequest;
|
|
2108
2251
|
onResponse;
|
|
2109
2252
|
resolveClientUrl;
|
|
2110
|
-
|
|
2111
|
-
|
|
2253
|
+
// -- HostConfig property accessors (attribute-reflected) --
|
|
2254
|
+
get src() {
|
|
2255
|
+
return this.getAttribute("src") ?? void 0;
|
|
2256
|
+
}
|
|
2257
|
+
set src(value) {
|
|
2258
|
+
if (value == null) {
|
|
2259
|
+
this.removeAttribute("src");
|
|
2260
|
+
} else {
|
|
2261
|
+
this.setAttribute("src", String(value));
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
/** Always `true` — the HTML host always isolates via Shadow DOM. */
|
|
2265
|
+
get isolate() {
|
|
2266
|
+
return true;
|
|
2267
|
+
}
|
|
2268
|
+
get mode() {
|
|
2269
|
+
const attr = this.getAttribute("mode");
|
|
2270
|
+
return attr === "closed" ? "closed" : "open";
|
|
2271
|
+
}
|
|
2272
|
+
set mode(value) {
|
|
2273
|
+
if (value) {
|
|
2274
|
+
this.setAttribute("mode", value);
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
get reset() {
|
|
2278
|
+
return this.getAttribute("reset") !== null;
|
|
2279
|
+
}
|
|
2280
|
+
set reset(value) {
|
|
2281
|
+
if (value) {
|
|
2282
|
+
this.setAttribute("reset", "");
|
|
2283
|
+
} else {
|
|
2284
|
+
this.removeAttribute("reset");
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
get credentials() {
|
|
2288
|
+
return this.getAttribute("credentials") || "same-origin";
|
|
2289
|
+
}
|
|
2290
|
+
set credentials(value) {
|
|
2291
|
+
if (value) {
|
|
2292
|
+
this.setAttribute("credentials", value);
|
|
2293
|
+
} else {
|
|
2294
|
+
this.removeAttribute("credentials");
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2112
2297
|
static get observedAttributes() {
|
|
2113
2298
|
return ["src", "name", "mode"];
|
|
2114
2299
|
}
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2300
|
+
dispatchLifecycleEvent(type, detail) {
|
|
2301
|
+
const event = new Event(type, { bubbles: true, composed: true });
|
|
2302
|
+
if (detail) {
|
|
2303
|
+
Object.assign(event, detail);
|
|
2304
|
+
}
|
|
2305
|
+
this.dispatchEvent(event);
|
|
2306
|
+
}
|
|
2118
2307
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
2119
2308
|
if ((name === "src" || name === "name") && oldValue !== newValue) {
|
|
2120
|
-
if (this.
|
|
2309
|
+
if (this.src) {
|
|
2121
2310
|
this.load().catch((e) => {
|
|
2122
2311
|
if (isAbortError(e)) {
|
|
2123
2312
|
return;
|
|
2124
2313
|
}
|
|
2125
2314
|
logError("HtmlHost", "Error loading remote component.", e);
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
composed: true
|
|
2129
|
-
});
|
|
2130
|
-
Object.assign(errorEvent, {
|
|
2131
|
-
error: e,
|
|
2132
|
-
src: this.getAttribute("src")
|
|
2133
|
-
});
|
|
2134
|
-
this.dispatchEvent(errorEvent);
|
|
2135
|
-
this.isLoading = false;
|
|
2315
|
+
this.dispatchLifecycleEvent("error", { error: e, src: this.src });
|
|
2316
|
+
this.hostState.stage = "error";
|
|
2136
2317
|
});
|
|
2137
2318
|
}
|
|
2138
2319
|
} else if (name === "mode" && oldValue !== newValue && this.root) {
|
|
@@ -2148,15 +2329,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2148
2329
|
return;
|
|
2149
2330
|
}
|
|
2150
2331
|
logError("HtmlHost", "Error reloading remote component.", e);
|
|
2151
|
-
|
|
2152
|
-
bubbles: true,
|
|
2153
|
-
composed: true
|
|
2154
|
-
});
|
|
2155
|
-
Object.assign(errorEvent, {
|
|
2156
|
-
error: e,
|
|
2157
|
-
src: this.getAttribute("src")
|
|
2158
|
-
});
|
|
2159
|
-
this.dispatchEvent(errorEvent);
|
|
2332
|
+
this.dispatchLifecycleEvent("error", { error: e, src: this.src });
|
|
2160
2333
|
});
|
|
2161
2334
|
}
|
|
2162
2335
|
}
|
|
@@ -2166,9 +2339,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2166
2339
|
resolve(void 0);
|
|
2167
2340
|
});
|
|
2168
2341
|
});
|
|
2169
|
-
if (this.
|
|
2170
|
-
this.abortController?.abort();
|
|
2171
|
-
this.
|
|
2342
|
+
if (this.hostState.stage === "loading") {
|
|
2343
|
+
this.hostState.abortController?.abort();
|
|
2344
|
+
this.hostState.stage = "idle";
|
|
2172
2345
|
if (this.root && !this.reactRoot) {
|
|
2173
2346
|
this.root.innerHTML = "";
|
|
2174
2347
|
this.fouc = null;
|
|
@@ -2178,29 +2351,24 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2178
2351
|
}
|
|
2179
2352
|
if (!this.root) {
|
|
2180
2353
|
this.root = this.attachShadow({
|
|
2181
|
-
mode: this.
|
|
2354
|
+
mode: this.mode === "closed" ? "closed" : "open"
|
|
2182
2355
|
});
|
|
2183
2356
|
this.fallbackSlot = document.createElement("slot");
|
|
2184
2357
|
this.root.appendChild(this.fallbackSlot);
|
|
2185
2358
|
}
|
|
2186
2359
|
this.name = this.getAttribute("name") || "__vercel_remote_component";
|
|
2187
2360
|
this.bundle = "default";
|
|
2188
|
-
this.
|
|
2189
|
-
const src = this.
|
|
2190
|
-
this.abortController = new AbortController();
|
|
2191
|
-
const signal = this.abortController.signal;
|
|
2192
|
-
const isCurrentLoad = () => !signal.aborted && this.
|
|
2361
|
+
this.hostState.stage = "loading";
|
|
2362
|
+
const src = this.src;
|
|
2363
|
+
this.hostState.abortController = new AbortController();
|
|
2364
|
+
const signal = this.hostState.abortController.signal;
|
|
2365
|
+
const isCurrentLoad = () => !signal.aborted && this.src === src;
|
|
2193
2366
|
const abandonLoad = () => {
|
|
2194
|
-
if (this.abortController?.signal === signal && this.
|
|
2195
|
-
this.
|
|
2367
|
+
if (this.hostState.abortController?.signal === signal && this.hostState.stage === "loading") {
|
|
2368
|
+
this.hostState.stage = "idle";
|
|
2196
2369
|
}
|
|
2197
2370
|
};
|
|
2198
|
-
|
|
2199
|
-
bubbles: true,
|
|
2200
|
-
composed: true
|
|
2201
|
-
});
|
|
2202
|
-
Object.assign(beforeLoadEvent, { src });
|
|
2203
|
-
this.dispatchEvent(beforeLoadEvent);
|
|
2371
|
+
this.dispatchLifecycleEvent("beforeload", { src });
|
|
2204
2372
|
const remoteComponentChild = this.querySelector("div#__REMOTE_COMPONENT__") || this.querySelector("div[data-bundle][data-route]");
|
|
2205
2373
|
if (!src && !remoteComponentChild) {
|
|
2206
2374
|
throw new RemoteComponentsError('"src" attribute is required');
|
|
@@ -2208,15 +2376,16 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2208
2376
|
let url = null;
|
|
2209
2377
|
let html = this.innerHTML;
|
|
2210
2378
|
if (src) {
|
|
2211
|
-
url =
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2379
|
+
url = getClientOrServerUrl(src, window.location.href);
|
|
2380
|
+
this.name = resolveNameFromSrc(
|
|
2381
|
+
src,
|
|
2382
|
+
this.name ?? "__vercel_remote_component"
|
|
2383
|
+
);
|
|
2215
2384
|
}
|
|
2216
2385
|
const resolveClientUrl = url ? bindResolveClientUrl(this.resolveClientUrl, url.href) : void 0;
|
|
2217
2386
|
if (!remoteComponentChild && url) {
|
|
2218
2387
|
const fetchInit = {
|
|
2219
|
-
credentials: this.
|
|
2388
|
+
credentials: this.credentials || "same-origin"
|
|
2220
2389
|
};
|
|
2221
2390
|
const resolvedUrl = new URL(
|
|
2222
2391
|
resolveClientUrl?.(url.href) ?? url.href,
|
|
@@ -2227,7 +2396,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2227
2396
|
res = await fetchWithHooks(resolvedUrl, fetchInit, {
|
|
2228
2397
|
onRequest: this.onRequest,
|
|
2229
2398
|
onResponse: this.onResponse,
|
|
2230
|
-
abortController: this.abortController
|
|
2399
|
+
abortController: this.hostState.abortController
|
|
2231
2400
|
});
|
|
2232
2401
|
} catch (e) {
|
|
2233
2402
|
if (isAbortError(e)) {
|
|
@@ -2252,29 +2421,27 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2252
2421
|
}
|
|
2253
2422
|
const parser = new DOMParser();
|
|
2254
2423
|
const doc = parser.parseFromString(html, "text/html");
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
url?.href ?? (this.getAttribute("src") || "unknown")
|
|
2260
|
-
);
|
|
2261
|
-
}
|
|
2262
|
-
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
|
|
2263
|
-
doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
|
|
2264
|
-
doc.querySelector("div#__next") ?? // fallback to a <remote-component> element
|
|
2265
|
-
doc.querySelector(`remote-component[name="${this.name}"]:not([src])`) ?? doc.querySelector("remote-component:not([src])");
|
|
2266
|
-
const nextData = JSON.parse(
|
|
2267
|
-
(doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
|
|
2424
|
+
const parsed = parseRemoteComponentDocument(
|
|
2425
|
+
doc,
|
|
2426
|
+
this.name ?? "__vercel_remote_component",
|
|
2427
|
+
url ?? new URL(window.location.href)
|
|
2268
2428
|
);
|
|
2269
|
-
const
|
|
2429
|
+
const {
|
|
2430
|
+
component,
|
|
2431
|
+
name: resolvedName,
|
|
2432
|
+
isRemoteComponent,
|
|
2433
|
+
metadata: parsedMetadata,
|
|
2434
|
+
nextData,
|
|
2435
|
+
rsc,
|
|
2436
|
+
remoteShared
|
|
2437
|
+
} = parsed;
|
|
2270
2438
|
if (nextData && nextData.buildId === "development" && !this.reactRoot) {
|
|
2271
2439
|
this.fouc = document.createElement("style");
|
|
2272
2440
|
this.fouc.textContent = `:host { display: none; }`;
|
|
2273
2441
|
this.root.appendChild(this.fouc);
|
|
2274
2442
|
}
|
|
2275
|
-
this.name =
|
|
2276
|
-
|
|
2277
|
-
this.bundle = component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || this.bundle;
|
|
2443
|
+
this.name = resolvedName;
|
|
2444
|
+
this.bundle = parsedMetadata.bundle;
|
|
2278
2445
|
if (url) {
|
|
2279
2446
|
const self2 = globalThis;
|
|
2280
2447
|
if (!self2.__remote_bundle_url__) {
|
|
@@ -2282,38 +2449,28 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2282
2449
|
}
|
|
2283
2450
|
self2.__remote_bundle_url__[this.bundle ?? "default"] = url;
|
|
2284
2451
|
}
|
|
2285
|
-
const
|
|
2286
|
-
|
|
2287
|
-
|
|
2452
|
+
const metadataEl = document.createElement("script");
|
|
2453
|
+
metadataEl.type = "application/json";
|
|
2454
|
+
metadataEl.setAttribute("data-remote-component", "");
|
|
2288
2455
|
const metadataObj = {
|
|
2289
2456
|
name: this.name,
|
|
2290
2457
|
bundle: this.bundle,
|
|
2291
|
-
route:
|
|
2292
|
-
runtime:
|
|
2458
|
+
route: parsedMetadata.route,
|
|
2459
|
+
runtime: parsedMetadata.runtime
|
|
2293
2460
|
};
|
|
2294
|
-
|
|
2461
|
+
metadataEl.textContent = JSON.stringify(metadataObj);
|
|
2295
2462
|
if (this.previousElementSibling?.getAttribute("data-remote-component") !== null) {
|
|
2296
2463
|
this.previousElementSibling?.remove();
|
|
2297
2464
|
}
|
|
2298
|
-
this.parentElement?.insertBefore(
|
|
2299
|
-
const remoteSharedEl = doc.querySelector(
|
|
2300
|
-
`#${this.name}_shared[data-remote-components-shared]`
|
|
2301
|
-
);
|
|
2302
|
-
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
2303
|
-
remoteSharedEl?.parentElement?.removeChild(remoteSharedEl);
|
|
2465
|
+
this.parentElement?.insertBefore(metadataEl, this);
|
|
2304
2466
|
if ("__remote_components_missing_shared__" in remoteShared) {
|
|
2305
2467
|
throw new RemoteComponentsError(
|
|
2306
2468
|
remoteShared.__remote_components_missing_shared__
|
|
2307
2469
|
);
|
|
2308
2470
|
}
|
|
2309
|
-
if (
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
);
|
|
2313
|
-
}
|
|
2314
|
-
if (this.prevIsRemoteComponent) {
|
|
2315
|
-
if (this.prevUrl) {
|
|
2316
|
-
const prevUrl = this.prevUrl;
|
|
2471
|
+
if (this.hostState.prevIsRemoteComponent) {
|
|
2472
|
+
if (this.hostState.prevUrl) {
|
|
2473
|
+
const prevUrl = this.hostState.prevUrl;
|
|
2317
2474
|
const self2 = globalThis;
|
|
2318
2475
|
if (self2.__remote_script_entrypoint_unmount__?.[prevUrl.href]) {
|
|
2319
2476
|
await Promise.all(
|
|
@@ -2338,26 +2495,21 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2338
2495
|
}
|
|
2339
2496
|
this.root.innerHTML = "";
|
|
2340
2497
|
}
|
|
2341
|
-
if (this.prevSrc !==
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
composed: true
|
|
2345
|
-
});
|
|
2346
|
-
Object.assign(changeEvent, {
|
|
2347
|
-
previousSrc: this.prevSrc,
|
|
2498
|
+
if (this.hostState.prevSrc !== void 0) {
|
|
2499
|
+
this.dispatchLifecycleEvent("change", {
|
|
2500
|
+
previousSrc: this.hostState.prevSrc,
|
|
2348
2501
|
nextSrc: src,
|
|
2349
|
-
previousName: this.prevName,
|
|
2502
|
+
previousName: this.hostState.prevName,
|
|
2350
2503
|
nextName: this.name
|
|
2351
2504
|
});
|
|
2352
|
-
this.dispatchEvent(changeEvent);
|
|
2353
2505
|
}
|
|
2354
|
-
this.prevUrl = url ?? new URL(window.location.href);
|
|
2355
|
-
this.prevIsRemoteComponent = isRemoteComponent;
|
|
2356
|
-
this.prevSrc = src;
|
|
2357
|
-
this.prevName = this.name;
|
|
2506
|
+
this.hostState.prevUrl = url ?? new URL(window.location.href);
|
|
2507
|
+
this.hostState.prevIsRemoteComponent = isRemoteComponent;
|
|
2508
|
+
this.hostState.prevSrc = src;
|
|
2509
|
+
this.hostState.prevName = this.name;
|
|
2358
2510
|
const removable = Array.from(this.childNodes);
|
|
2359
2511
|
const links = doc.querySelectorAll("link[href]");
|
|
2360
|
-
const remoteComponentSrc = this.
|
|
2512
|
+
const remoteComponentSrc = this.src ? String(this.src) : null;
|
|
2361
2513
|
const doAttachStyles = () => attachStyles({
|
|
2362
2514
|
doc,
|
|
2363
2515
|
component,
|
|
@@ -2431,7 +2583,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2431
2583
|
}
|
|
2432
2584
|
this.fallbackSlot?.remove();
|
|
2433
2585
|
const applyReset = () => {
|
|
2434
|
-
if (this.
|
|
2586
|
+
if (this.reset && !this.root?.querySelector("link[data-remote-components-reset]")) {
|
|
2435
2587
|
const allInitial = document.createElement("link");
|
|
2436
2588
|
allInitial.setAttribute("data-remote-components-reset", "");
|
|
2437
2589
|
const css = `:host { all: initial; }`;
|
|
@@ -2449,7 +2601,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2449
2601
|
allInitial.removeAttribute("onload");
|
|
2450
2602
|
};
|
|
2451
2603
|
this.root?.prepend(allInitial);
|
|
2452
|
-
} else if (this.
|
|
2604
|
+
} else if (!this.reset && this.root?.querySelector("link[data-remote-components-reset]")) {
|
|
2453
2605
|
this.root.querySelector("link[data-remote-components-reset]")?.remove();
|
|
2454
2606
|
}
|
|
2455
2607
|
};
|
|
@@ -2557,14 +2709,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2557
2709
|
});
|
|
2558
2710
|
}
|
|
2559
2711
|
if (isCurrentLoad()) {
|
|
2560
|
-
this.
|
|
2712
|
+
this.hostState.stage = "loaded";
|
|
2561
2713
|
}
|
|
2562
|
-
|
|
2563
|
-
bubbles: true,
|
|
2564
|
-
composed: true
|
|
2565
|
-
});
|
|
2566
|
-
Object.assign(loadEvent, { src: this.getAttribute("src") });
|
|
2567
|
-
this.dispatchEvent(loadEvent);
|
|
2714
|
+
this.dispatchLifecycleEvent("load", { src: this.src });
|
|
2568
2715
|
}, [initial, name]);
|
|
2569
2716
|
return Component;
|
|
2570
2717
|
};
|
|
@@ -2598,7 +2745,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2598
2745
|
} else if (nextData) {
|
|
2599
2746
|
const { Component, App } = nextClientPagesLoader2(
|
|
2600
2747
|
this.bundle ?? "default",
|
|
2601
|
-
nextData.page,
|
|
2748
|
+
nextData.page ?? "/",
|
|
2602
2749
|
this.root
|
|
2603
2750
|
);
|
|
2604
2751
|
if (Component) {
|
|
@@ -2612,16 +2759,11 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2612
2759
|
});
|
|
2613
2760
|
}
|
|
2614
2761
|
if (isCurrentLoad()) {
|
|
2615
|
-
remoteComponent.
|
|
2762
|
+
remoteComponent.hostState.stage = "loaded";
|
|
2616
2763
|
}
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
composed: true
|
|
2620
|
-
});
|
|
2621
|
-
Object.assign(loadEvent, {
|
|
2622
|
-
src: remoteComponent.getAttribute("src")
|
|
2764
|
+
remoteComponent.dispatchLifecycleEvent("load", {
|
|
2765
|
+
src: remoteComponent.src
|
|
2623
2766
|
});
|
|
2624
|
-
remoteComponent.dispatchEvent(loadEvent);
|
|
2625
2767
|
}, [initial, remoteComponent]);
|
|
2626
2768
|
return NextApp ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NextApp, { Component: NextComponent, ...nextData.props }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NextComponent, { ...nextData.props });
|
|
2627
2769
|
})(App, Component, this);
|
|
@@ -2631,7 +2773,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2631
2773
|
root.render(/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RemoteComponentFromNext, { initial: false }));
|
|
2632
2774
|
doCleanup();
|
|
2633
2775
|
if (isCurrentLoad()) {
|
|
2634
|
-
this.
|
|
2776
|
+
this.hostState.stage = "loaded";
|
|
2635
2777
|
}
|
|
2636
2778
|
});
|
|
2637
2779
|
return;
|
|
@@ -2662,22 +2804,12 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2662
2804
|
}
|
|
2663
2805
|
})
|
|
2664
2806
|
);
|
|
2665
|
-
|
|
2666
|
-
bubbles: true,
|
|
2667
|
-
composed: true
|
|
2668
|
-
});
|
|
2669
|
-
Object.assign(loadEvent, { src: this.getAttribute("src") });
|
|
2670
|
-
this.dispatchEvent(loadEvent);
|
|
2807
|
+
this.dispatchLifecycleEvent("load", { src: this.src });
|
|
2671
2808
|
} else {
|
|
2672
|
-
|
|
2673
|
-
bubbles: true,
|
|
2674
|
-
composed: true
|
|
2675
|
-
});
|
|
2676
|
-
Object.assign(loadEvent, { src: this.getAttribute("src") });
|
|
2677
|
-
this.dispatchEvent(loadEvent);
|
|
2809
|
+
this.dispatchLifecycleEvent("load", { src: this.src });
|
|
2678
2810
|
}
|
|
2679
2811
|
if (isCurrentLoad()) {
|
|
2680
|
-
this.
|
|
2812
|
+
this.hostState.stage = "loaded";
|
|
2681
2813
|
}
|
|
2682
2814
|
}
|
|
2683
2815
|
}
|