remote-components 0.0.51 → 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-1838f572.d.ts → component-loader-21865da3.d.ts} +142 -16
- package/dist/host-config-58cdccea.d.ts +87 -0
- package/dist/html/host.cjs +589 -377
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.d.ts +2 -0
- package/dist/html/host.js +588 -377
- package/dist/html/host.js.map +1 -1
- package/dist/html/remote.cjs +65 -57
- package/dist/html/remote.cjs.map +1 -1
- package/dist/html/remote.js +65 -57
- package/dist/html/remote.js.map +1 -1
- package/dist/internal/next/host/app-router-client.cjs +21 -10
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +36 -14
- package/dist/internal/next/host/app-router-client.js +21 -10
- 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/react/context.cjs +43 -0
- package/dist/internal/react/context.cjs.map +1 -0
- package/dist/internal/react/context.d.ts +20 -0
- package/dist/internal/react/context.js +18 -0
- package/dist/internal/react/context.js.map +1 -0
- package/dist/internal/react/hooks/use-resolve-client-url.cjs +39 -0
- package/dist/internal/react/hooks/use-resolve-client-url.cjs.map +1 -0
- package/dist/internal/react/hooks/use-resolve-client-url.d.ts +5 -0
- package/dist/internal/react/hooks/use-resolve-client-url.js +15 -0
- package/dist/internal/react/hooks/use-resolve-client-url.js.map +1 -0
- package/dist/internal/shared/client/apply-origin.cjs +10 -5
- package/dist/internal/shared/client/apply-origin.cjs.map +1 -1
- package/dist/internal/shared/client/apply-origin.d.ts +3 -1
- package/dist/internal/shared/client/apply-origin.js +10 -5
- package/dist/internal/shared/client/apply-origin.js.map +1 -1
- package/dist/internal/shared/client/default-resolve-client-url.cjs +32 -0
- package/dist/internal/shared/client/default-resolve-client-url.cjs.map +1 -0
- package/dist/internal/shared/client/default-resolve-client-url.d.ts +5 -0
- package/dist/internal/shared/client/default-resolve-client-url.js +10 -0
- package/dist/internal/shared/client/default-resolve-client-url.js.map +1 -0
- package/dist/internal/shared/client/protected-rc-fallback.cjs +11 -2
- package/dist/internal/shared/client/protected-rc-fallback.cjs.map +1 -1
- package/dist/internal/shared/client/protected-rc-fallback.d.ts +2 -1
- package/dist/internal/shared/client/protected-rc-fallback.js +9 -1
- package/dist/internal/shared/client/protected-rc-fallback.js.map +1 -1
- package/dist/internal/shared/client/proxy-through-host.cjs +65 -0
- package/dist/internal/shared/client/proxy-through-host.cjs.map +1 -0
- package/dist/internal/shared/client/proxy-through-host.d.ts +62 -0
- package/dist/internal/shared/client/proxy-through-host.js +40 -0
- package/dist/internal/shared/client/proxy-through-host.js.map +1 -0
- package/dist/internal/shared/client/remote-component.cjs +121 -137
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +7 -5
- package/dist/internal/shared/client/remote-component.js +120 -137
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/constants.cjs +3 -0
- package/dist/internal/shared/constants.cjs.map +1 -1
- package/dist/internal/shared/constants.d.ts +2 -1
- package/dist/internal/shared/constants.js +2 -0
- package/dist/internal/shared/constants.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/error.cjs +70 -0
- package/dist/internal/shared/error.cjs.map +1 -1
- package/dist/internal/shared/error.d.ts +3 -1
- package/dist/internal/shared/error.js +71 -0
- package/dist/internal/shared/error.js.map +1 -1
- 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.cjs +7 -2
- package/dist/internal/shared/ssr/fetch-with-hooks.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.d.ts +1 -1
- package/dist/internal/shared/ssr/fetch-with-hooks.js +7 -2
- package/dist/internal/shared/ssr/fetch-with-hooks.js.map +1 -1
- package/dist/internal/shared/utils/logger.cjs +26 -10
- package/dist/internal/shared/utils/logger.cjs.map +1 -1
- package/dist/internal/shared/utils/logger.d.ts +6 -1
- package/dist/internal/shared/utils/logger.js +24 -9
- package/dist/internal/shared/utils/logger.js.map +1 -1
- package/dist/next/config.cjs +2 -2
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +2 -2
- package/dist/next/config.js.map +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 +467 -298
- package/dist/next/host/client/index.cjs.map +1 -1
- package/dist/next/host/client/index.d.ts +3 -1
- package/dist/next/host/client/index.js +445 -277
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-client.cjs +15 -2
- package/dist/next/host/pages-router-client.cjs.map +1 -1
- package/dist/next/host/pages-router-client.d.ts +14 -26
- package/dist/next/host/pages-router-client.js +15 -2
- package/dist/next/host/pages-router-client.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs +2 -0
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.d.ts +17 -31
- package/dist/next/host/pages-router-server.js +2 -0
- 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/proxy.cjs +33 -6
- package/dist/next/proxy.cjs.map +1 -1
- package/dist/next/proxy.js +33 -6
- package/dist/next/proxy.js.map +1 -1
- package/dist/next/remote/server.d.ts +4 -0
- package/dist/proxy-through-host-a676a522.d.ts +52 -0
- package/dist/react/index.cjs +486 -298
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +27 -40
- package/dist/react/index.js +463 -277
- package/dist/react/index.js.map +1 -1
- package/dist/shared/host/proxy.cjs +32 -6
- package/dist/shared/host/proxy.cjs.map +1 -1
- package/dist/shared/host/proxy.js +36 -7
- package/dist/shared/host/proxy.js.map +1 -1
- package/dist/{types-cbe44b51.d.ts → types-2b26a246.d.ts} +23 -6
- package/package.json +1 -1
- package/dist/internal/shared/client/fetch-with-protected-rc-fallback.cjs +0 -65
- package/dist/internal/shared/client/fetch-with-protected-rc-fallback.cjs.map +0 -1
- package/dist/internal/shared/client/fetch-with-protected-rc-fallback.d.ts +0 -13
- package/dist/internal/shared/client/fetch-with-protected-rc-fallback.js +0 -41
- package/dist/internal/shared/client/fetch-with-protected-rc-fallback.js.map +0 -1
package/dist/html/host.js
CHANGED
|
@@ -8,6 +8,51 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
// src/shared/constants.ts
|
|
12
|
+
var RC_PROTECTED_REMOTE_FETCH_PATHNAME, CORS_DOCS_URL;
|
|
13
|
+
var init_constants = __esm({
|
|
14
|
+
"src/shared/constants.ts"() {
|
|
15
|
+
"use strict";
|
|
16
|
+
RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
17
|
+
CORS_DOCS_URL = "https://vercel.com/docs/remote-components/concepts/cors-external-urls#accessing-cross-site-protected-remote-components";
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// src/shared/client/protected-rc-fallback.ts
|
|
22
|
+
function generateProtectedRcFallbackSrc(url) {
|
|
23
|
+
return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
|
|
24
|
+
}
|
|
25
|
+
function isProxiedUrl(url) {
|
|
26
|
+
try {
|
|
27
|
+
return new URL(url, location.href).pathname === RC_PROTECTED_REMOTE_FETCH_PATHNAME;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
var init_protected_rc_fallback = __esm({
|
|
33
|
+
"src/shared/client/protected-rc-fallback.ts"() {
|
|
34
|
+
"use strict";
|
|
35
|
+
init_constants();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// src/shared/utils/abort.ts
|
|
40
|
+
function isAbortError(error) {
|
|
41
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (error !== null && typeof error === "object" && "name" in error && error.name === "AbortError" && "message" in error && typeof error.message === "string") {
|
|
45
|
+
const e = error;
|
|
46
|
+
return typeof e.code === "number" || e.constructor?.name === "DOMException";
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
var init_abort = __esm({
|
|
51
|
+
"src/shared/utils/abort.ts"() {
|
|
52
|
+
"use strict";
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
11
56
|
// src/shared/error.ts
|
|
12
57
|
function multipleRemoteComponentsError(url) {
|
|
13
58
|
return new RemoteComponentsError(
|
|
@@ -20,10 +65,76 @@ function failedToFetchRemoteComponentError(url, { status, statusText }, help = "
|
|
|
20
65
|
{ cause: new Error(`${status} ${statusText}`) }
|
|
21
66
|
);
|
|
22
67
|
}
|
|
68
|
+
async function errorFromFailedFetch(originalUrl, resolvedUrl, res) {
|
|
69
|
+
const isProxied = isProxiedUrl(resolvedUrl.href);
|
|
70
|
+
if (isProxied && res) {
|
|
71
|
+
const body = await res.text().catch(() => "");
|
|
72
|
+
return failedProxyFetchError(
|
|
73
|
+
originalUrl,
|
|
74
|
+
resolvedUrl.href,
|
|
75
|
+
res.status,
|
|
76
|
+
body
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const fallback = failedToFetchRemoteComponentError(
|
|
80
|
+
originalUrl,
|
|
81
|
+
res ?? { status: 0, statusText: "No Response" }
|
|
82
|
+
);
|
|
83
|
+
if (!res)
|
|
84
|
+
return fallback;
|
|
85
|
+
try {
|
|
86
|
+
const body = await res.text();
|
|
87
|
+
const parser = new DOMParser();
|
|
88
|
+
const doc = parser.parseFromString(body, "text/html");
|
|
89
|
+
const errorTemplate = doc.querySelector(
|
|
90
|
+
"template[data-next-error-message]"
|
|
91
|
+
);
|
|
92
|
+
const errorMessage = errorTemplate?.getAttribute("data-next-error-message");
|
|
93
|
+
if (errorMessage) {
|
|
94
|
+
const error = new RemoteComponentsError(errorMessage);
|
|
95
|
+
const errorStack = errorTemplate?.getAttribute("data-next-error-stack");
|
|
96
|
+
if (errorStack) {
|
|
97
|
+
error.stack = errorStack;
|
|
98
|
+
}
|
|
99
|
+
return error;
|
|
100
|
+
}
|
|
101
|
+
} catch (parseError) {
|
|
102
|
+
if (isAbortError(parseError))
|
|
103
|
+
throw parseError;
|
|
104
|
+
}
|
|
105
|
+
return fallback;
|
|
106
|
+
}
|
|
107
|
+
function failedProxyFetchError(originalUrl, proxyUrl, status, responseBody) {
|
|
108
|
+
if (status === 404) {
|
|
109
|
+
return new RemoteComponentsError(
|
|
110
|
+
`Could not proxy the request to "${originalUrl}" \u2014 the proxy endpoint "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" returned 404.
|
|
111
|
+
|
|
112
|
+
The host server needs middleware or a route that handles "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}".
|
|
113
|
+
|
|
114
|
+
Proxying requires two pieces:
|
|
115
|
+
1. resolveClientUrl={proxyClientRequestsThroughHost} on <RemoteComponent>
|
|
116
|
+
2. Middleware or a route for "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" on the host server
|
|
117
|
+
|
|
118
|
+
Docs: ${CORS_DOCS_URL}`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (status === 403) {
|
|
122
|
+
const detail = responseBody ? ` ${responseBody}` : "";
|
|
123
|
+
return new RemoteComponentsError(
|
|
124
|
+
`Proxied request to "${proxyUrl}" was forbidden.${detail} See: ${CORS_DOCS_URL}`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return new RemoteComponentsError(
|
|
128
|
+
`Proxied request for "${originalUrl}" via "${proxyUrl}" failed with status ${status}. See: ${CORS_DOCS_URL}`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
23
131
|
var RemoteComponentsError;
|
|
24
132
|
var init_error = __esm({
|
|
25
133
|
"src/shared/error.ts"() {
|
|
26
134
|
"use strict";
|
|
135
|
+
init_protected_rc_fallback();
|
|
136
|
+
init_constants();
|
|
137
|
+
init_abort();
|
|
27
138
|
RemoteComponentsError = class extends Error {
|
|
28
139
|
code = "REMOTE_COMPONENTS_ERROR";
|
|
29
140
|
constructor(message, options) {
|
|
@@ -34,15 +145,39 @@ var init_error = __esm({
|
|
|
34
145
|
}
|
|
35
146
|
});
|
|
36
147
|
|
|
148
|
+
// src/shared/utils/index.ts
|
|
149
|
+
function escapeString(str) {
|
|
150
|
+
return str.replace(/[^a-z0-9]/g, "_");
|
|
151
|
+
}
|
|
152
|
+
var init_utils = __esm({
|
|
153
|
+
"src/shared/utils/index.ts"() {
|
|
154
|
+
"use strict";
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// src/shared/client/const.ts
|
|
159
|
+
function getBundleKey(bundle) {
|
|
160
|
+
return escapeString(bundle);
|
|
161
|
+
}
|
|
162
|
+
var DEFAULT_ROUTE, RUNTIME_WEBPACK, RUNTIME_TURBOPACK, RUNTIME_SCRIPT, REMOTE_COMPONENT_REGEX;
|
|
163
|
+
var init_const = __esm({
|
|
164
|
+
"src/shared/client/const.ts"() {
|
|
165
|
+
"use strict";
|
|
166
|
+
init_utils();
|
|
167
|
+
DEFAULT_ROUTE = "/";
|
|
168
|
+
RUNTIME_WEBPACK = "webpack";
|
|
169
|
+
RUNTIME_TURBOPACK = "turbopack";
|
|
170
|
+
RUNTIME_SCRIPT = "script";
|
|
171
|
+
REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
37
175
|
// src/shared/utils/logger.ts
|
|
38
176
|
function logDebug(location2, message) {
|
|
39
177
|
if (DEBUG) {
|
|
40
178
|
console.debug(`[${PREFIX}:${location2}]: ${message}`);
|
|
41
179
|
}
|
|
42
180
|
}
|
|
43
|
-
function logInfo(location2, message) {
|
|
44
|
-
console.info(`[${PREFIX}:${location2}]: ${message}`);
|
|
45
|
-
}
|
|
46
181
|
function logWarn(location2, message) {
|
|
47
182
|
console.warn(`[${PREFIX}:${location2}]: ${message}`);
|
|
48
183
|
}
|
|
@@ -53,10 +188,24 @@ function logError(location2, message, cause) {
|
|
|
53
188
|
})
|
|
54
189
|
);
|
|
55
190
|
}
|
|
191
|
+
function warnCrossOriginFetchError(logLocation, url) {
|
|
192
|
+
try {
|
|
193
|
+
const parsed = typeof url === "string" ? new URL(url) : url;
|
|
194
|
+
if (typeof location === "undefined" || parsed.origin === location.origin) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
logWarn(
|
|
198
|
+
logLocation,
|
|
199
|
+
`Failed to fetch cross-origin resource "${parsed.href}". If this is a protected deployment, ensure withRemoteComponentsHost middleware is configured in your host and that the remote URL is included in allowedProxyUrls. See: ${CORS_DOCS_URL}`
|
|
200
|
+
);
|
|
201
|
+
} catch {
|
|
202
|
+
}
|
|
203
|
+
}
|
|
56
204
|
var PREFIX, DEBUG;
|
|
57
205
|
var init_logger = __esm({
|
|
58
206
|
"src/shared/utils/logger.ts"() {
|
|
59
207
|
"use strict";
|
|
208
|
+
init_constants();
|
|
60
209
|
init_error();
|
|
61
210
|
PREFIX = "remote-components";
|
|
62
211
|
DEBUG = typeof window !== "undefined" && localStorage.getItem("RC_DEBUG") === "true";
|
|
@@ -248,26 +397,6 @@ var init_shared_modules = __esm({
|
|
|
248
397
|
}
|
|
249
398
|
});
|
|
250
399
|
|
|
251
|
-
// src/shared/constants.ts
|
|
252
|
-
var RC_PROTECTED_REMOTE_FETCH_PATHNAME;
|
|
253
|
-
var init_constants = __esm({
|
|
254
|
-
"src/shared/constants.ts"() {
|
|
255
|
-
"use strict";
|
|
256
|
-
RC_PROTECTED_REMOTE_FETCH_PATHNAME = "/rc-fetch-protected-remote";
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
// src/shared/client/protected-rc-fallback.ts
|
|
261
|
-
function generateProtectedRcFallbackSrc(url) {
|
|
262
|
-
return `${RC_PROTECTED_REMOTE_FETCH_PATHNAME}?url=${encodeURIComponent(url)}`;
|
|
263
|
-
}
|
|
264
|
-
var init_protected_rc_fallback = __esm({
|
|
265
|
-
"src/shared/client/protected-rc-fallback.ts"() {
|
|
266
|
-
"use strict";
|
|
267
|
-
init_constants();
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
|
|
271
400
|
// src/shared/client/webpack-patterns.ts
|
|
272
401
|
var NEXT_BUNDLE_PATH_RE;
|
|
273
402
|
var init_webpack_patterns = __esm({
|
|
@@ -278,7 +407,7 @@ var init_webpack_patterns = __esm({
|
|
|
278
407
|
});
|
|
279
408
|
|
|
280
409
|
// src/shared/client/script-loader.ts
|
|
281
|
-
async function loadScripts(scripts) {
|
|
410
|
+
async function loadScripts(scripts, resolveClientUrl) {
|
|
282
411
|
await Promise.all(
|
|
283
412
|
scripts.map((script) => {
|
|
284
413
|
return new Promise((resolve, reject) => {
|
|
@@ -287,42 +416,29 @@ async function loadScripts(scripts) {
|
|
|
287
416
|
script.src.replace(NEXT_BUNDLE_PATH_RE, "/_next/"),
|
|
288
417
|
location.origin
|
|
289
418
|
).href;
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
"
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
} else {
|
|
310
|
-
logError(
|
|
311
|
-
"ScriptLoader",
|
|
312
|
-
`Failed to load fallback for <script src="${newSrc}"> for Remote Component.`
|
|
313
|
-
);
|
|
314
|
-
reject(
|
|
315
|
-
new RemoteComponentsError(
|
|
316
|
-
`Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
|
|
317
|
-
)
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
newScript.src = src;
|
|
322
|
-
newScript.async = true;
|
|
323
|
-
document.head.appendChild(newScript);
|
|
419
|
+
const resolvedSrc = resolveClientUrl?.(newSrc) ?? newSrc;
|
|
420
|
+
const newScript = document.createElement("script");
|
|
421
|
+
newScript.onload = () => resolve();
|
|
422
|
+
newScript.onerror = () => {
|
|
423
|
+
const isProxied = isProxiedUrl(resolvedSrc);
|
|
424
|
+
if (isProxied) {
|
|
425
|
+
reject(
|
|
426
|
+
new RemoteComponentsError(
|
|
427
|
+
`Failed to load script "${newSrc}" via proxy "${resolvedSrc}". Ensure withRemoteComponentsHost middleware is configured and "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" is in the matcher. See: ${CORS_DOCS_URL}`
|
|
428
|
+
)
|
|
429
|
+
);
|
|
430
|
+
} else {
|
|
431
|
+
warnCrossOriginFetchError("ScriptLoader", newSrc);
|
|
432
|
+
reject(
|
|
433
|
+
new RemoteComponentsError(
|
|
434
|
+
`Failed to load <script src="${newSrc}"> for Remote Component. Check the URL is correct.`
|
|
435
|
+
)
|
|
436
|
+
);
|
|
437
|
+
}
|
|
324
438
|
};
|
|
325
|
-
|
|
439
|
+
newScript.src = resolvedSrc;
|
|
440
|
+
newScript.async = true;
|
|
441
|
+
document.head.appendChild(newScript);
|
|
326
442
|
});
|
|
327
443
|
})
|
|
328
444
|
);
|
|
@@ -338,92 +454,6 @@ var init_script_loader = __esm({
|
|
|
338
454
|
}
|
|
339
455
|
});
|
|
340
456
|
|
|
341
|
-
// src/shared/utils/index.ts
|
|
342
|
-
function escapeString(str) {
|
|
343
|
-
return str.replace(/[^a-z0-9]/g, "_");
|
|
344
|
-
}
|
|
345
|
-
var init_utils = __esm({
|
|
346
|
-
"src/shared/utils/index.ts"() {
|
|
347
|
-
"use strict";
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
// src/shared/client/const.ts
|
|
352
|
-
function getBundleKey(bundle) {
|
|
353
|
-
return escapeString(bundle);
|
|
354
|
-
}
|
|
355
|
-
var RUNTIME_WEBPACK, RUNTIME_TURBOPACK, REMOTE_COMPONENT_REGEX;
|
|
356
|
-
var init_const = __esm({
|
|
357
|
-
"src/shared/client/const.ts"() {
|
|
358
|
-
"use strict";
|
|
359
|
-
init_utils();
|
|
360
|
-
RUNTIME_WEBPACK = "webpack";
|
|
361
|
-
RUNTIME_TURBOPACK = "turbopack";
|
|
362
|
-
REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
// src/shared/utils/abort.ts
|
|
367
|
-
function isAbortError(error) {
|
|
368
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
369
|
-
return true;
|
|
370
|
-
}
|
|
371
|
-
if (error !== null && typeof error === "object" && "name" in error && error.name === "AbortError" && "message" in error && typeof error.message === "string") {
|
|
372
|
-
const e = error;
|
|
373
|
-
return typeof e.code === "number" || e.constructor?.name === "DOMException";
|
|
374
|
-
}
|
|
375
|
-
return false;
|
|
376
|
-
}
|
|
377
|
-
var init_abort = __esm({
|
|
378
|
-
"src/shared/utils/abort.ts"() {
|
|
379
|
-
"use strict";
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
// src/shared/client/fetch-with-protected-rc-fallback.ts
|
|
384
|
-
async function fetchWithProtectedRcFallback(url, init) {
|
|
385
|
-
try {
|
|
386
|
-
const res = await fetch(url, init);
|
|
387
|
-
return res;
|
|
388
|
-
} catch (error) {
|
|
389
|
-
if (isAbortError(error)) {
|
|
390
|
-
throw error;
|
|
391
|
-
}
|
|
392
|
-
const parsedUrl = new URL(url);
|
|
393
|
-
if (typeof document === "object" && typeof document.location === "object" && document.location.origin !== parsedUrl.origin) {
|
|
394
|
-
logWarn(
|
|
395
|
-
"FetchRemoteComponent",
|
|
396
|
-
"Request failed due to CORS, attempting to fetch it via the withRemoteComponentsHost proxy."
|
|
397
|
-
);
|
|
398
|
-
const proxiedRes = await fetch(
|
|
399
|
-
generateProtectedRcFallbackSrc(parsedUrl.href),
|
|
400
|
-
init?.signal ? { signal: init.signal } : void 0
|
|
401
|
-
);
|
|
402
|
-
if (proxiedRes.status === 200) {
|
|
403
|
-
logInfo(
|
|
404
|
-
"FetchRemoteComponent",
|
|
405
|
-
`Successfully fetched ${parsedUrl.href} with fallback withRemoteComponentsHost proxy`
|
|
406
|
-
);
|
|
407
|
-
return proxiedRes;
|
|
408
|
-
} else {
|
|
409
|
-
logError(
|
|
410
|
-
"FetchRemoteComponent",
|
|
411
|
-
`Could not proxy remote: [response status ${proxiedRes.status}] ${await proxiedRes.text()}`
|
|
412
|
-
);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
throw error;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
var init_fetch_with_protected_rc_fallback = __esm({
|
|
419
|
-
"src/shared/client/fetch-with-protected-rc-fallback.ts"() {
|
|
420
|
-
"use strict";
|
|
421
|
-
init_protected_rc_fallback();
|
|
422
|
-
init_abort();
|
|
423
|
-
init_logger();
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
|
|
427
457
|
// src/shared/client/turbopack-patterns.ts
|
|
428
458
|
var REMOTE_SHARED_MARKER_RE, REMOTE_SHARED_ASSIGNMENT_RE, ASYNC_MODULE_LOADER_RE, ASYNC_MODULE_RESOLVE_RE, ASYNC_MODULE_ALL_RE, TURBOPACK_GLOBAL_RE;
|
|
429
459
|
var init_turbopack_patterns = __esm({
|
|
@@ -439,7 +469,7 @@ var init_turbopack_patterns = __esm({
|
|
|
439
469
|
});
|
|
440
470
|
|
|
441
471
|
// src/shared/client/chunk-loader.ts
|
|
442
|
-
function createChunkLoader(runtime) {
|
|
472
|
+
function createChunkLoader(runtime, resolveClientUrl) {
|
|
443
473
|
return function __turbopack_chunk_load__(chunkId, scriptBundle) {
|
|
444
474
|
logDebug("ChunkLoader", `Loading chunk: "${chunkId}"`);
|
|
445
475
|
const self = globalThis;
|
|
@@ -479,9 +509,10 @@ function createChunkLoader(runtime) {
|
|
|
479
509
|
logDebug("ChunkLoader", `Returning cached promise for: "${url}"`);
|
|
480
510
|
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
481
511
|
}
|
|
482
|
-
|
|
512
|
+
const resolvedUrl = resolveClientUrl?.(url) ?? url;
|
|
513
|
+
logDebug("ChunkLoader", `Fetching chunk from: "${resolvedUrl}"`);
|
|
483
514
|
self.__remote_components_turbopack_chunk_loader_promise__[url] = new Promise((resolve, reject) => {
|
|
484
|
-
|
|
515
|
+
fetch(resolvedUrl).then((res) => res.text()).then((code) => {
|
|
485
516
|
const hasTurbopack = TURBOPACK_GLOBAL_RE.test(code);
|
|
486
517
|
if (hasTurbopack) {
|
|
487
518
|
return handleTurbopackChunk(code, bundle ?? "", url);
|
|
@@ -494,7 +525,19 @@ function createChunkLoader(runtime) {
|
|
|
494
525
|
"ChunkLoader",
|
|
495
526
|
`First 500 chars of chunk: ${code.slice(0, 500)}`
|
|
496
527
|
);
|
|
497
|
-
}).then(resolve).catch(
|
|
528
|
+
}).then(resolve).catch((error) => {
|
|
529
|
+
const isProxied = isProxiedUrl(resolvedUrl);
|
|
530
|
+
if (isProxied) {
|
|
531
|
+
reject(
|
|
532
|
+
new RemoteComponentsError(
|
|
533
|
+
`Failed to load chunk "${url}" via proxy "${resolvedUrl}". Ensure withRemoteComponentsHost middleware is configured and "${RC_PROTECTED_REMOTE_FETCH_PATHNAME}" is in the matcher. See: ${CORS_DOCS_URL}`
|
|
534
|
+
)
|
|
535
|
+
);
|
|
536
|
+
} else {
|
|
537
|
+
warnCrossOriginFetchError("ChunkLoader", url);
|
|
538
|
+
reject(error);
|
|
539
|
+
}
|
|
540
|
+
});
|
|
498
541
|
});
|
|
499
542
|
return self.__remote_components_turbopack_chunk_loader_promise__[url];
|
|
500
543
|
};
|
|
@@ -639,10 +682,11 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
639
682
|
var init_chunk_loader = __esm({
|
|
640
683
|
"src/shared/client/chunk-loader.ts"() {
|
|
641
684
|
"use strict";
|
|
685
|
+
init_constants();
|
|
642
686
|
init_error();
|
|
643
687
|
init_logger();
|
|
644
688
|
init_const();
|
|
645
|
-
|
|
689
|
+
init_protected_rc_fallback();
|
|
646
690
|
init_turbopack_patterns();
|
|
647
691
|
}
|
|
648
692
|
});
|
|
@@ -1013,7 +1057,7 @@ var init_shared_modules2 = __esm({
|
|
|
1013
1057
|
});
|
|
1014
1058
|
|
|
1015
1059
|
// src/shared/client/webpack-adapter.ts
|
|
1016
|
-
async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}) {
|
|
1060
|
+
async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location.href), bundle, shared = {}, remoteShared = {}, resolveClientUrl) {
|
|
1017
1061
|
const self = globalThis;
|
|
1018
1062
|
if (!self.__remote_bundle_url__) {
|
|
1019
1063
|
self.__remote_bundle_url__ = {};
|
|
@@ -1025,7 +1069,7 @@ async function setupWebpackRuntime(runtime, scripts = [], url = new URL(location
|
|
|
1025
1069
|
self.__original_webpack_chunk_load__ = self.__webpack_chunk_load__;
|
|
1026
1070
|
self.__original_webpack_require__ = self.__webpack_require__;
|
|
1027
1071
|
}
|
|
1028
|
-
self.__webpack_chunk_load__ = createChunkLoader(runtime);
|
|
1072
|
+
self.__webpack_chunk_load__ = createChunkLoader(runtime, resolveClientUrl);
|
|
1029
1073
|
self.__webpack_require__ = createModuleRequire(runtime);
|
|
1030
1074
|
self.__webpack_require_type__ = runtime;
|
|
1031
1075
|
if (self.__remote_webpack_require__ && runtime === RUNTIME_TURBOPACK) {
|
|
@@ -1119,27 +1163,21 @@ var init_webpack_adapter = __esm({
|
|
|
1119
1163
|
});
|
|
1120
1164
|
|
|
1121
1165
|
// src/shared/client/static-loader.ts
|
|
1122
|
-
async function
|
|
1123
|
-
const
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
).href;
|
|
1127
|
-
const response = await fetch(proxyUrl);
|
|
1166
|
+
async function importViaCallback(absoluteSrc, resolveClientUrl) {
|
|
1167
|
+
const resolvedUrl = resolveClientUrl(absoluteSrc) ?? absoluteSrc;
|
|
1168
|
+
const fetchUrl = new URL(resolvedUrl, location.href).href;
|
|
1169
|
+
const response = await fetch(fetchUrl);
|
|
1128
1170
|
if (!response.ok)
|
|
1129
|
-
throw new Error(`
|
|
1130
|
-
logInfo(
|
|
1131
|
-
"StaticLoader",
|
|
1132
|
-
`Successfully loaded ${absoluteSrc} via protected RC proxy fallback.`
|
|
1133
|
-
);
|
|
1171
|
+
throw new Error(`Proxied fetch failed: ${response.status}`);
|
|
1134
1172
|
const content = (await response.text()).replace(/import\.meta\.url/g, JSON.stringify(absoluteSrc)).replace(
|
|
1135
1173
|
/\b(from|import)\s*(["'])(\.\.?\/[^"']+)\2/g,
|
|
1136
1174
|
(_, keyword, quote, relativePath) => {
|
|
1137
1175
|
const absoluteImportUrl = new URL(relativePath, absoluteSrc).href;
|
|
1138
|
-
const
|
|
1139
|
-
|
|
1176
|
+
const resolvedImportUrl = new URL(
|
|
1177
|
+
resolveClientUrl(absoluteImportUrl) ?? absoluteImportUrl,
|
|
1140
1178
|
location.href
|
|
1141
1179
|
).href;
|
|
1142
|
-
return `${keyword} ${quote}${
|
|
1180
|
+
return `${keyword} ${quote}${resolvedImportUrl}${quote}`;
|
|
1143
1181
|
}
|
|
1144
1182
|
);
|
|
1145
1183
|
const moduleBlobUrl = URL.createObjectURL(
|
|
@@ -1173,6 +1211,20 @@ async function importViaProxy(absoluteSrc) {
|
|
|
1173
1211
|
delete registry[absoluteSrc];
|
|
1174
1212
|
return mod;
|
|
1175
1213
|
}
|
|
1214
|
+
async function importDirectly(absoluteSrc) {
|
|
1215
|
+
try {
|
|
1216
|
+
return await import(
|
|
1217
|
+
/* @vite-ignore */
|
|
1218
|
+
/* webpackIgnore: true */
|
|
1219
|
+
absoluteSrc
|
|
1220
|
+
);
|
|
1221
|
+
} catch (importError) {
|
|
1222
|
+
if (!absoluteSrc.startsWith("blob:")) {
|
|
1223
|
+
warnCrossOriginFetchError("StaticLoader", absoluteSrc);
|
|
1224
|
+
}
|
|
1225
|
+
throw importError;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1176
1228
|
function resolveScriptSrc(script, url) {
|
|
1177
1229
|
const rawSrc = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
1178
1230
|
if (!rawSrc && script.textContent) {
|
|
@@ -1185,24 +1237,7 @@ function resolveScriptSrc(script, url) {
|
|
|
1185
1237
|
}
|
|
1186
1238
|
return rawSrc;
|
|
1187
1239
|
}
|
|
1188
|
-
async function
|
|
1189
|
-
try {
|
|
1190
|
-
return await import(
|
|
1191
|
-
/* @vite-ignore */
|
|
1192
|
-
/* webpackIgnore: true */
|
|
1193
|
-
absoluteSrc
|
|
1194
|
-
);
|
|
1195
|
-
} catch (importError) {
|
|
1196
|
-
if (absoluteSrc.startsWith("blob:"))
|
|
1197
|
-
throw importError;
|
|
1198
|
-
logWarn(
|
|
1199
|
-
"StaticLoader",
|
|
1200
|
-
`Direct import of ${absoluteSrc} failed, attempting via protected RC proxy fallback.`
|
|
1201
|
-
);
|
|
1202
|
-
return importViaProxy(absoluteSrc);
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
async function loadStaticRemoteComponent(scripts, url) {
|
|
1240
|
+
async function loadStaticRemoteComponent(scripts, url, resolveClientUrl) {
|
|
1206
1241
|
const self = globalThis;
|
|
1207
1242
|
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
1208
1243
|
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
@@ -1215,7 +1250,7 @@ async function loadStaticRemoteComponent(scripts, url) {
|
|
|
1215
1250
|
try {
|
|
1216
1251
|
const src = resolveScriptSrc(script, url);
|
|
1217
1252
|
const absoluteSrc = new URL(src, url).href;
|
|
1218
|
-
const mod = await
|
|
1253
|
+
const mod = resolveClientUrl ? await importViaCallback(absoluteSrc, resolveClientUrl) : await importDirectly(absoluteSrc);
|
|
1219
1254
|
if (src.startsWith("blob:")) {
|
|
1220
1255
|
URL.revokeObjectURL(src);
|
|
1221
1256
|
}
|
|
@@ -1280,7 +1315,6 @@ var init_static_loader = __esm({
|
|
|
1280
1315
|
"src/shared/client/static-loader.ts"() {
|
|
1281
1316
|
"use strict";
|
|
1282
1317
|
init_logger();
|
|
1283
|
-
init_protected_rc_fallback();
|
|
1284
1318
|
}
|
|
1285
1319
|
});
|
|
1286
1320
|
|
|
@@ -1492,7 +1526,7 @@ var webpack_exports = {};
|
|
|
1492
1526
|
__export(webpack_exports, {
|
|
1493
1527
|
webpackRuntime: () => webpackRuntime
|
|
1494
1528
|
});
|
|
1495
|
-
async function webpackRuntime(bundle, shared, remoteShared) {
|
|
1529
|
+
async function webpackRuntime(bundle, shared, remoteShared, resolveClientUrl) {
|
|
1496
1530
|
const self = globalThis;
|
|
1497
1531
|
if (!self.__DISABLE_WEBPACK_EXEC__) {
|
|
1498
1532
|
self.__DISABLE_WEBPACK_EXEC__ = {};
|
|
@@ -1535,7 +1569,7 @@ async function webpackRuntime(bundle, shared, remoteShared) {
|
|
|
1535
1569
|
}
|
|
1536
1570
|
];
|
|
1537
1571
|
});
|
|
1538
|
-
await loadScripts(scriptSrcs);
|
|
1572
|
+
await loadScripts(scriptSrcs, resolveClientUrl);
|
|
1539
1573
|
const hostShared = {
|
|
1540
1574
|
...sharedPolyfills(shared),
|
|
1541
1575
|
...self.__remote_component_host_shared_modules__,
|
|
@@ -1592,7 +1626,7 @@ var turbopack_exports = {};
|
|
|
1592
1626
|
__export(turbopack_exports, {
|
|
1593
1627
|
turbopackRuntime: () => turbopackRuntime
|
|
1594
1628
|
});
|
|
1595
|
-
async function turbopackRuntime(url, bundle, shared, remoteShared) {
|
|
1629
|
+
async function turbopackRuntime(url, bundle, shared, remoteShared, resolveClientUrl) {
|
|
1596
1630
|
const self = globalThis;
|
|
1597
1631
|
const hostShared = {
|
|
1598
1632
|
...sharedPolyfills(shared),
|
|
@@ -1606,7 +1640,8 @@ async function turbopackRuntime(url, bundle, shared, remoteShared) {
|
|
|
1606
1640
|
url,
|
|
1607
1641
|
bundle,
|
|
1608
1642
|
hostShared,
|
|
1609
|
-
remoteShared
|
|
1643
|
+
remoteShared,
|
|
1644
|
+
resolveClientUrl
|
|
1610
1645
|
);
|
|
1611
1646
|
const {
|
|
1612
1647
|
default: { createFromReadableStream }
|
|
@@ -1620,7 +1655,8 @@ async function turbopackRuntime(url, bundle, shared, remoteShared) {
|
|
|
1620
1655
|
url,
|
|
1621
1656
|
bundle,
|
|
1622
1657
|
hostShared,
|
|
1623
|
-
remoteShared
|
|
1658
|
+
remoteShared,
|
|
1659
|
+
resolveClientUrl
|
|
1624
1660
|
);
|
|
1625
1661
|
}
|
|
1626
1662
|
return {
|
|
@@ -1646,7 +1682,7 @@ var script_exports = {};
|
|
|
1646
1682
|
__export(script_exports, {
|
|
1647
1683
|
scriptRuntime: () => scriptRuntime
|
|
1648
1684
|
});
|
|
1649
|
-
function scriptRuntime() {
|
|
1685
|
+
function scriptRuntime(resolveClientUrl) {
|
|
1650
1686
|
const self = globalThis;
|
|
1651
1687
|
return {
|
|
1652
1688
|
self,
|
|
@@ -1656,7 +1692,7 @@ function scriptRuntime() {
|
|
|
1656
1692
|
Component: null,
|
|
1657
1693
|
App: null
|
|
1658
1694
|
}),
|
|
1659
|
-
preloadScripts: loadStaticRemoteComponent
|
|
1695
|
+
preloadScripts: (scripts, url) => loadStaticRemoteComponent(scripts, url, resolveClientUrl)
|
|
1660
1696
|
};
|
|
1661
1697
|
}
|
|
1662
1698
|
var init_script = __esm({
|
|
@@ -1682,7 +1718,7 @@ var tagNames = [
|
|
|
1682
1718
|
"script",
|
|
1683
1719
|
"link"
|
|
1684
1720
|
];
|
|
1685
|
-
function applyOriginToNodes(doc, url) {
|
|
1721
|
+
function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
1686
1722
|
if (url.origin !== location.origin) {
|
|
1687
1723
|
const nodes = doc.querySelectorAll(
|
|
1688
1724
|
tagNames.map(
|
|
@@ -1691,12 +1727,15 @@ function applyOriginToNodes(doc, url) {
|
|
|
1691
1727
|
);
|
|
1692
1728
|
nodes.forEach((node) => {
|
|
1693
1729
|
if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
|
|
1694
|
-
|
|
1730
|
+
const absoluteSrc = new URL(node.getAttribute("src") ?? "/", url).href;
|
|
1731
|
+
const isScript = node.tagName.toLowerCase() === "script";
|
|
1732
|
+
node.src = isScript ? absoluteSrc : resolveClientUrl?.(absoluteSrc) ?? absoluteSrc;
|
|
1695
1733
|
}
|
|
1696
1734
|
if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
|
|
1735
|
+
const absoluteHref = new URL(node.getAttribute("href") ?? "/", url).href;
|
|
1697
1736
|
node.setAttribute(
|
|
1698
1737
|
"href",
|
|
1699
|
-
|
|
1738
|
+
resolveClientUrl?.(absoluteHref) ?? absoluteHref
|
|
1700
1739
|
);
|
|
1701
1740
|
}
|
|
1702
1741
|
if (node.hasAttribute("srcset")) {
|
|
@@ -1705,7 +1744,8 @@ function applyOriginToNodes(doc, url) {
|
|
|
1705
1744
|
if (!urlPart)
|
|
1706
1745
|
return entry;
|
|
1707
1746
|
const absoluteUrl = new URL(urlPart, url).href;
|
|
1708
|
-
|
|
1747
|
+
const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
|
|
1748
|
+
return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
|
|
1709
1749
|
}).join(", ");
|
|
1710
1750
|
if (srcSet) {
|
|
1711
1751
|
node.setAttribute("srcset", srcSet);
|
|
@@ -1717,7 +1757,8 @@ function applyOriginToNodes(doc, url) {
|
|
|
1717
1757
|
if (!urlPart)
|
|
1718
1758
|
return entry;
|
|
1719
1759
|
const absoluteUrl = new URL(urlPart, url).href;
|
|
1720
|
-
|
|
1760
|
+
const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
|
|
1761
|
+
return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
|
|
1721
1762
|
}).join(", ");
|
|
1722
1763
|
if (srcSet) {
|
|
1723
1764
|
node.setAttribute("imagesrcset", srcSet);
|
|
@@ -1727,6 +1768,144 @@ function applyOriginToNodes(doc, url) {
|
|
|
1727
1768
|
}
|
|
1728
1769
|
}
|
|
1729
1770
|
|
|
1771
|
+
// src/shared/client/proxy-through-host.ts
|
|
1772
|
+
init_protected_rc_fallback();
|
|
1773
|
+
function withRemoteSrc(resolveClientUrl, remoteSrc) {
|
|
1774
|
+
const remoteOrigin = parseOrigin(remoteSrc);
|
|
1775
|
+
return (url) => {
|
|
1776
|
+
const urlOrigin = parseOrigin(url);
|
|
1777
|
+
if (remoteOrigin && urlOrigin && urlOrigin !== remoteOrigin) {
|
|
1778
|
+
return void 0;
|
|
1779
|
+
}
|
|
1780
|
+
return resolveClientUrl(remoteSrc, url);
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
function parseOrigin(url) {
|
|
1784
|
+
try {
|
|
1785
|
+
return new URL(url).origin;
|
|
1786
|
+
} catch {
|
|
1787
|
+
return void 0;
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
var proxyClientRequestsThroughHost = (remoteSrc, url) => {
|
|
1791
|
+
if (typeof location === "undefined") {
|
|
1792
|
+
return void 0;
|
|
1793
|
+
}
|
|
1794
|
+
const remoteOrigin = new URL(remoteSrc, location.href).origin;
|
|
1795
|
+
if (remoteOrigin === location.origin) {
|
|
1796
|
+
return void 0;
|
|
1797
|
+
}
|
|
1798
|
+
try {
|
|
1799
|
+
const parsed = new URL(url, location.href);
|
|
1800
|
+
if (parsed.origin === remoteOrigin) {
|
|
1801
|
+
return generateProtectedRcFallbackSrc(url);
|
|
1802
|
+
}
|
|
1803
|
+
} catch {
|
|
1804
|
+
}
|
|
1805
|
+
return void 0;
|
|
1806
|
+
};
|
|
1807
|
+
|
|
1808
|
+
// src/shared/client/default-resolve-client-url.ts
|
|
1809
|
+
function bindResolveClientUrl(prop, remoteSrc) {
|
|
1810
|
+
return prop ? withRemoteSrc(prop, remoteSrc) : void 0;
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
// src/shared/client/parse-remote-html.ts
|
|
1814
|
+
init_error();
|
|
1815
|
+
init_const();
|
|
1816
|
+
function validateSingleComponent(doc, name, url) {
|
|
1817
|
+
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}"]`)) {
|
|
1818
|
+
throw multipleRemoteComponentsError(url);
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
function findComponentElement(doc, name) {
|
|
1822
|
+
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])");
|
|
1823
|
+
}
|
|
1824
|
+
function parseNextData(doc) {
|
|
1825
|
+
return JSON.parse(
|
|
1826
|
+
(doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1829
|
+
function resolveComponentName(component, nextData, fallbackName) {
|
|
1830
|
+
const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
|
|
1831
|
+
const name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component?.getAttribute("name") || (nextData ? "__next" : fallbackName);
|
|
1832
|
+
return { name, isRemoteComponent };
|
|
1833
|
+
}
|
|
1834
|
+
function extractComponentMetadata(component, nextData, name, url) {
|
|
1835
|
+
return {
|
|
1836
|
+
name,
|
|
1837
|
+
bundle: component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || "default",
|
|
1838
|
+
route: component?.getAttribute("data-route") ?? nextData?.page ?? (url.pathname || DEFAULT_ROUTE),
|
|
1839
|
+
runtime: component?.getAttribute("data-runtime") ?? (nextData?.props.__REMOTE_COMPONENT__?.runtime || RUNTIME_SCRIPT)
|
|
1840
|
+
};
|
|
1841
|
+
}
|
|
1842
|
+
function extractRemoteShared(doc, name, nextData) {
|
|
1843
|
+
const remoteSharedEl = doc.querySelector(
|
|
1844
|
+
`#${name}_shared[data-remote-components-shared]`
|
|
1845
|
+
);
|
|
1846
|
+
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
1847
|
+
remoteSharedEl?.remove();
|
|
1848
|
+
return remoteShared;
|
|
1849
|
+
}
|
|
1850
|
+
function validateComponentFound(component, rsc, nextData, isRemoteComponent, url, name) {
|
|
1851
|
+
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
1852
|
+
throw new RemoteComponentsError(
|
|
1853
|
+
`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>?`
|
|
1854
|
+
);
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
function extractLinks(doc, component) {
|
|
1858
|
+
return Array.from(doc.querySelectorAll("link[href]")).filter(
|
|
1859
|
+
(link) => !component.contains(link)
|
|
1860
|
+
);
|
|
1861
|
+
}
|
|
1862
|
+
function extractScripts(doc, component, isRemoteComponent) {
|
|
1863
|
+
return Array.from(
|
|
1864
|
+
(isRemoteComponent ? component : doc).querySelectorAll(
|
|
1865
|
+
"script[src],script[data-src]"
|
|
1866
|
+
)
|
|
1867
|
+
);
|
|
1868
|
+
}
|
|
1869
|
+
function parseRemoteComponentDocument(doc, name, url) {
|
|
1870
|
+
validateSingleComponent(doc, name, url.href);
|
|
1871
|
+
const component = findComponentElement(doc, name);
|
|
1872
|
+
const nextData = parseNextData(doc);
|
|
1873
|
+
const { name: resolvedName, isRemoteComponent } = resolveComponentName(
|
|
1874
|
+
component,
|
|
1875
|
+
nextData,
|
|
1876
|
+
name
|
|
1877
|
+
);
|
|
1878
|
+
const rsc = doc.querySelector(`#${resolvedName}_rsc`);
|
|
1879
|
+
const metadata = extractComponentMetadata(
|
|
1880
|
+
component,
|
|
1881
|
+
nextData,
|
|
1882
|
+
resolvedName,
|
|
1883
|
+
url
|
|
1884
|
+
);
|
|
1885
|
+
const remoteShared = extractRemoteShared(doc, resolvedName, nextData);
|
|
1886
|
+
validateComponentFound(
|
|
1887
|
+
component,
|
|
1888
|
+
rsc,
|
|
1889
|
+
nextData,
|
|
1890
|
+
isRemoteComponent,
|
|
1891
|
+
url.href,
|
|
1892
|
+
resolvedName
|
|
1893
|
+
);
|
|
1894
|
+
const links = extractLinks(doc, component);
|
|
1895
|
+
const scripts = extractScripts(doc, component, isRemoteComponent);
|
|
1896
|
+
return {
|
|
1897
|
+
component,
|
|
1898
|
+
name: resolvedName,
|
|
1899
|
+
isRemoteComponent,
|
|
1900
|
+
metadata,
|
|
1901
|
+
nextData,
|
|
1902
|
+
rsc,
|
|
1903
|
+
remoteShared,
|
|
1904
|
+
links,
|
|
1905
|
+
scripts
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1730
1909
|
// src/shared/client/remote-component.ts
|
|
1731
1910
|
init_error();
|
|
1732
1911
|
|
|
@@ -1817,11 +1996,37 @@ init_script_loader();
|
|
|
1817
1996
|
init_static_loader();
|
|
1818
1997
|
init_webpack_adapter();
|
|
1819
1998
|
|
|
1999
|
+
// src/shared/contract/host-state.ts
|
|
2000
|
+
function createHostState() {
|
|
2001
|
+
return {
|
|
2002
|
+
stage: "idle",
|
|
2003
|
+
prevSrc: void 0,
|
|
2004
|
+
prevUrl: void 0,
|
|
2005
|
+
prevName: void 0,
|
|
2006
|
+
prevIsRemoteComponent: false,
|
|
2007
|
+
abortController: void 0
|
|
2008
|
+
};
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
// src/shared/contract/resolve-name-from-src.ts
|
|
2012
|
+
function resolveNameFromSrc(src, defaultName) {
|
|
2013
|
+
if (!src) {
|
|
2014
|
+
return defaultName;
|
|
2015
|
+
}
|
|
2016
|
+
const hash = typeof src === "string" ? src : src.hash;
|
|
2017
|
+
const hashIndex = hash.indexOf("#");
|
|
2018
|
+
if (hashIndex < 0) {
|
|
2019
|
+
return defaultName;
|
|
2020
|
+
}
|
|
2021
|
+
const name = hash.slice(hashIndex + 1);
|
|
2022
|
+
return name || defaultName;
|
|
2023
|
+
}
|
|
2024
|
+
|
|
1820
2025
|
// src/html/host/index.tsx
|
|
1821
2026
|
init_error();
|
|
1822
2027
|
|
|
1823
2028
|
// src/shared/ssr/fetch-with-hooks.ts
|
|
1824
|
-
|
|
2029
|
+
init_logger();
|
|
1825
2030
|
|
|
1826
2031
|
// src/shared/ssr/fetch-headers.ts
|
|
1827
2032
|
function remoteFetchHeaders() {
|
|
@@ -1859,7 +2064,12 @@ async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
|
1859
2064
|
};
|
|
1860
2065
|
let res = await onRequest?.(url, init, hookOptions);
|
|
1861
2066
|
if (!res) {
|
|
1862
|
-
|
|
2067
|
+
try {
|
|
2068
|
+
res = await fetch(url, init);
|
|
2069
|
+
} catch (error) {
|
|
2070
|
+
warnCrossOriginFetchError("FetchRemoteComponent", url);
|
|
2071
|
+
throw error;
|
|
2072
|
+
}
|
|
1863
2073
|
}
|
|
1864
2074
|
const transformedRes = await onResponse?.(url, res, hookOptions);
|
|
1865
2075
|
if (transformedRes) {
|
|
@@ -1868,6 +2078,15 @@ async function fetchWithHooks(url, additionalInit, options = {}) {
|
|
|
1868
2078
|
return res;
|
|
1869
2079
|
}
|
|
1870
2080
|
|
|
2081
|
+
// src/shared/ssr/get-client-or-server-url.ts
|
|
2082
|
+
function getClientOrServerUrl(src, serverFallback) {
|
|
2083
|
+
const fallback = typeof location !== "undefined" ? location.href : serverFallback;
|
|
2084
|
+
if (!src) {
|
|
2085
|
+
return new URL(fallback);
|
|
2086
|
+
}
|
|
2087
|
+
return typeof src === "string" ? new URL(src, fallback) : src;
|
|
2088
|
+
}
|
|
2089
|
+
|
|
1871
2090
|
// src/html/host/index.tsx
|
|
1872
2091
|
init_utils();
|
|
1873
2092
|
init_abort();
|
|
@@ -1882,7 +2101,8 @@ async function attachStyles({
|
|
|
1882
2101
|
signal,
|
|
1883
2102
|
baseUrl,
|
|
1884
2103
|
remoteComponentSrc,
|
|
1885
|
-
root
|
|
2104
|
+
root,
|
|
2105
|
+
resolveClientUrl
|
|
1886
2106
|
}) {
|
|
1887
2107
|
const appendedLinks = [];
|
|
1888
2108
|
let abortReject = null;
|
|
@@ -1917,9 +2137,13 @@ async function attachStyles({
|
|
|
1917
2137
|
});
|
|
1918
2138
|
for (const attr of link.attributes) {
|
|
1919
2139
|
if (attr.name === "href") {
|
|
2140
|
+
const absoluteHref = new URL(
|
|
2141
|
+
attr.value,
|
|
2142
|
+
baseUrl ?? location.origin
|
|
2143
|
+
).href;
|
|
1920
2144
|
newLink.setAttribute(
|
|
1921
2145
|
attr.name,
|
|
1922
|
-
|
|
2146
|
+
resolveClientUrl?.(absoluteHref) ?? absoluteHref
|
|
1923
2147
|
);
|
|
1924
2148
|
} else {
|
|
1925
2149
|
newLink.setAttribute(attr.name, attr.value);
|
|
@@ -1953,7 +2177,7 @@ async function attachStyles({
|
|
|
1953
2177
|
|
|
1954
2178
|
// src/html/host/runtime/index.ts
|
|
1955
2179
|
init_error();
|
|
1956
|
-
async function getRuntime(type, url, bundle, shared, remoteShared) {
|
|
2180
|
+
async function getRuntime(type, url, bundle, shared, remoteShared, resolveClientUrl) {
|
|
1957
2181
|
if (typeof globalThis.process === "undefined") {
|
|
1958
2182
|
globalThis.process = {
|
|
1959
2183
|
env: {}
|
|
@@ -1961,13 +2185,24 @@ async function getRuntime(type, url, bundle, shared, remoteShared) {
|
|
|
1961
2185
|
}
|
|
1962
2186
|
if (type === "webpack") {
|
|
1963
2187
|
const { webpackRuntime: webpackRuntime2 } = await Promise.resolve().then(() => (init_webpack(), webpack_exports));
|
|
1964
|
-
return webpackRuntime2(
|
|
2188
|
+
return webpackRuntime2(
|
|
2189
|
+
bundle ?? "default",
|
|
2190
|
+
shared,
|
|
2191
|
+
remoteShared,
|
|
2192
|
+
resolveClientUrl
|
|
2193
|
+
);
|
|
1965
2194
|
} else if (type === "turbopack") {
|
|
1966
2195
|
const { turbopackRuntime: turbopackRuntime2 } = await Promise.resolve().then(() => (init_turbopack(), turbopack_exports));
|
|
1967
|
-
return turbopackRuntime2(
|
|
2196
|
+
return turbopackRuntime2(
|
|
2197
|
+
url,
|
|
2198
|
+
bundle,
|
|
2199
|
+
shared,
|
|
2200
|
+
remoteShared,
|
|
2201
|
+
resolveClientUrl
|
|
2202
|
+
);
|
|
1968
2203
|
} else if (type === "script") {
|
|
1969
2204
|
const { scriptRuntime: scriptRuntime2 } = await Promise.resolve().then(() => (init_script(), script_exports));
|
|
1970
|
-
return scriptRuntime2();
|
|
2205
|
+
return scriptRuntime2(resolveClientUrl);
|
|
1971
2206
|
}
|
|
1972
2207
|
throw new RemoteComponentsError(
|
|
1973
2208
|
`Remote Components runtime "${type}" is not supported. Supported runtimes are "webpack", "turbopack", and "script".`
|
|
@@ -1983,41 +2218,76 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1983
2218
|
fallbackSlot;
|
|
1984
2219
|
__next = null;
|
|
1985
2220
|
fouc = null;
|
|
1986
|
-
|
|
1987
|
-
prevIsRemoteComponent = false;
|
|
1988
|
-
prevUrl;
|
|
1989
|
-
prevSrc = null;
|
|
1990
|
-
prevName;
|
|
2221
|
+
hostState = createHostState();
|
|
1991
2222
|
root = null;
|
|
1992
2223
|
reactRoot;
|
|
1993
2224
|
onRequest;
|
|
1994
2225
|
onResponse;
|
|
1995
|
-
|
|
1996
|
-
|
|
2226
|
+
resolveClientUrl;
|
|
2227
|
+
// -- HostConfig property accessors (attribute-reflected) --
|
|
2228
|
+
get src() {
|
|
2229
|
+
return this.getAttribute("src") ?? void 0;
|
|
2230
|
+
}
|
|
2231
|
+
set src(value) {
|
|
2232
|
+
if (value == null) {
|
|
2233
|
+
this.removeAttribute("src");
|
|
2234
|
+
} else {
|
|
2235
|
+
this.setAttribute("src", String(value));
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
/** Always `true` — the HTML host always isolates via Shadow DOM. */
|
|
2239
|
+
get isolate() {
|
|
2240
|
+
return true;
|
|
2241
|
+
}
|
|
2242
|
+
get mode() {
|
|
2243
|
+
const attr = this.getAttribute("mode");
|
|
2244
|
+
return attr === "closed" ? "closed" : "open";
|
|
2245
|
+
}
|
|
2246
|
+
set mode(value) {
|
|
2247
|
+
if (value) {
|
|
2248
|
+
this.setAttribute("mode", value);
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
get reset() {
|
|
2252
|
+
return this.getAttribute("reset") !== null;
|
|
2253
|
+
}
|
|
2254
|
+
set reset(value) {
|
|
2255
|
+
if (value) {
|
|
2256
|
+
this.setAttribute("reset", "");
|
|
2257
|
+
} else {
|
|
2258
|
+
this.removeAttribute("reset");
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
get credentials() {
|
|
2262
|
+
return this.getAttribute("credentials") || "same-origin";
|
|
2263
|
+
}
|
|
2264
|
+
set credentials(value) {
|
|
2265
|
+
if (value) {
|
|
2266
|
+
this.setAttribute("credentials", value);
|
|
2267
|
+
} else {
|
|
2268
|
+
this.removeAttribute("credentials");
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
1997
2271
|
static get observedAttributes() {
|
|
1998
2272
|
return ["src", "name", "mode"];
|
|
1999
2273
|
}
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2274
|
+
dispatchLifecycleEvent(type, detail) {
|
|
2275
|
+
const event = new Event(type, { bubbles: true, composed: true });
|
|
2276
|
+
if (detail) {
|
|
2277
|
+
Object.assign(event, detail);
|
|
2278
|
+
}
|
|
2279
|
+
this.dispatchEvent(event);
|
|
2280
|
+
}
|
|
2003
2281
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
2004
2282
|
if ((name === "src" || name === "name") && oldValue !== newValue) {
|
|
2005
|
-
if (this.
|
|
2283
|
+
if (this.src) {
|
|
2006
2284
|
this.load().catch((e) => {
|
|
2007
2285
|
if (isAbortError(e)) {
|
|
2008
2286
|
return;
|
|
2009
2287
|
}
|
|
2010
2288
|
logError("HtmlHost", "Error loading remote component.", e);
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
composed: true
|
|
2014
|
-
});
|
|
2015
|
-
Object.assign(errorEvent, {
|
|
2016
|
-
error: e,
|
|
2017
|
-
src: this.getAttribute("src")
|
|
2018
|
-
});
|
|
2019
|
-
this.dispatchEvent(errorEvent);
|
|
2020
|
-
this.isLoading = false;
|
|
2289
|
+
this.dispatchLifecycleEvent("error", { error: e, src: this.src });
|
|
2290
|
+
this.hostState.stage = "error";
|
|
2021
2291
|
});
|
|
2022
2292
|
}
|
|
2023
2293
|
} else if (name === "mode" && oldValue !== newValue && this.root) {
|
|
@@ -2033,15 +2303,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2033
2303
|
return;
|
|
2034
2304
|
}
|
|
2035
2305
|
logError("HtmlHost", "Error reloading remote component.", e);
|
|
2036
|
-
|
|
2037
|
-
bubbles: true,
|
|
2038
|
-
composed: true
|
|
2039
|
-
});
|
|
2040
|
-
Object.assign(errorEvent, {
|
|
2041
|
-
error: e,
|
|
2042
|
-
src: this.getAttribute("src")
|
|
2043
|
-
});
|
|
2044
|
-
this.dispatchEvent(errorEvent);
|
|
2306
|
+
this.dispatchLifecycleEvent("error", { error: e, src: this.src });
|
|
2045
2307
|
});
|
|
2046
2308
|
}
|
|
2047
2309
|
}
|
|
@@ -2051,9 +2313,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2051
2313
|
resolve(void 0);
|
|
2052
2314
|
});
|
|
2053
2315
|
});
|
|
2054
|
-
if (this.
|
|
2055
|
-
this.abortController?.abort();
|
|
2056
|
-
this.
|
|
2316
|
+
if (this.hostState.stage === "loading") {
|
|
2317
|
+
this.hostState.abortController?.abort();
|
|
2318
|
+
this.hostState.stage = "idle";
|
|
2057
2319
|
if (this.root && !this.reactRoot) {
|
|
2058
2320
|
this.root.innerHTML = "";
|
|
2059
2321
|
this.fouc = null;
|
|
@@ -2063,29 +2325,24 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2063
2325
|
}
|
|
2064
2326
|
if (!this.root) {
|
|
2065
2327
|
this.root = this.attachShadow({
|
|
2066
|
-
mode: this.
|
|
2328
|
+
mode: this.mode === "closed" ? "closed" : "open"
|
|
2067
2329
|
});
|
|
2068
2330
|
this.fallbackSlot = document.createElement("slot");
|
|
2069
2331
|
this.root.appendChild(this.fallbackSlot);
|
|
2070
2332
|
}
|
|
2071
2333
|
this.name = this.getAttribute("name") || "__vercel_remote_component";
|
|
2072
2334
|
this.bundle = "default";
|
|
2073
|
-
this.
|
|
2074
|
-
const src = this.
|
|
2075
|
-
this.abortController = new AbortController();
|
|
2076
|
-
const signal = this.abortController.signal;
|
|
2077
|
-
const isCurrentLoad = () => !signal.aborted && this.
|
|
2335
|
+
this.hostState.stage = "loading";
|
|
2336
|
+
const src = this.src;
|
|
2337
|
+
this.hostState.abortController = new AbortController();
|
|
2338
|
+
const signal = this.hostState.abortController.signal;
|
|
2339
|
+
const isCurrentLoad = () => !signal.aborted && this.src === src;
|
|
2078
2340
|
const abandonLoad = () => {
|
|
2079
|
-
if (this.abortController?.signal === signal && this.
|
|
2080
|
-
this.
|
|
2341
|
+
if (this.hostState.abortController?.signal === signal && this.hostState.stage === "loading") {
|
|
2342
|
+
this.hostState.stage = "idle";
|
|
2081
2343
|
}
|
|
2082
2344
|
};
|
|
2083
|
-
|
|
2084
|
-
bubbles: true,
|
|
2085
|
-
composed: true
|
|
2086
|
-
});
|
|
2087
|
-
Object.assign(beforeLoadEvent, { src });
|
|
2088
|
-
this.dispatchEvent(beforeLoadEvent);
|
|
2345
|
+
this.dispatchLifecycleEvent("beforeload", { src });
|
|
2089
2346
|
const remoteComponentChild = this.querySelector("div#__REMOTE_COMPONENT__") || this.querySelector("div[data-bundle][data-route]");
|
|
2090
2347
|
if (!src && !remoteComponentChild) {
|
|
2091
2348
|
throw new RemoteComponentsError('"src" attribute is required');
|
|
@@ -2093,21 +2350,27 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2093
2350
|
let url = null;
|
|
2094
2351
|
let html = this.innerHTML;
|
|
2095
2352
|
if (src) {
|
|
2096
|
-
url =
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2353
|
+
url = getClientOrServerUrl(src, window.location.href);
|
|
2354
|
+
this.name = resolveNameFromSrc(
|
|
2355
|
+
src,
|
|
2356
|
+
this.name ?? "__vercel_remote_component"
|
|
2357
|
+
);
|
|
2100
2358
|
}
|
|
2359
|
+
const resolveClientUrl = url ? bindResolveClientUrl(this.resolveClientUrl, url.href) : void 0;
|
|
2101
2360
|
if (!remoteComponentChild && url) {
|
|
2102
2361
|
const fetchInit = {
|
|
2103
|
-
credentials: this.
|
|
2362
|
+
credentials: this.credentials || "same-origin"
|
|
2104
2363
|
};
|
|
2364
|
+
const resolvedUrl = new URL(
|
|
2365
|
+
resolveClientUrl?.(url.href) ?? url.href,
|
|
2366
|
+
window.location.href
|
|
2367
|
+
);
|
|
2105
2368
|
let res;
|
|
2106
2369
|
try {
|
|
2107
|
-
res = await fetchWithHooks(
|
|
2370
|
+
res = await fetchWithHooks(resolvedUrl, fetchInit, {
|
|
2108
2371
|
onRequest: this.onRequest,
|
|
2109
2372
|
onResponse: this.onResponse,
|
|
2110
|
-
abortController: this.abortController
|
|
2373
|
+
abortController: this.hostState.abortController
|
|
2111
2374
|
});
|
|
2112
2375
|
} catch (e) {
|
|
2113
2376
|
if (isAbortError(e)) {
|
|
@@ -2116,34 +2379,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2116
2379
|
throw e;
|
|
2117
2380
|
}
|
|
2118
2381
|
if (!res || !res.ok) {
|
|
2119
|
-
|
|
2120
|
-
url.href,
|
|
2121
|
-
res ?? new Response(null, { status: 0 })
|
|
2122
|
-
);
|
|
2123
|
-
try {
|
|
2124
|
-
const body = res ? await res.text() : "";
|
|
2125
|
-
const parser2 = new DOMParser();
|
|
2126
|
-
const doc2 = parser2.parseFromString(body, "text/html");
|
|
2127
|
-
const errorTemplate = doc2.querySelector(
|
|
2128
|
-
"template[data-next-error-message]"
|
|
2129
|
-
);
|
|
2130
|
-
const errorMessage = errorTemplate?.getAttribute(
|
|
2131
|
-
"data-next-error-message"
|
|
2132
|
-
);
|
|
2133
|
-
const errorStack = errorTemplate?.getAttribute(
|
|
2134
|
-
"data-next-error-stack"
|
|
2135
|
-
);
|
|
2136
|
-
if (errorMessage) {
|
|
2137
|
-
error = new RemoteComponentsError(errorMessage);
|
|
2138
|
-
if (errorStack) {
|
|
2139
|
-
error.stack = errorStack;
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
} catch (parseError) {
|
|
2143
|
-
if (isAbortError(parseError))
|
|
2144
|
-
throw parseError;
|
|
2145
|
-
}
|
|
2146
|
-
throw error;
|
|
2382
|
+
throw await errorFromFailedFetch(url.href, resolvedUrl, res);
|
|
2147
2383
|
}
|
|
2148
2384
|
try {
|
|
2149
2385
|
html = await res.text();
|
|
@@ -2159,29 +2395,27 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2159
2395
|
}
|
|
2160
2396
|
const parser = new DOMParser();
|
|
2161
2397
|
const doc = parser.parseFromString(html, "text/html");
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
url?.href ?? (this.getAttribute("src") || "unknown")
|
|
2167
|
-
);
|
|
2168
|
-
}
|
|
2169
|
-
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
|
|
2170
|
-
doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
|
|
2171
|
-
doc.querySelector("div#__next") ?? // fallback to a <remote-component> element
|
|
2172
|
-
doc.querySelector(`remote-component[name="${this.name}"]:not([src])`) ?? doc.querySelector("remote-component:not([src])");
|
|
2173
|
-
const nextData = JSON.parse(
|
|
2174
|
-
(doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
|
|
2398
|
+
const parsed = parseRemoteComponentDocument(
|
|
2399
|
+
doc,
|
|
2400
|
+
this.name ?? "__vercel_remote_component",
|
|
2401
|
+
url ?? new URL(window.location.href)
|
|
2175
2402
|
);
|
|
2176
|
-
const
|
|
2403
|
+
const {
|
|
2404
|
+
component,
|
|
2405
|
+
name: resolvedName,
|
|
2406
|
+
isRemoteComponent,
|
|
2407
|
+
metadata: parsedMetadata,
|
|
2408
|
+
nextData,
|
|
2409
|
+
rsc,
|
|
2410
|
+
remoteShared
|
|
2411
|
+
} = parsed;
|
|
2177
2412
|
if (nextData && nextData.buildId === "development" && !this.reactRoot) {
|
|
2178
2413
|
this.fouc = document.createElement("style");
|
|
2179
2414
|
this.fouc.textContent = `:host { display: none; }`;
|
|
2180
2415
|
this.root.appendChild(this.fouc);
|
|
2181
2416
|
}
|
|
2182
|
-
this.name =
|
|
2183
|
-
|
|
2184
|
-
this.bundle = component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || this.bundle;
|
|
2417
|
+
this.name = resolvedName;
|
|
2418
|
+
this.bundle = parsedMetadata.bundle;
|
|
2185
2419
|
if (url) {
|
|
2186
2420
|
const self2 = globalThis;
|
|
2187
2421
|
if (!self2.__remote_bundle_url__) {
|
|
@@ -2189,38 +2423,28 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2189
2423
|
}
|
|
2190
2424
|
self2.__remote_bundle_url__[this.bundle ?? "default"] = url;
|
|
2191
2425
|
}
|
|
2192
|
-
const
|
|
2193
|
-
|
|
2194
|
-
|
|
2426
|
+
const metadataEl = document.createElement("script");
|
|
2427
|
+
metadataEl.type = "application/json";
|
|
2428
|
+
metadataEl.setAttribute("data-remote-component", "");
|
|
2195
2429
|
const metadataObj = {
|
|
2196
2430
|
name: this.name,
|
|
2197
2431
|
bundle: this.bundle,
|
|
2198
|
-
route:
|
|
2199
|
-
runtime:
|
|
2432
|
+
route: parsedMetadata.route,
|
|
2433
|
+
runtime: parsedMetadata.runtime
|
|
2200
2434
|
};
|
|
2201
|
-
|
|
2435
|
+
metadataEl.textContent = JSON.stringify(metadataObj);
|
|
2202
2436
|
if (this.previousElementSibling?.getAttribute("data-remote-component") !== null) {
|
|
2203
2437
|
this.previousElementSibling?.remove();
|
|
2204
2438
|
}
|
|
2205
|
-
this.parentElement?.insertBefore(
|
|
2206
|
-
const remoteSharedEl = doc.querySelector(
|
|
2207
|
-
`#${this.name}_shared[data-remote-components-shared]`
|
|
2208
|
-
);
|
|
2209
|
-
const remoteShared = nextData?.props.__REMOTE_COMPONENT__?.shared ?? (JSON.parse(remoteSharedEl?.textContent ?? "{}") ?? {});
|
|
2210
|
-
remoteSharedEl?.parentElement?.removeChild(remoteSharedEl);
|
|
2439
|
+
this.parentElement?.insertBefore(metadataEl, this);
|
|
2211
2440
|
if ("__remote_components_missing_shared__" in remoteShared) {
|
|
2212
2441
|
throw new RemoteComponentsError(
|
|
2213
2442
|
remoteShared.__remote_components_missing_shared__
|
|
2214
2443
|
);
|
|
2215
2444
|
}
|
|
2216
|
-
if (
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
);
|
|
2220
|
-
}
|
|
2221
|
-
if (this.prevIsRemoteComponent) {
|
|
2222
|
-
if (this.prevUrl) {
|
|
2223
|
-
const prevUrl = this.prevUrl;
|
|
2445
|
+
if (this.hostState.prevIsRemoteComponent) {
|
|
2446
|
+
if (this.hostState.prevUrl) {
|
|
2447
|
+
const prevUrl = this.hostState.prevUrl;
|
|
2224
2448
|
const self2 = globalThis;
|
|
2225
2449
|
if (self2.__remote_script_entrypoint_unmount__?.[prevUrl.href]) {
|
|
2226
2450
|
await Promise.all(
|
|
@@ -2245,26 +2469,21 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2245
2469
|
}
|
|
2246
2470
|
this.root.innerHTML = "";
|
|
2247
2471
|
}
|
|
2248
|
-
if (this.prevSrc !==
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
composed: true
|
|
2252
|
-
});
|
|
2253
|
-
Object.assign(changeEvent, {
|
|
2254
|
-
previousSrc: this.prevSrc,
|
|
2472
|
+
if (this.hostState.prevSrc !== void 0) {
|
|
2473
|
+
this.dispatchLifecycleEvent("change", {
|
|
2474
|
+
previousSrc: this.hostState.prevSrc,
|
|
2255
2475
|
nextSrc: src,
|
|
2256
|
-
previousName: this.prevName,
|
|
2476
|
+
previousName: this.hostState.prevName,
|
|
2257
2477
|
nextName: this.name
|
|
2258
2478
|
});
|
|
2259
|
-
this.dispatchEvent(changeEvent);
|
|
2260
2479
|
}
|
|
2261
|
-
this.prevUrl = url ?? new URL(location.href);
|
|
2262
|
-
this.prevIsRemoteComponent = isRemoteComponent;
|
|
2263
|
-
this.prevSrc = src;
|
|
2264
|
-
this.prevName = this.name;
|
|
2480
|
+
this.hostState.prevUrl = url ?? new URL(window.location.href);
|
|
2481
|
+
this.hostState.prevIsRemoteComponent = isRemoteComponent;
|
|
2482
|
+
this.hostState.prevSrc = src;
|
|
2483
|
+
this.hostState.prevName = this.name;
|
|
2265
2484
|
const removable = Array.from(this.childNodes);
|
|
2266
2485
|
const links = doc.querySelectorAll("link[href]");
|
|
2267
|
-
const remoteComponentSrc = this.
|
|
2486
|
+
const remoteComponentSrc = this.src ? String(this.src) : null;
|
|
2268
2487
|
const doAttachStyles = () => attachStyles({
|
|
2269
2488
|
doc,
|
|
2270
2489
|
component,
|
|
@@ -2273,7 +2492,8 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2273
2492
|
// Effects run after load, no abort needed
|
|
2274
2493
|
baseUrl: url?.href,
|
|
2275
2494
|
remoteComponentSrc,
|
|
2276
|
-
root: this.root ?? null
|
|
2495
|
+
root: this.root ?? null,
|
|
2496
|
+
resolveClientUrl
|
|
2277
2497
|
});
|
|
2278
2498
|
if (!this.reactRoot) {
|
|
2279
2499
|
await attachStyles({
|
|
@@ -2283,22 +2503,31 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2283
2503
|
signal,
|
|
2284
2504
|
baseUrl: url?.href,
|
|
2285
2505
|
remoteComponentSrc,
|
|
2286
|
-
root: this.root
|
|
2506
|
+
root: this.root,
|
|
2507
|
+
resolveClientUrl
|
|
2287
2508
|
});
|
|
2288
2509
|
if (!isCurrentLoad()) {
|
|
2289
2510
|
return abandonLoad();
|
|
2290
2511
|
}
|
|
2291
2512
|
}
|
|
2292
|
-
applyOriginToNodes(
|
|
2513
|
+
applyOriginToNodes(
|
|
2514
|
+
doc,
|
|
2515
|
+
url ?? new URL(window.location.href),
|
|
2516
|
+
resolveClientUrl
|
|
2517
|
+
);
|
|
2293
2518
|
if (!this.reactRoot) {
|
|
2294
2519
|
Array.from(component.children).forEach((el) => {
|
|
2295
2520
|
if (!isRemoteComponent && el.tagName.toLowerCase() === "script") {
|
|
2296
2521
|
const newScript = document.createElement("script");
|
|
2297
2522
|
for (const attr of el.attributes) {
|
|
2298
2523
|
if (attr.name === "src") {
|
|
2524
|
+
const absoluteSrc = new URL(
|
|
2525
|
+
attr.value,
|
|
2526
|
+
url ?? window.location.origin
|
|
2527
|
+
).href;
|
|
2299
2528
|
newScript.setAttribute(
|
|
2300
2529
|
attr.name,
|
|
2301
|
-
|
|
2530
|
+
resolveClientUrl?.(absoluteSrc) ?? absoluteSrc
|
|
2302
2531
|
);
|
|
2303
2532
|
} else {
|
|
2304
2533
|
newScript.setAttribute(attr.name, attr.value);
|
|
@@ -2328,7 +2557,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2328
2557
|
}
|
|
2329
2558
|
this.fallbackSlot?.remove();
|
|
2330
2559
|
const applyReset = () => {
|
|
2331
|
-
if (this.
|
|
2560
|
+
if (this.reset && !this.root?.querySelector("link[data-remote-components-reset]")) {
|
|
2332
2561
|
const allInitial = document.createElement("link");
|
|
2333
2562
|
allInitial.setAttribute("data-remote-components-reset", "");
|
|
2334
2563
|
const css = `:host { all: initial; }`;
|
|
@@ -2346,7 +2575,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2346
2575
|
allInitial.removeAttribute("onload");
|
|
2347
2576
|
};
|
|
2348
2577
|
this.root?.prepend(allInitial);
|
|
2349
|
-
} else if (this.
|
|
2578
|
+
} else if (!this.reset && this.root?.querySelector("link[data-remote-components-reset]")) {
|
|
2350
2579
|
this.root.querySelector("link[data-remote-components-reset]")?.remove();
|
|
2351
2580
|
}
|
|
2352
2581
|
};
|
|
@@ -2360,7 +2589,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2360
2589
|
preloadScripts
|
|
2361
2590
|
} = await getRuntime(
|
|
2362
2591
|
metadataObj.runtime,
|
|
2363
|
-
url ?? new URL(location.href),
|
|
2592
|
+
url ?? new URL(window.location.href),
|
|
2364
2593
|
this.bundle,
|
|
2365
2594
|
{
|
|
2366
2595
|
react: async () => (await import("react")).default,
|
|
@@ -2369,7 +2598,8 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2369
2598
|
"react-dom": async () => (await import("react-dom")).default,
|
|
2370
2599
|
"react-dom/client": async () => (await import("react-dom/client")).default
|
|
2371
2600
|
},
|
|
2372
|
-
remoteShared
|
|
2601
|
+
remoteShared,
|
|
2602
|
+
resolveClientUrl
|
|
2373
2603
|
);
|
|
2374
2604
|
if (!isCurrentLoad()) {
|
|
2375
2605
|
return abandonLoad();
|
|
@@ -2453,14 +2683,9 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2453
2683
|
});
|
|
2454
2684
|
}
|
|
2455
2685
|
if (isCurrentLoad()) {
|
|
2456
|
-
this.
|
|
2686
|
+
this.hostState.stage = "loaded";
|
|
2457
2687
|
}
|
|
2458
|
-
|
|
2459
|
-
bubbles: true,
|
|
2460
|
-
composed: true
|
|
2461
|
-
});
|
|
2462
|
-
Object.assign(loadEvent, { src: this.getAttribute("src") });
|
|
2463
|
-
this.dispatchEvent(loadEvent);
|
|
2688
|
+
this.dispatchLifecycleEvent("load", { src: this.src });
|
|
2464
2689
|
}, [initial, name]);
|
|
2465
2690
|
return Component;
|
|
2466
2691
|
};
|
|
@@ -2494,7 +2719,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2494
2719
|
} else if (nextData) {
|
|
2495
2720
|
const { Component, App } = nextClientPagesLoader2(
|
|
2496
2721
|
this.bundle ?? "default",
|
|
2497
|
-
nextData.page,
|
|
2722
|
+
nextData.page ?? "/",
|
|
2498
2723
|
this.root
|
|
2499
2724
|
);
|
|
2500
2725
|
if (Component) {
|
|
@@ -2508,16 +2733,11 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2508
2733
|
});
|
|
2509
2734
|
}
|
|
2510
2735
|
if (isCurrentLoad()) {
|
|
2511
|
-
remoteComponent.
|
|
2736
|
+
remoteComponent.hostState.stage = "loaded";
|
|
2512
2737
|
}
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
composed: true
|
|
2516
|
-
});
|
|
2517
|
-
Object.assign(loadEvent, {
|
|
2518
|
-
src: remoteComponent.getAttribute("src")
|
|
2738
|
+
remoteComponent.dispatchLifecycleEvent("load", {
|
|
2739
|
+
src: remoteComponent.src
|
|
2519
2740
|
});
|
|
2520
|
-
remoteComponent.dispatchEvent(loadEvent);
|
|
2521
2741
|
}, [initial, remoteComponent]);
|
|
2522
2742
|
return NextApp ? /* @__PURE__ */ jsx2(NextApp, { Component: NextComponent, ...nextData.props }) : /* @__PURE__ */ jsx2(NextComponent, { ...nextData.props });
|
|
2523
2743
|
})(App, Component, this);
|
|
@@ -2527,7 +2747,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2527
2747
|
root.render(/* @__PURE__ */ jsx2(RemoteComponentFromNext, { initial: false }));
|
|
2528
2748
|
doCleanup();
|
|
2529
2749
|
if (isCurrentLoad()) {
|
|
2530
|
-
this.
|
|
2750
|
+
this.hostState.stage = "loaded";
|
|
2531
2751
|
}
|
|
2532
2752
|
});
|
|
2533
2753
|
return;
|
|
@@ -2558,22 +2778,12 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
2558
2778
|
}
|
|
2559
2779
|
})
|
|
2560
2780
|
);
|
|
2561
|
-
|
|
2562
|
-
bubbles: true,
|
|
2563
|
-
composed: true
|
|
2564
|
-
});
|
|
2565
|
-
Object.assign(loadEvent, { src: this.getAttribute("src") });
|
|
2566
|
-
this.dispatchEvent(loadEvent);
|
|
2781
|
+
this.dispatchLifecycleEvent("load", { src: this.src });
|
|
2567
2782
|
} else {
|
|
2568
|
-
|
|
2569
|
-
bubbles: true,
|
|
2570
|
-
composed: true
|
|
2571
|
-
});
|
|
2572
|
-
Object.assign(loadEvent, { src: this.getAttribute("src") });
|
|
2573
|
-
this.dispatchEvent(loadEvent);
|
|
2783
|
+
this.dispatchLifecycleEvent("load", { src: this.src });
|
|
2574
2784
|
}
|
|
2575
2785
|
if (isCurrentLoad()) {
|
|
2576
|
-
this.
|
|
2786
|
+
this.hostState.stage = "loaded";
|
|
2577
2787
|
}
|
|
2578
2788
|
}
|
|
2579
2789
|
}
|
|
@@ -2591,6 +2801,7 @@ function registerSharedModules(modules = {}) {
|
|
|
2591
2801
|
});
|
|
2592
2802
|
}
|
|
2593
2803
|
export {
|
|
2804
|
+
proxyClientRequestsThroughHost,
|
|
2594
2805
|
registerSharedModules
|
|
2595
2806
|
};
|
|
2596
2807
|
//# sourceMappingURL=host.js.map
|