remote-components 0.0.24 → 0.0.26
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/html/host.cjs +103 -38
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +103 -38
- package/dist/html/host.js.map +1 -1
- package/dist/internal/next/host/app-router-client.cjs +5 -2
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.js +5 -2
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/shared/client/apply-origin.cjs +21 -19
- package/dist/internal/shared/client/apply-origin.cjs.map +1 -1
- package/dist/internal/shared/client/apply-origin.js +21 -19
- package/dist/internal/shared/client/apply-origin.js.map +1 -1
- package/dist/internal/shared/client/polyfill.cjs +9 -1
- package/dist/internal/shared/client/polyfill.cjs.map +1 -1
- package/dist/internal/shared/client/polyfill.js +9 -1
- package/dist/internal/shared/client/polyfill.js.map +1 -1
- package/dist/internal/shared/client/remote-component.cjs +58 -18
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +3 -2
- package/dist/internal/shared/client/remote-component.js +58 -18
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/utils.cjs +31 -0
- package/dist/internal/shared/utils.cjs.map +1 -0
- package/dist/internal/shared/utils.d.ts +3 -0
- package/dist/internal/shared/utils.js +7 -0
- package/dist/internal/shared/utils.js.map +1 -0
- package/dist/next/config.cjs +2 -1
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +2 -1
- package/dist/next/config.js.map +1 -1
- package/dist/react/index.cjs +15 -7
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +15 -7
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/html/host.cjs
CHANGED
|
@@ -179,14 +179,25 @@ var init_next_client_pages_loader = __esm({
|
|
|
179
179
|
}
|
|
180
180
|
});
|
|
181
181
|
|
|
182
|
+
// src/shared/utils/index.ts
|
|
183
|
+
function escapeString(str) {
|
|
184
|
+
return str.replace(/[^a-z0-9]/g, "_");
|
|
185
|
+
}
|
|
186
|
+
var init_utils = __esm({
|
|
187
|
+
"src/shared/utils/index.ts"() {
|
|
188
|
+
"use strict";
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
182
192
|
// src/shared/client/const.ts
|
|
183
193
|
function getBundleKey(bundle) {
|
|
184
|
-
return bundle
|
|
194
|
+
return escapeString(bundle);
|
|
185
195
|
}
|
|
186
196
|
var RUNTIME_WEBPACK, RUNTIME_TURBOPACK, REMOTE_COMPONENT_REGEX;
|
|
187
197
|
var init_const = __esm({
|
|
188
198
|
"src/shared/client/const.ts"() {
|
|
189
199
|
"use strict";
|
|
200
|
+
init_utils();
|
|
190
201
|
RUNTIME_WEBPACK = "webpack";
|
|
191
202
|
RUNTIME_TURBOPACK = "turbopack";
|
|
192
203
|
REMOTE_COMPONENT_REGEX = /(?<prefix>.*?)\[(?<bundle>[^\]]+)\](?:%20| )(?<id>.+)/;
|
|
@@ -369,17 +380,21 @@ function createModuleRequire(runtime) {
|
|
|
369
380
|
return handleTurbopackModule(bundle, moduleId, id);
|
|
370
381
|
}
|
|
371
382
|
throw new Error(`Module ${id} not found`);
|
|
372
|
-
} catch {
|
|
383
|
+
} catch (requireError) {
|
|
373
384
|
if (typeof self.__original_webpack_require__ !== "function") {
|
|
374
385
|
throw new Error(
|
|
375
|
-
`Module ${id} not found in remote component bundle ${bundle}
|
|
386
|
+
`Module ${id} not found in remote component bundle ${bundle}`,
|
|
387
|
+
{
|
|
388
|
+
cause: requireError instanceof Error ? requireError : void 0
|
|
389
|
+
}
|
|
376
390
|
);
|
|
377
391
|
}
|
|
378
392
|
try {
|
|
379
393
|
return self.__original_webpack_require__(id);
|
|
380
|
-
} catch {
|
|
394
|
+
} catch (originalError) {
|
|
381
395
|
throw new Error(
|
|
382
|
-
`Module ${id} not found in remote component bundle ${bundle}
|
|
396
|
+
`Module ${id} not found in remote component bundle ${bundle}`,
|
|
397
|
+
{ cause: originalError instanceof Error ? originalError : void 0 }
|
|
383
398
|
);
|
|
384
399
|
}
|
|
385
400
|
}
|
|
@@ -475,7 +490,8 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
475
490
|
registerExports() {
|
|
476
491
|
},
|
|
477
492
|
signature() {
|
|
478
|
-
return () => {
|
|
493
|
+
return (fn) => {
|
|
494
|
+
return fn;
|
|
479
495
|
};
|
|
480
496
|
}
|
|
481
497
|
},
|
|
@@ -508,8 +524,18 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
508
524
|
const mod = self.__webpack_require__?.(
|
|
509
525
|
`[${bundle}] ${normalizedId}`
|
|
510
526
|
);
|
|
511
|
-
if (exportSource && exportName && typeof mod[exportSource] !== "undefined" && typeof mod[exportName] === "undefined") {
|
|
512
|
-
|
|
527
|
+
if (exportSource && exportName && (exportSource === "*" || typeof mod[exportSource] !== "undefined") && typeof mod[exportName] === "undefined") {
|
|
528
|
+
if (exportSource === "*") {
|
|
529
|
+
mod[exportName] = mod;
|
|
530
|
+
} else {
|
|
531
|
+
mod[exportName] = mod[exportSource];
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (!("default" in mod) && mod.toString() !== "[object Module]") {
|
|
535
|
+
try {
|
|
536
|
+
mod.default = mod;
|
|
537
|
+
} catch {
|
|
538
|
+
}
|
|
513
539
|
}
|
|
514
540
|
return mod;
|
|
515
541
|
},
|
|
@@ -519,6 +545,21 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
519
545
|
v(value) {
|
|
520
546
|
exports.default = value;
|
|
521
547
|
},
|
|
548
|
+
async a(mod) {
|
|
549
|
+
let result;
|
|
550
|
+
await mod(
|
|
551
|
+
() => {
|
|
552
|
+
},
|
|
553
|
+
(value) => result = value
|
|
554
|
+
);
|
|
555
|
+
exports.default = result;
|
|
556
|
+
},
|
|
557
|
+
async A(Aid) {
|
|
558
|
+
const mod = self.__webpack_require__?.(`[${bundle}] ${Aid}`);
|
|
559
|
+
return mod.default(
|
|
560
|
+
(parentId) => self.__webpack_require__?.(`[${bundle}] ${parentId}`)
|
|
561
|
+
);
|
|
562
|
+
},
|
|
522
563
|
g: self.__remote_components_turbopack_global__[bundle],
|
|
523
564
|
m: moduleExports,
|
|
524
565
|
e: exports
|
|
@@ -531,6 +572,9 @@ function handleTurbopackModule(bundle, moduleId, id) {
|
|
|
531
572
|
exports[name] = exports[name]();
|
|
532
573
|
}
|
|
533
574
|
}
|
|
575
|
+
if (self.__remote_components_turbopack_modules__[bundle][moduleId] !== moduleExports.exports) {
|
|
576
|
+
self.__remote_components_turbopack_modules__[bundle][moduleId] = moduleExports.exports;
|
|
577
|
+
}
|
|
534
578
|
return moduleExports.exports;
|
|
535
579
|
}
|
|
536
580
|
var init_webpack_adapter = __esm({
|
|
@@ -631,7 +675,15 @@ function sharedPolyfills(shared) {
|
|
|
631
675
|
},
|
|
632
676
|
__esModule: true
|
|
633
677
|
})
|
|
634
|
-
))
|
|
678
|
+
)),
|
|
679
|
+
"next/dist/build/polyfills/process": () => Promise.resolve({
|
|
680
|
+
default: {
|
|
681
|
+
env: {
|
|
682
|
+
NODE_ENV: "production"
|
|
683
|
+
}
|
|
684
|
+
},
|
|
685
|
+
__esModule: true
|
|
686
|
+
})
|
|
635
687
|
};
|
|
636
688
|
polyfill["next/navigation"] = polyfill["next/dist/client/components/navigation"];
|
|
637
689
|
polyfill["next/link"] = polyfill["next/dist/client/app-dir/link"];
|
|
@@ -868,29 +920,30 @@ function fixPayload(payload) {
|
|
|
868
920
|
}
|
|
869
921
|
}
|
|
870
922
|
}
|
|
871
|
-
function createRSCStream(
|
|
923
|
+
function createRSCStream(rscName, data) {
|
|
872
924
|
return new import_web_streams_polyfill.ReadableStream({
|
|
873
925
|
type: "bytes",
|
|
874
926
|
start(controller) {
|
|
875
927
|
const encoder = new TextEncoder();
|
|
876
928
|
const self = globalThis;
|
|
877
|
-
if (
|
|
929
|
+
if (data.length > 0) {
|
|
878
930
|
data.forEach((chunk) => {
|
|
879
931
|
const lines = chunk.split("\n");
|
|
880
932
|
for (const line of lines) {
|
|
881
933
|
const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
|
|
882
934
|
if (match?.groups?.rsc) {
|
|
883
|
-
self[
|
|
884
|
-
self[
|
|
935
|
+
self[rscName] = self[rscName] ?? [];
|
|
936
|
+
self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
|
|
885
937
|
}
|
|
886
938
|
}
|
|
887
939
|
});
|
|
888
940
|
}
|
|
889
|
-
const allChunks = (self[
|
|
941
|
+
const allChunks = (self[rscName] ?? [`0:[null]
|
|
890
942
|
`]).join("");
|
|
943
|
+
self[rscName] = null;
|
|
891
944
|
allChunks.split("\n").forEach((chunk) => {
|
|
892
945
|
if (chunk.length > 0) {
|
|
893
|
-
const { before, id, prefix, payload } = /^(?<before
|
|
946
|
+
const { before, id, prefix, payload } = /^(?<before>[^:]*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
|
|
894
947
|
chunk
|
|
895
948
|
)?.groups ?? {};
|
|
896
949
|
if (payload) {
|
|
@@ -917,6 +970,9 @@ function createRSCStream(name, data) {
|
|
|
917
970
|
init_webpack_adapter();
|
|
918
971
|
init_const();
|
|
919
972
|
|
|
973
|
+
// src/html/host/index.tsx
|
|
974
|
+
init_utils();
|
|
975
|
+
|
|
920
976
|
// src/shared/client/apply-origin.ts
|
|
921
977
|
var tagNames = [
|
|
922
978
|
"img",
|
|
@@ -930,26 +986,28 @@ var tagNames = [
|
|
|
930
986
|
"link"
|
|
931
987
|
];
|
|
932
988
|
function applyOriginToNodes(doc, url) {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
node.src
|
|
939
|
-
|
|
940
|
-
if (node.hasAttribute("srcset")) {
|
|
941
|
-
const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
|
|
942
|
-
const [urlPart, descriptor] = entry.trim().split(/\s+/);
|
|
943
|
-
if (!urlPart)
|
|
944
|
-
return entry;
|
|
945
|
-
const absoluteUrl = new URL(urlPart, url).href;
|
|
946
|
-
return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
|
|
947
|
-
}).join(", ");
|
|
948
|
-
if (srcSet) {
|
|
949
|
-
node.setAttribute("srcset", srcSet);
|
|
989
|
+
if (url.origin !== location.origin) {
|
|
990
|
+
const nodes = doc.querySelectorAll(
|
|
991
|
+
tagNames.map((type) => `${type}[src],${type}[srcset]`).join(",")
|
|
992
|
+
);
|
|
993
|
+
nodes.forEach((node) => {
|
|
994
|
+
if (node.hasAttribute("src") && /^[./]+\/?/.test(node.getAttribute("src") ?? "")) {
|
|
995
|
+
node.src = new URL(node.getAttribute("src") ?? "/", url).href;
|
|
950
996
|
}
|
|
951
|
-
|
|
952
|
-
|
|
997
|
+
if (node.hasAttribute("srcset")) {
|
|
998
|
+
const srcSet = node.getAttribute("srcset")?.split(",").map((entry) => {
|
|
999
|
+
const [urlPart, descriptor] = entry.trim().split(/\s+/);
|
|
1000
|
+
if (!urlPart)
|
|
1001
|
+
return entry;
|
|
1002
|
+
const absoluteUrl = new URL(urlPart, url).href;
|
|
1003
|
+
return descriptor ? `${absoluteUrl} ${descriptor}` : absoluteUrl;
|
|
1004
|
+
}).join(", ");
|
|
1005
|
+
if (srcSet) {
|
|
1006
|
+
node.setAttribute("srcset", srcSet);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
953
1011
|
}
|
|
954
1012
|
|
|
955
1013
|
// src/html/host/runtime/index.ts
|
|
@@ -1253,17 +1311,24 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1253
1311
|
};
|
|
1254
1312
|
if (rsc) {
|
|
1255
1313
|
rsc.parentElement?.removeChild(rsc);
|
|
1314
|
+
const rscName = `__remote_component_rsc_${escapeString(url.href)}_${escapeString(this.name)}`;
|
|
1256
1315
|
const rscClone = document.createElement("script");
|
|
1257
|
-
rscClone.id = `${
|
|
1258
|
-
rscClone.textContent = rsc.textContent
|
|
1316
|
+
rscClone.id = `${rscName}_rsc`;
|
|
1317
|
+
rscClone.textContent = rsc.textContent?.replace(
|
|
1318
|
+
new RegExp(`self\\["${this.name}"\\]`, "g"),
|
|
1319
|
+
`self["${rscName}"]`
|
|
1320
|
+
) ?? "";
|
|
1259
1321
|
document.body.appendChild(rscClone);
|
|
1260
1322
|
let cache;
|
|
1261
1323
|
const RemoteComponentFromReadableStream = ({
|
|
1262
1324
|
name,
|
|
1263
1325
|
initial
|
|
1264
1326
|
}) => {
|
|
1265
|
-
const stream = createRSCStream(
|
|
1266
|
-
|
|
1327
|
+
const stream = createRSCStream(
|
|
1328
|
+
rscName,
|
|
1329
|
+
self[rscName] ?? [`0:[null]
|
|
1330
|
+
`]
|
|
1331
|
+
);
|
|
1267
1332
|
const Component = cache ?? // cache the component to avoid reloading the RSC flight data
|
|
1268
1333
|
(cache = createFromReadableStream(stream));
|
|
1269
1334
|
(0, import_react.useLayoutEffect)(() => {
|