remote-components 0.0.33 → 0.0.35
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-28ad0083.d.ts → component-loader-8951c052.d.ts} +6 -4
- package/dist/html/host.cjs +353 -129
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +353 -129
- package/dist/html/host.js.map +1 -1
- package/dist/html/remote.cjs +199 -0
- package/dist/html/remote.cjs.map +1 -0
- package/dist/html/remote.d.ts +2 -0
- package/dist/html/remote.js +198 -0
- package/dist/html/remote.js.map +1 -0
- package/dist/internal/next/host/app-router-client.cjs +60 -19
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.d.ts +3 -3
- package/dist/internal/next/host/app-router-client.js +65 -23
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
- package/dist/internal/next/host/app-router-compat.d.ts +1 -1
- package/dist/internal/next/host/app-router-compat.js.map +1 -1
- package/dist/internal/next/remote/render-server.cjs +1 -1
- package/dist/internal/next/remote/render-server.cjs.map +1 -1
- package/dist/internal/next/remote/render-server.js +1 -1
- package/dist/internal/next/remote/render-server.js.map +1 -1
- package/dist/internal/shared/client/polyfill.cjs.map +1 -1
- package/dist/internal/shared/client/polyfill.js.map +1 -1
- package/dist/internal/shared/client/remote-component.cjs +237 -133
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +29 -22
- package/dist/internal/shared/client/remote-component.js +235 -133
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/error.cjs +1 -1
- package/dist/internal/shared/error.cjs.map +1 -1
- package/dist/internal/shared/error.d.ts +1 -1
- package/dist/internal/shared/error.js +1 -1
- package/dist/internal/shared/error.js.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.cjs +24 -8
- package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.d.ts +1 -1
- package/dist/internal/shared/ssr/dom-flight.js +24 -8
- package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +8 -4
- package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.d.ts +2 -1
- package/dist/internal/shared/ssr/fetch-remote-component.js +9 -5
- package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
- package/dist/next/config.cjs +100 -86
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +100 -86
- package/dist/next/config.js.map +1 -1
- package/dist/next/host/app-router-server.cjs +1 -0
- package/dist/next/host/app-router-server.cjs.map +1 -1
- package/dist/next/host/app-router-server.js +2 -1
- package/dist/next/host/app-router-server.js.map +1 -1
- package/dist/next/host/client/index.cjs +1381 -1187
- 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 +682 -490
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs +4 -4
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.js +4 -4
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/{middleware.cjs → proxy.cjs} +24 -14
- package/dist/next/proxy.cjs.map +1 -0
- package/dist/next/proxy.d.ts +29 -0
- package/dist/next/{middleware.js → proxy.js} +21 -11
- package/dist/next/proxy.js.map +1 -0
- package/dist/react/index.cjs +201 -107
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +206 -112
- package/dist/react/index.js.map +1 -1
- package/dist/{types-7c207455.d.ts → types-4e7dea94.d.ts} +2 -1
- package/dist/{types-e4a3fa37.d.ts → types-cbf6c34f.d.ts} +2 -2
- package/package.json +22 -9
- package/dist/next/middleware.cjs.map +0 -1
- package/dist/next/middleware.d.ts +0 -29
- package/dist/next/middleware.js.map +0 -1
package/dist/html/host.cjs
CHANGED
|
@@ -30,38 +30,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
-
// src/shared/webpack/shared-modules.ts
|
|
34
|
-
function applySharedModules(bundle, resolve) {
|
|
35
|
-
const self = globalThis;
|
|
36
|
-
if (self.__remote_webpack_require__?.[bundle]) {
|
|
37
|
-
const modulePaths = Object.keys(
|
|
38
|
-
self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
|
|
39
|
-
);
|
|
40
|
-
for (const [key, value] of Object.entries(resolve)) {
|
|
41
|
-
let ids = modulePaths.filter((p) => p === key);
|
|
42
|
-
if (ids.length === 0) {
|
|
43
|
-
ids = modulePaths.filter((p) => p.includes(key));
|
|
44
|
-
}
|
|
45
|
-
for (let id of ids) {
|
|
46
|
-
const webpackBundle = self.__remote_webpack_require__[bundle];
|
|
47
|
-
if (webpackBundle.m) {
|
|
48
|
-
if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
|
|
49
|
-
id = `${self.__remote_webpack_module_map__[bundle][id]}`;
|
|
50
|
-
}
|
|
51
|
-
webpackBundle.m[id] = (module2) => {
|
|
52
|
-
module2.exports = value;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
var init_shared_modules = __esm({
|
|
60
|
-
"src/shared/webpack/shared-modules.ts"() {
|
|
61
|
-
"use strict";
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
33
|
// src/shared/error.ts
|
|
66
34
|
function multipleRemoteComponentsError(url) {
|
|
67
35
|
return new Error(
|
|
@@ -79,9 +47,9 @@ var init_error = __esm({
|
|
|
79
47
|
"src/shared/error.ts"() {
|
|
80
48
|
"use strict";
|
|
81
49
|
RemoteComponentsError = class extends Error {
|
|
50
|
+
code = "REMOTE_COMPONENTS_ERROR";
|
|
82
51
|
constructor(message, options) {
|
|
83
52
|
super(message, options);
|
|
84
|
-
this.code = "REMOTE_COMPONENTS_ERROR";
|
|
85
53
|
this.name = "RemoteComponentsError";
|
|
86
54
|
}
|
|
87
55
|
};
|
|
@@ -206,6 +174,38 @@ var init_next_client_pages_loader = __esm({
|
|
|
206
174
|
}
|
|
207
175
|
});
|
|
208
176
|
|
|
177
|
+
// src/shared/webpack/shared-modules.ts
|
|
178
|
+
function applySharedModules(bundle, resolve) {
|
|
179
|
+
const self = globalThis;
|
|
180
|
+
if (self.__remote_webpack_require__?.[bundle]) {
|
|
181
|
+
const modulePaths = Object.keys(
|
|
182
|
+
self.__remote_webpack_module_map__?.[bundle] ?? self.__remote_webpack_require__[bundle].m ?? {}
|
|
183
|
+
);
|
|
184
|
+
for (const [key, value] of Object.entries(resolve)) {
|
|
185
|
+
let ids = modulePaths.filter((p) => p === key);
|
|
186
|
+
if (ids.length === 0) {
|
|
187
|
+
ids = modulePaths.filter((p) => p.includes(key));
|
|
188
|
+
}
|
|
189
|
+
for (let id of ids) {
|
|
190
|
+
const webpackBundle = self.__remote_webpack_require__[bundle];
|
|
191
|
+
if (webpackBundle.m) {
|
|
192
|
+
if (self.__remote_webpack_module_map__?.[bundle]?.[id]) {
|
|
193
|
+
id = `${self.__remote_webpack_module_map__[bundle][id]}`;
|
|
194
|
+
}
|
|
195
|
+
webpackBundle.m[id] = (module2) => {
|
|
196
|
+
module2.exports = value;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
var init_shared_modules = __esm({
|
|
204
|
+
"src/shared/webpack/shared-modules.ts"() {
|
|
205
|
+
"use strict";
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
209
|
// src/shared/utils/index.ts
|
|
210
210
|
function escapeString(str) {
|
|
211
211
|
return str.replace(/[^a-z0-9]/g, "_");
|
|
@@ -394,7 +394,10 @@ async function handleTurbopackChunk(code, bundle, url) {
|
|
|
394
394
|
function createModuleRequire(runtime) {
|
|
395
395
|
return (id) => {
|
|
396
396
|
const self = globalThis;
|
|
397
|
-
const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
|
|
397
|
+
const { bundle, id: moduleId } = id.match(REMOTE_COMPONENT_REGEX)?.groups ?? {
|
|
398
|
+
bundle: "default",
|
|
399
|
+
id
|
|
400
|
+
};
|
|
398
401
|
const remoteRuntime = self.__remote_webpack_require__?.[bundle ?? "default"] ? self.__remote_webpack_require__[bundle ?? "default"]?.type || "webpack" : runtime;
|
|
399
402
|
try {
|
|
400
403
|
if (remoteRuntime === RUNTIME_WEBPACK && bundle && moduleId) {
|
|
@@ -737,6 +740,106 @@ var init_webpack_adapter = __esm({
|
|
|
737
740
|
}
|
|
738
741
|
});
|
|
739
742
|
|
|
743
|
+
// src/shared/client/static-loader.ts
|
|
744
|
+
async function loadStaticRemoteComponent(scripts, url) {
|
|
745
|
+
const self = globalThis;
|
|
746
|
+
if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
747
|
+
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
748
|
+
}
|
|
749
|
+
if (self.__remote_script_entrypoint_unmount__?.[url.href]) {
|
|
750
|
+
self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
|
|
751
|
+
}
|
|
752
|
+
const mountUnmountSets = await Promise.all(
|
|
753
|
+
scripts.map(async (script) => {
|
|
754
|
+
try {
|
|
755
|
+
let src = typeof script.getAttribute === "function" ? script.getAttribute("src") ?? script.src : script.src;
|
|
756
|
+
if (!src && script.textContent) {
|
|
757
|
+
const blob = new Blob(
|
|
758
|
+
[
|
|
759
|
+
script.textContent.replace(
|
|
760
|
+
/import\.meta\.url/g,
|
|
761
|
+
JSON.stringify(url)
|
|
762
|
+
)
|
|
763
|
+
],
|
|
764
|
+
{
|
|
765
|
+
type: "text/javascript"
|
|
766
|
+
}
|
|
767
|
+
);
|
|
768
|
+
src = URL.createObjectURL(blob);
|
|
769
|
+
}
|
|
770
|
+
const mod = await import(
|
|
771
|
+
/* @vite-ignore */
|
|
772
|
+
/* webpackIgnore: true */
|
|
773
|
+
new URL(src, url).href
|
|
774
|
+
);
|
|
775
|
+
if (src.startsWith("blob:")) {
|
|
776
|
+
URL.revokeObjectURL(src);
|
|
777
|
+
}
|
|
778
|
+
if (typeof mod.mount === "function" || typeof mod.default?.mount === "function") {
|
|
779
|
+
if (!self.__remote_script_entrypoint_mount__) {
|
|
780
|
+
self.__remote_script_entrypoint_mount__ = {};
|
|
781
|
+
}
|
|
782
|
+
if (!self.__remote_script_entrypoint_mount__[url.href]) {
|
|
783
|
+
self.__remote_script_entrypoint_mount__[url.href] = /* @__PURE__ */ new Set();
|
|
784
|
+
}
|
|
785
|
+
self.__remote_script_entrypoint_mount__[url.href]?.add(
|
|
786
|
+
mod.mount || mod.default?.mount || (() => {
|
|
787
|
+
})
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
if (typeof mod.unmount === "function" || typeof mod.default?.unmount === "function") {
|
|
791
|
+
if (!self.__remote_script_entrypoint_unmount__) {
|
|
792
|
+
self.__remote_script_entrypoint_unmount__ = {};
|
|
793
|
+
}
|
|
794
|
+
if (!self.__remote_script_entrypoint_unmount__[url.href]) {
|
|
795
|
+
self.__remote_script_entrypoint_unmount__[url.href] = /* @__PURE__ */ new Set();
|
|
796
|
+
}
|
|
797
|
+
self.__remote_script_entrypoint_unmount__[url.href]?.add(
|
|
798
|
+
mod.unmount || mod.default?.unmount || (() => {
|
|
799
|
+
})
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
return {
|
|
803
|
+
mount: mod.mount || mod.default?.mount,
|
|
804
|
+
unmount: mod.unmount || mod.default?.unmount
|
|
805
|
+
};
|
|
806
|
+
} catch (e) {
|
|
807
|
+
console.error(
|
|
808
|
+
new RemoteComponentsError(
|
|
809
|
+
`Error loading remote component script from "${script.src || url.href}".`,
|
|
810
|
+
{ cause: e }
|
|
811
|
+
)
|
|
812
|
+
);
|
|
813
|
+
return {
|
|
814
|
+
mount: void 0,
|
|
815
|
+
unmount: void 0
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
})
|
|
819
|
+
);
|
|
820
|
+
return mountUnmountSets.reduce(
|
|
821
|
+
(acc, { mount, unmount }) => {
|
|
822
|
+
if (typeof mount === "function") {
|
|
823
|
+
acc.mount.add(mount);
|
|
824
|
+
}
|
|
825
|
+
if (typeof unmount === "function") {
|
|
826
|
+
acc.unmount.add(unmount);
|
|
827
|
+
}
|
|
828
|
+
return acc;
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
mount: /* @__PURE__ */ new Set(),
|
|
832
|
+
unmount: /* @__PURE__ */ new Set()
|
|
833
|
+
}
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
var init_static_loader = __esm({
|
|
837
|
+
"src/shared/client/static-loader.ts"() {
|
|
838
|
+
"use strict";
|
|
839
|
+
init_error();
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
|
|
740
843
|
// src/shared/client/polyfill.tsx
|
|
741
844
|
function applyBundleUrlToSrc(bundle, src) {
|
|
742
845
|
const self = globalThis;
|
|
@@ -1044,10 +1147,10 @@ async function webpackRuntime(bundle, shared, remoteShared) {
|
|
|
1044
1147
|
var init_webpack = __esm({
|
|
1045
1148
|
"src/html/host/runtime/webpack.ts"() {
|
|
1046
1149
|
"use strict";
|
|
1150
|
+
init_polyfill();
|
|
1047
1151
|
init_error();
|
|
1048
|
-
init_shared_modules();
|
|
1049
1152
|
init_next_client_pages_loader();
|
|
1050
|
-
|
|
1153
|
+
init_shared_modules();
|
|
1051
1154
|
}
|
|
1052
1155
|
});
|
|
1053
1156
|
|
|
@@ -1098,10 +1201,35 @@ async function turbopackRuntime(url, bundle, shared, remoteShared) {
|
|
|
1098
1201
|
var init_turbopack = __esm({
|
|
1099
1202
|
"src/html/host/runtime/turbopack.ts"() {
|
|
1100
1203
|
"use strict";
|
|
1101
|
-
init_shared_modules();
|
|
1102
|
-
init_next_client_pages_loader();
|
|
1103
|
-
init_webpack_adapter();
|
|
1104
1204
|
init_polyfill();
|
|
1205
|
+
init_webpack_adapter();
|
|
1206
|
+
init_next_client_pages_loader();
|
|
1207
|
+
init_shared_modules();
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1211
|
+
// src/html/host/runtime/script.ts
|
|
1212
|
+
var script_exports = {};
|
|
1213
|
+
__export(script_exports, {
|
|
1214
|
+
scriptRuntime: () => scriptRuntime
|
|
1215
|
+
});
|
|
1216
|
+
function scriptRuntime() {
|
|
1217
|
+
const self = globalThis;
|
|
1218
|
+
return {
|
|
1219
|
+
self,
|
|
1220
|
+
createFromReadableStream: () => Promise.resolve(null),
|
|
1221
|
+
applySharedModules: () => Promise.resolve(),
|
|
1222
|
+
nextClientPagesLoader: () => ({
|
|
1223
|
+
Component: null,
|
|
1224
|
+
App: null
|
|
1225
|
+
}),
|
|
1226
|
+
preloadScripts: loadStaticRemoteComponent
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
var init_script = __esm({
|
|
1230
|
+
"src/html/host/runtime/script.ts"() {
|
|
1231
|
+
"use strict";
|
|
1232
|
+
init_static_loader();
|
|
1105
1233
|
}
|
|
1106
1234
|
});
|
|
1107
1235
|
|
|
@@ -1114,19 +1242,75 @@ module.exports = __toCommonJS(host_exports);
|
|
|
1114
1242
|
var import_react = require("react");
|
|
1115
1243
|
var import_client = require("react-dom/client");
|
|
1116
1244
|
|
|
1245
|
+
// src/shared/client/apply-origin.ts
|
|
1246
|
+
var tagNames = [
|
|
1247
|
+
"img",
|
|
1248
|
+
"source",
|
|
1249
|
+
"video",
|
|
1250
|
+
"audio",
|
|
1251
|
+
"track",
|
|
1252
|
+
"iframe",
|
|
1253
|
+
"embed",
|
|
1254
|
+
"script",
|
|
1255
|
+
"link"
|
|
1256
|
+
];
|
|
1257
|
+
function applyOriginToNodes(doc, url) {
|
|
1258
|
+
if (url.origin !== location.origin) {
|
|
1259
|
+
const nodes = doc.querySelectorAll(
|
|
1260
|
+
tagNames.map(
|
|
1261
|
+
(type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
|
|
1262
|
+
).join(",")
|
|
1263
|
+
);
|
|
1264
|
+
nodes.forEach((node) => {
|
|
1265
|
+
if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
|
|
1266
|
+
node.src = new URL(node.getAttribute("src") ?? "/", url).href;
|
|
1267
|
+
}
|
|
1268
|
+
if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
|
|
1269
|
+
node.setAttribute(
|
|
1270
|
+
"href",
|
|
1271
|
+
new URL(node.getAttribute("href") ?? "/", url).href
|
|
1272
|
+
);
|
|
1273
|
+
}
|
|
1274
|
+
if (node.hasAttribute("srcset")) {
|
|
1275
|
+
const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
|
|
1276
|
+
const [urlPart, descriptor] = entry.trim().split(/\s+/);
|
|
1277
|
+
if (!urlPart)
|
|
1278
|
+
return entry;
|
|
1279
|
+
const absoluteUrl = new URL(urlPart, url).href;
|
|
1280
|
+
return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
|
|
1281
|
+
}).join(", ");
|
|
1282
|
+
if (srcSet) {
|
|
1283
|
+
node.setAttribute("srcset", srcSet);
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
if (node.hasAttribute("imagesrcset")) {
|
|
1287
|
+
const srcSet = node.getAttribute("imagesrcset")?.split(",").map((entry) => {
|
|
1288
|
+
const [urlPart, descriptor] = entry.trim().split(/\s+/);
|
|
1289
|
+
if (!urlPart)
|
|
1290
|
+
return entry;
|
|
1291
|
+
const absoluteUrl = new URL(urlPart, url).href;
|
|
1292
|
+
return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
|
|
1293
|
+
}).join(", ");
|
|
1294
|
+
if (srcSet) {
|
|
1295
|
+
node.setAttribute("imagesrcset", srcSet);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// src/shared/client/remote-component.ts
|
|
1303
|
+
init_error();
|
|
1304
|
+
|
|
1117
1305
|
// src/shared/client/component-loader.ts
|
|
1118
1306
|
var React = __toESM(require("react"), 1);
|
|
1119
|
-
var ReactDOM = __toESM(require("react-dom"), 1);
|
|
1120
|
-
var ReactDOMClient = __toESM(require("react-dom/client"), 1);
|
|
1121
1307
|
var JSXDevRuntime = __toESM(require("react/jsx-dev-runtime"), 1);
|
|
1122
1308
|
var JSXRuntime = __toESM(require("react/jsx-runtime"), 1);
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
init_error();
|
|
1126
|
-
init_webpack_adapter();
|
|
1127
|
-
|
|
1128
|
-
// src/shared/client/script-loader.ts
|
|
1309
|
+
var ReactDOM = __toESM(require("react-dom"), 1);
|
|
1310
|
+
var ReactDOMClient = __toESM(require("react-dom/client"), 1);
|
|
1129
1311
|
init_error();
|
|
1312
|
+
init_next_client_pages_loader();
|
|
1313
|
+
init_shared_modules();
|
|
1130
1314
|
|
|
1131
1315
|
// src/shared/client/rsc.ts
|
|
1132
1316
|
var import_web_streams_polyfill = require("web-streams-polyfill");
|
|
@@ -1194,13 +1378,19 @@ function createRSCStream(rscName, data) {
|
|
|
1194
1378
|
});
|
|
1195
1379
|
}
|
|
1196
1380
|
|
|
1197
|
-
// src/shared/client/
|
|
1381
|
+
// src/shared/client/script-loader.ts
|
|
1382
|
+
init_error();
|
|
1383
|
+
|
|
1384
|
+
// src/shared/client/component-loader.ts
|
|
1198
1385
|
init_webpack_adapter();
|
|
1386
|
+
|
|
1387
|
+
// src/shared/client/remote-component.ts
|
|
1199
1388
|
init_const();
|
|
1200
|
-
|
|
1389
|
+
init_static_loader();
|
|
1390
|
+
init_webpack_adapter();
|
|
1201
1391
|
|
|
1202
1392
|
// src/html/host/index.tsx
|
|
1203
|
-
|
|
1393
|
+
init_error();
|
|
1204
1394
|
|
|
1205
1395
|
// src/shared/ssr/fetch-headers.ts
|
|
1206
1396
|
function remoteFetchHeaders(additionalHeaders) {
|
|
@@ -1220,65 +1410,8 @@ function remoteFetchHeaders(additionalHeaders) {
|
|
|
1220
1410
|
};
|
|
1221
1411
|
}
|
|
1222
1412
|
|
|
1223
|
-
// src/shared/client/apply-origin.ts
|
|
1224
|
-
var tagNames = [
|
|
1225
|
-
"img",
|
|
1226
|
-
"source",
|
|
1227
|
-
"video",
|
|
1228
|
-
"audio",
|
|
1229
|
-
"track",
|
|
1230
|
-
"iframe",
|
|
1231
|
-
"embed",
|
|
1232
|
-
"script",
|
|
1233
|
-
"link"
|
|
1234
|
-
];
|
|
1235
|
-
function applyOriginToNodes(doc, url) {
|
|
1236
|
-
if (url.origin !== location.origin) {
|
|
1237
|
-
const nodes = doc.querySelectorAll(
|
|
1238
|
-
tagNames.map(
|
|
1239
|
-
(type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
|
|
1240
|
-
).join(",")
|
|
1241
|
-
);
|
|
1242
|
-
nodes.forEach((node) => {
|
|
1243
|
-
if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
|
|
1244
|
-
node.src = new URL(node.getAttribute("src") ?? "/", url).href;
|
|
1245
|
-
}
|
|
1246
|
-
if (node.hasAttribute("href") && /^[./]+\/?/.test(node.getAttribute("href") ?? "")) {
|
|
1247
|
-
node.setAttribute(
|
|
1248
|
-
"href",
|
|
1249
|
-
new URL(node.getAttribute("href") ?? "/", url).href
|
|
1250
|
-
);
|
|
1251
|
-
}
|
|
1252
|
-
if (node.hasAttribute("srcset")) {
|
|
1253
|
-
const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
|
|
1254
|
-
const [urlPart, descriptor] = entry.trim().split(/\s+/);
|
|
1255
|
-
if (!urlPart)
|
|
1256
|
-
return entry;
|
|
1257
|
-
const absoluteUrl = new URL(urlPart, url).href;
|
|
1258
|
-
return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
|
|
1259
|
-
}).join(", ");
|
|
1260
|
-
if (srcSet) {
|
|
1261
|
-
node.setAttribute("srcset", srcSet);
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
if (node.hasAttribute("imagesrcset")) {
|
|
1265
|
-
const srcSet = node.getAttribute("imagesrcset")?.split(",").map((entry) => {
|
|
1266
|
-
const [urlPart, descriptor] = entry.trim().split(/\s+/);
|
|
1267
|
-
if (!urlPart)
|
|
1268
|
-
return entry;
|
|
1269
|
-
const absoluteUrl = new URL(urlPart, url).href;
|
|
1270
|
-
return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
|
|
1271
|
-
}).join(", ");
|
|
1272
|
-
if (srcSet) {
|
|
1273
|
-
node.setAttribute("imagesrcset", srcSet);
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
});
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
1413
|
// src/html/host/index.tsx
|
|
1281
|
-
|
|
1414
|
+
init_utils();
|
|
1282
1415
|
|
|
1283
1416
|
// src/html/host/runtime/index.ts
|
|
1284
1417
|
init_error();
|
|
@@ -1294,9 +1427,12 @@ async function getRuntime(type, url, bundle, shared, remoteShared) {
|
|
|
1294
1427
|
} else if (type === "turbopack") {
|
|
1295
1428
|
const { turbopackRuntime: turbopackRuntime2 } = await Promise.resolve().then(() => (init_turbopack(), turbopack_exports));
|
|
1296
1429
|
return turbopackRuntime2(url, bundle, shared, remoteShared);
|
|
1430
|
+
} else if (type === "script") {
|
|
1431
|
+
const { scriptRuntime: scriptRuntime2 } = await Promise.resolve().then(() => (init_script(), script_exports));
|
|
1432
|
+
return scriptRuntime2();
|
|
1297
1433
|
}
|
|
1298
1434
|
throw new RemoteComponentsError(
|
|
1299
|
-
`Remote Components runtime "${type}" is not supported. Supported runtimes are "webpack" and "
|
|
1435
|
+
`Remote Components runtime "${type}" is not supported. Supported runtimes are "webpack", "turbopack", and "script".`
|
|
1300
1436
|
);
|
|
1301
1437
|
}
|
|
1302
1438
|
|
|
@@ -1304,13 +1440,17 @@ async function getRuntime(type, url, bundle, shared, remoteShared) {
|
|
|
1304
1440
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1305
1441
|
if (typeof HTMLElement !== "undefined") {
|
|
1306
1442
|
class RemoteComponent extends HTMLElement {
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1443
|
+
name;
|
|
1444
|
+
bundle;
|
|
1445
|
+
fallbackSlot;
|
|
1446
|
+
__next = null;
|
|
1447
|
+
fouc = null;
|
|
1448
|
+
isLoading = false;
|
|
1449
|
+
prevIsRemoteComponent = false;
|
|
1450
|
+
prevUrl;
|
|
1451
|
+
root = null;
|
|
1452
|
+
reactRoot;
|
|
1453
|
+
additionalHeaders;
|
|
1314
1454
|
static get observedAttributes() {
|
|
1315
1455
|
return ["src", "name", "mode"];
|
|
1316
1456
|
}
|
|
@@ -1422,23 +1562,27 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1422
1562
|
}
|
|
1423
1563
|
const parser = new DOMParser();
|
|
1424
1564
|
const doc = parser.parseFromString(html, "text/html");
|
|
1425
|
-
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(
|
|
1565
|
+
if (doc.querySelectorAll("div[data-bundle][data-route]").length > 1 && !doc.querySelector(
|
|
1566
|
+
`div[data-bundle][data-route][id^="${this.name}"]`
|
|
1567
|
+
) || doc.querySelectorAll("remote-component").length > 1 && !doc.querySelector(`remote-component[name="${this.name}"]`)) {
|
|
1426
1568
|
throw multipleRemoteComponentsError(
|
|
1427
1569
|
url?.href ?? (this.getAttribute("src") || "unknown")
|
|
1428
1570
|
);
|
|
1429
1571
|
}
|
|
1430
1572
|
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
|
|
1431
1573
|
doc.querySelector("div[data-bundle][data-route]") ?? // fallback to Next.js Pages Router
|
|
1432
|
-
doc.querySelector("div#__next")
|
|
1574
|
+
doc.querySelector("div#__next") ?? // fallback to a <remote-component> element
|
|
1575
|
+
doc.querySelector(`remote-component[name="${this.name}"]:not([src])`) ?? doc.querySelector("remote-component:not([src])");
|
|
1433
1576
|
const nextData = JSON.parse(
|
|
1434
1577
|
(doc.querySelector("#__NEXT_DATA__") ?? doc.querySelector("#__REMOTE_NEXT_DATA__"))?.textContent ?? "null"
|
|
1435
1578
|
);
|
|
1579
|
+
const isRemoteComponent = component?.tagName.toLowerCase() === "remote-component";
|
|
1436
1580
|
if (nextData && nextData.buildId === "development" && !this.reactRoot) {
|
|
1437
1581
|
this.fouc = document.createElement("style");
|
|
1438
1582
|
this.fouc.textContent = `:host { display: none; }`;
|
|
1439
1583
|
this.root.appendChild(this.fouc);
|
|
1440
1584
|
}
|
|
1441
|
-
this.name = component?.getAttribute("id")?.replace(/_ssr$/, "") || (nextData ? "__next" : this.name);
|
|
1585
|
+
this.name = component?.getAttribute("id")?.replace(/_ssr$/, "") || isRemoteComponent && component.getAttribute("name") || (nextData ? "__next" : this.name);
|
|
1442
1586
|
const rsc = doc.querySelector(`#${this.name}_rsc`);
|
|
1443
1587
|
this.bundle = component?.getAttribute("data-bundle") || nextData?.props.__REMOTE_COMPONENT__?.bundle || this.bundle;
|
|
1444
1588
|
if (url) {
|
|
@@ -1451,12 +1595,13 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1451
1595
|
const metadata = document.createElement("script");
|
|
1452
1596
|
metadata.type = "application/json";
|
|
1453
1597
|
metadata.setAttribute("data-remote-component", "");
|
|
1454
|
-
|
|
1598
|
+
const metadataObj = {
|
|
1455
1599
|
name: this.name,
|
|
1456
1600
|
bundle: this.bundle,
|
|
1457
|
-
route: component?.getAttribute("data-route") ?? nextData?.page ?? "/",
|
|
1458
|
-
runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime
|
|
1459
|
-
}
|
|
1601
|
+
route: component?.getAttribute("data-route") ?? nextData?.page ?? url?.pathname ?? "/",
|
|
1602
|
+
runtime: component?.getAttribute("data-runtime") ?? nextData?.props.__REMOTE_COMPONENT__?.runtime ?? "script"
|
|
1603
|
+
};
|
|
1604
|
+
metadata.textContent = JSON.stringify(metadataObj);
|
|
1460
1605
|
if (this.previousElementSibling?.getAttribute("data-remote-component") !== null) {
|
|
1461
1606
|
this.previousElementSibling?.remove();
|
|
1462
1607
|
}
|
|
@@ -1471,11 +1616,38 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1471
1616
|
remoteShared.__remote_components_missing_shared__
|
|
1472
1617
|
);
|
|
1473
1618
|
}
|
|
1474
|
-
if (!component || !(rsc || nextData)) {
|
|
1619
|
+
if (!component || !(rsc || nextData || isRemoteComponent)) {
|
|
1475
1620
|
throw new RemoteComponentsError(
|
|
1476
1621
|
`Remote Component not found on ${src}.${this.name !== "__vercel_remote_component" ? ` The name for the <RemoteComponent> is "${this.name}". Check <RemoteComponent> usage.` : ""} Did you forget to wrap the content in <RemoteComponent>?`
|
|
1477
1622
|
);
|
|
1478
1623
|
}
|
|
1624
|
+
if (this.prevIsRemoteComponent) {
|
|
1625
|
+
if (this.prevUrl) {
|
|
1626
|
+
const prevUrl = this.prevUrl;
|
|
1627
|
+
const self2 = globalThis;
|
|
1628
|
+
if (self2.__remote_script_entrypoint_unmount__?.[prevUrl.href]) {
|
|
1629
|
+
await Promise.all(
|
|
1630
|
+
Array.from(
|
|
1631
|
+
self2.__remote_script_entrypoint_unmount__[prevUrl.href] ?? []
|
|
1632
|
+
).map(async (unmount) => {
|
|
1633
|
+
try {
|
|
1634
|
+
await unmount(this.root);
|
|
1635
|
+
} catch (e) {
|
|
1636
|
+
console.error(
|
|
1637
|
+
new RemoteComponentsError(
|
|
1638
|
+
`Error while calling unmount() for Remote Component from ${prevUrl.href}.`,
|
|
1639
|
+
{ cause: e }
|
|
1640
|
+
)
|
|
1641
|
+
);
|
|
1642
|
+
}
|
|
1643
|
+
})
|
|
1644
|
+
);
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
this.root.innerHTML = "";
|
|
1648
|
+
}
|
|
1649
|
+
this.prevUrl = url ?? new URL(location.href);
|
|
1650
|
+
this.prevIsRemoteComponent = isRemoteComponent;
|
|
1479
1651
|
const removable = Array.from(this.childNodes);
|
|
1480
1652
|
const links = doc.querySelectorAll("link[href]");
|
|
1481
1653
|
const remoteComponentSrc = this.getAttribute("src");
|
|
@@ -1541,7 +1713,35 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1541
1713
|
applyOriginToNodes(doc, url ?? new URL(location.href));
|
|
1542
1714
|
if (!this.reactRoot) {
|
|
1543
1715
|
Array.from(component.children).forEach((el) => {
|
|
1544
|
-
|
|
1716
|
+
if (!isRemoteComponent && el.tagName.toLowerCase() === "script") {
|
|
1717
|
+
const newScript = document.createElement("script");
|
|
1718
|
+
for (const attr of el.attributes) {
|
|
1719
|
+
if (attr.name === "src") {
|
|
1720
|
+
newScript.setAttribute(
|
|
1721
|
+
attr.name,
|
|
1722
|
+
new URL(attr.value, url ?? location.origin).href
|
|
1723
|
+
);
|
|
1724
|
+
} else {
|
|
1725
|
+
newScript.setAttribute(attr.name, attr.value);
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
newScript.textContent = el.textContent;
|
|
1729
|
+
if (remoteComponentSrc) {
|
|
1730
|
+
newScript.setAttribute(
|
|
1731
|
+
"data-remote-component-src",
|
|
1732
|
+
remoteComponentSrc
|
|
1733
|
+
);
|
|
1734
|
+
}
|
|
1735
|
+
this.root?.appendChild(newScript);
|
|
1736
|
+
} else {
|
|
1737
|
+
const newEl = el.cloneNode(true);
|
|
1738
|
+
for (const attr of el.attributes) {
|
|
1739
|
+
if (attr.name.startsWith("on")) {
|
|
1740
|
+
newEl.setAttribute(attr.name, attr.value);
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
this.root?.appendChild(newEl);
|
|
1744
|
+
}
|
|
1545
1745
|
});
|
|
1546
1746
|
}
|
|
1547
1747
|
for (const el of removable) {
|
|
@@ -1580,7 +1780,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1580
1780
|
nextClientPagesLoader: nextClientPagesLoader2,
|
|
1581
1781
|
preloadScripts
|
|
1582
1782
|
} = await getRuntime(
|
|
1583
|
-
|
|
1783
|
+
metadataObj.runtime,
|
|
1584
1784
|
url ?? new URL(location.href),
|
|
1585
1785
|
this.bundle,
|
|
1586
1786
|
{
|
|
@@ -1592,8 +1792,8 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1592
1792
|
},
|
|
1593
1793
|
remoteShared
|
|
1594
1794
|
);
|
|
1595
|
-
const scripts = doc.querySelectorAll(
|
|
1596
|
-
"script[src],script[data-src]"
|
|
1795
|
+
const scripts = isRemoteComponent ? component.querySelectorAll("script") : doc.querySelectorAll(
|
|
1796
|
+
"script[src],script[data-src],script[data-remote-component-entrypoint]"
|
|
1597
1797
|
);
|
|
1598
1798
|
if (!url) {
|
|
1599
1799
|
url = new URL(
|
|
@@ -1607,6 +1807,13 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1607
1807
|
this.bundle ?? "default",
|
|
1608
1808
|
this.name ?? "__vercel_remote_component"
|
|
1609
1809
|
);
|
|
1810
|
+
if (isRemoteComponent) {
|
|
1811
|
+
Array.from(component.children).forEach((child) => {
|
|
1812
|
+
if (child.tagName === "SCRIPT") {
|
|
1813
|
+
child.remove();
|
|
1814
|
+
}
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1610
1817
|
const doCleanup = () => {
|
|
1611
1818
|
if (this.root && remoteComponentSrc) {
|
|
1612
1819
|
const selector = `[data-remote-component-src]:not([data-remote-component-src="${remoteComponentSrc}"])`;
|
|
@@ -1706,7 +1913,7 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1706
1913
|
});
|
|
1707
1914
|
}
|
|
1708
1915
|
remoteComponent.isLoading = false;
|
|
1709
|
-
}, [initial]);
|
|
1916
|
+
}, [initial, remoteComponent]);
|
|
1710
1917
|
return NextApp ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NextApp, { Component: NextComponent, ...nextData.props }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NextComponent, { ...nextData.props });
|
|
1711
1918
|
})(App, Component, this);
|
|
1712
1919
|
if (this.reactRoot) {
|
|
@@ -1728,6 +1935,23 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1728
1935
|
if (this.fouc) {
|
|
1729
1936
|
this.root.removeChild(this.fouc);
|
|
1730
1937
|
}
|
|
1938
|
+
} else if (self.__remote_script_entrypoint_mount__?.[url.href]) {
|
|
1939
|
+
await Promise.all(
|
|
1940
|
+
Array.from(
|
|
1941
|
+
self.__remote_script_entrypoint_mount__[url.href] ?? []
|
|
1942
|
+
).map(async (mount) => {
|
|
1943
|
+
try {
|
|
1944
|
+
await mount(this.root);
|
|
1945
|
+
} catch (e) {
|
|
1946
|
+
console.error(
|
|
1947
|
+
new RemoteComponentsError(
|
|
1948
|
+
`Error while calling mount() for Remote Component from ${url.href}.`,
|
|
1949
|
+
{ cause: e }
|
|
1950
|
+
)
|
|
1951
|
+
);
|
|
1952
|
+
}
|
|
1953
|
+
})
|
|
1954
|
+
);
|
|
1731
1955
|
}
|
|
1732
1956
|
this.isLoading = false;
|
|
1733
1957
|
}
|