remote-components 0.0.24 → 0.0.25
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 +32 -10
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +32 -10
- 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/remote-component.cjs +17 -10
- 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 +17 -10
- 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/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>.+)/;
|
|
@@ -868,26 +879,27 @@ function fixPayload(payload) {
|
|
|
868
879
|
}
|
|
869
880
|
}
|
|
870
881
|
}
|
|
871
|
-
function createRSCStream(
|
|
882
|
+
function createRSCStream(rscName, data) {
|
|
872
883
|
return new import_web_streams_polyfill.ReadableStream({
|
|
873
884
|
type: "bytes",
|
|
874
885
|
start(controller) {
|
|
875
886
|
const encoder = new TextEncoder();
|
|
876
887
|
const self = globalThis;
|
|
877
|
-
if (
|
|
888
|
+
if (data.length > 0) {
|
|
878
889
|
data.forEach((chunk) => {
|
|
879
890
|
const lines = chunk.split("\n");
|
|
880
891
|
for (const line of lines) {
|
|
881
892
|
const match = /\.push\("(?<rsc>.*)"\);$/.exec(line);
|
|
882
893
|
if (match?.groups?.rsc) {
|
|
883
|
-
self[
|
|
884
|
-
self[
|
|
894
|
+
self[rscName] = self[rscName] ?? [];
|
|
895
|
+
self[rscName].push(JSON.parse(`"${match.groups.rsc}"`));
|
|
885
896
|
}
|
|
886
897
|
}
|
|
887
898
|
});
|
|
888
899
|
}
|
|
889
|
-
const allChunks = (self[
|
|
900
|
+
const allChunks = (self[rscName] ?? [`0:[null]
|
|
890
901
|
`]).join("");
|
|
902
|
+
self[rscName] = null;
|
|
891
903
|
allChunks.split("\n").forEach((chunk) => {
|
|
892
904
|
if (chunk.length > 0) {
|
|
893
905
|
const { before, id, prefix, payload } = /^(?<before>.*?)?(?<id>[0-9a-zA-Z]+):(?<prefix>[A-Z])?(?<payload>\[.*\])/.exec(
|
|
@@ -917,6 +929,9 @@ function createRSCStream(name, data) {
|
|
|
917
929
|
init_webpack_adapter();
|
|
918
930
|
init_const();
|
|
919
931
|
|
|
932
|
+
// src/html/host/index.tsx
|
|
933
|
+
init_utils();
|
|
934
|
+
|
|
920
935
|
// src/shared/client/apply-origin.ts
|
|
921
936
|
var tagNames = [
|
|
922
937
|
"img",
|
|
@@ -1253,17 +1268,24 @@ if (typeof HTMLElement !== "undefined") {
|
|
|
1253
1268
|
};
|
|
1254
1269
|
if (rsc) {
|
|
1255
1270
|
rsc.parentElement?.removeChild(rsc);
|
|
1271
|
+
const rscName = `__remote_component_rsc_${escapeString(url.href)}_${escapeString(this.name)}`;
|
|
1256
1272
|
const rscClone = document.createElement("script");
|
|
1257
|
-
rscClone.id = `${
|
|
1258
|
-
rscClone.textContent = rsc.textContent
|
|
1273
|
+
rscClone.id = `${rscName}_rsc`;
|
|
1274
|
+
rscClone.textContent = rsc.textContent?.replace(
|
|
1275
|
+
new RegExp(`self\\["${this.name}"\\]`, "g"),
|
|
1276
|
+
`self["${rscName}"]`
|
|
1277
|
+
) ?? "";
|
|
1259
1278
|
document.body.appendChild(rscClone);
|
|
1260
1279
|
let cache;
|
|
1261
1280
|
const RemoteComponentFromReadableStream = ({
|
|
1262
1281
|
name,
|
|
1263
1282
|
initial
|
|
1264
1283
|
}) => {
|
|
1265
|
-
const stream = createRSCStream(
|
|
1266
|
-
|
|
1284
|
+
const stream = createRSCStream(
|
|
1285
|
+
rscName,
|
|
1286
|
+
self[rscName] ?? [`0:[null]
|
|
1287
|
+
`]
|
|
1288
|
+
);
|
|
1267
1289
|
const Component = cache ?? // cache the component to avoid reloading the RSC flight data
|
|
1268
1290
|
(cache = createFromReadableStream(stream));
|
|
1269
1291
|
(0, import_react.useLayoutEffect)(() => {
|