react-server-dom-webpack 19.0.0-beta-04b058868c-20240508 → 19.0.0-beta-26f2496093-20240514
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/cjs/react-server-dom-webpack-client.browser.development.js +933 -63
- package/cjs/react-server-dom-webpack-client.browser.production.js +715 -217
- package/cjs/react-server-dom-webpack-client.edge.development.js +933 -63
- package/cjs/react-server-dom-webpack-client.edge.production.js +715 -217
- package/cjs/react-server-dom-webpack-client.node.development.js +932 -62
- package/cjs/react-server-dom-webpack-client.node.production.js +700 -207
- package/cjs/react-server-dom-webpack-client.node.unbundled.development.js +932 -62
- package/cjs/react-server-dom-webpack-client.node.unbundled.production.js +700 -207
- package/cjs/react-server-dom-webpack-server.browser.development.js +1279 -199
- package/cjs/react-server-dom-webpack-server.browser.production.js +808 -162
- package/cjs/react-server-dom-webpack-server.edge.development.js +1280 -200
- package/cjs/react-server-dom-webpack-server.edge.production.js +808 -162
- package/cjs/react-server-dom-webpack-server.node.development.js +1235 -204
- package/cjs/react-server-dom-webpack-server.node.production.js +803 -183
- package/cjs/react-server-dom-webpack-server.node.unbundled.development.js +1235 -204
- package/cjs/react-server-dom-webpack-server.node.unbundled.production.js +803 -183
- package/package.json +3 -3
@@ -17,8 +17,20 @@ if (process.env.NODE_ENV !== "production") {
|
|
17
17
|
var ReactDOM = require('react-dom');
|
18
18
|
var React = require('react');
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
function _defineProperty(obj, key, value) {
|
21
|
+
if (key in obj) {
|
22
|
+
Object.defineProperty(obj, key, {
|
23
|
+
value: value,
|
24
|
+
enumerable: true,
|
25
|
+
configurable: true,
|
26
|
+
writable: true
|
27
|
+
});
|
28
|
+
} else {
|
29
|
+
obj[key] = value;
|
30
|
+
}
|
31
|
+
|
32
|
+
return obj;
|
33
|
+
}
|
22
34
|
|
23
35
|
function createStringDecoder() {
|
24
36
|
return new TextDecoder();
|
@@ -794,22 +806,13 @@ function describeObjectForErrorMessage(objectOrArray, expandedName) {
|
|
794
806
|
}
|
795
807
|
|
796
808
|
function createTemporaryReferenceSet() {
|
797
|
-
return
|
809
|
+
return new Map();
|
798
810
|
}
|
799
|
-
function writeTemporaryReference(set, object) {
|
800
|
-
|
801
|
-
// object. This ensures that we always generate a deterministic encoding of
|
802
|
-
// each slot in the reply for cacheability.
|
803
|
-
var newId = set.length;
|
804
|
-
set.push(object);
|
805
|
-
return newId;
|
811
|
+
function writeTemporaryReference(set, reference, object) {
|
812
|
+
set.set(reference, object);
|
806
813
|
}
|
807
|
-
function readTemporaryReference(set,
|
808
|
-
|
809
|
-
throw new Error("The RSC response contained a reference that doesn't exist in the temporary reference set. " + 'Always pass the matching set that was used to create the reply when parsing its response.');
|
810
|
-
}
|
811
|
-
|
812
|
-
return set[id];
|
814
|
+
function readTemporaryReference(set, reference) {
|
815
|
+
return set.get(reference);
|
813
816
|
}
|
814
817
|
|
815
818
|
var ObjectPrototype = Object.prototype;
|
@@ -828,8 +831,8 @@ function serializeServerReferenceID(id) {
|
|
828
831
|
return '$F' + id.toString(16);
|
829
832
|
}
|
830
833
|
|
831
|
-
function
|
832
|
-
return '$T'
|
834
|
+
function serializeTemporaryReferenceMarker() {
|
835
|
+
return '$T';
|
833
836
|
}
|
834
837
|
|
835
838
|
function serializeFormDataReference(id) {
|
@@ -877,6 +880,10 @@ function serializeSetID(id) {
|
|
877
880
|
return '$W' + id.toString(16);
|
878
881
|
}
|
879
882
|
|
883
|
+
function serializeBlobID(id) {
|
884
|
+
return '$B' + id.toString(16);
|
885
|
+
}
|
886
|
+
|
880
887
|
function serializeIteratorID(id) {
|
881
888
|
return '$i' + id.toString(16);
|
882
889
|
}
|
@@ -895,6 +902,170 @@ function processReply(root, formFieldPrefix, temporaryReferences, resolve, rejec
|
|
895
902
|
var nextPartId = 1;
|
896
903
|
var pendingParts = 0;
|
897
904
|
var formData = null;
|
905
|
+
var writtenObjects = new WeakMap();
|
906
|
+
var modelRoot = root;
|
907
|
+
|
908
|
+
function serializeTypedArray(tag, typedArray) {
|
909
|
+
var blob = new Blob([// We should be able to pass the buffer straight through but Node < 18 treat
|
910
|
+
// multi-byte array blobs differently so we first convert it to single-byte.
|
911
|
+
new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength)]);
|
912
|
+
var blobId = nextPartId++;
|
913
|
+
|
914
|
+
if (formData === null) {
|
915
|
+
formData = new FormData();
|
916
|
+
}
|
917
|
+
|
918
|
+
formData.append(formFieldPrefix + blobId, blob);
|
919
|
+
return '$' + tag + blobId.toString(16);
|
920
|
+
}
|
921
|
+
|
922
|
+
function serializeBinaryReader(reader) {
|
923
|
+
if (formData === null) {
|
924
|
+
// Upgrade to use FormData to allow us to stream this value.
|
925
|
+
formData = new FormData();
|
926
|
+
}
|
927
|
+
|
928
|
+
var data = formData;
|
929
|
+
pendingParts++;
|
930
|
+
var streamId = nextPartId++;
|
931
|
+
var buffer = [];
|
932
|
+
|
933
|
+
function progress(entry) {
|
934
|
+
if (entry.done) {
|
935
|
+
var blobId = nextPartId++; // eslint-disable-next-line react-internal/safe-string-coercion
|
936
|
+
|
937
|
+
data.append(formFieldPrefix + blobId, new Blob(buffer)); // eslint-disable-next-line react-internal/safe-string-coercion
|
938
|
+
|
939
|
+
data.append(formFieldPrefix + streamId, '"$o' + blobId.toString(16) + '"'); // eslint-disable-next-line react-internal/safe-string-coercion
|
940
|
+
|
941
|
+
data.append(formFieldPrefix + streamId, 'C'); // Close signal
|
942
|
+
|
943
|
+
pendingParts--;
|
944
|
+
|
945
|
+
if (pendingParts === 0) {
|
946
|
+
resolve(data);
|
947
|
+
}
|
948
|
+
} else {
|
949
|
+
buffer.push(entry.value);
|
950
|
+
reader.read(new Uint8Array(1024)).then(progress, reject);
|
951
|
+
}
|
952
|
+
}
|
953
|
+
|
954
|
+
reader.read(new Uint8Array(1024)).then(progress, reject);
|
955
|
+
return '$r' + streamId.toString(16);
|
956
|
+
}
|
957
|
+
|
958
|
+
function serializeReader(reader) {
|
959
|
+
if (formData === null) {
|
960
|
+
// Upgrade to use FormData to allow us to stream this value.
|
961
|
+
formData = new FormData();
|
962
|
+
}
|
963
|
+
|
964
|
+
var data = formData;
|
965
|
+
pendingParts++;
|
966
|
+
var streamId = nextPartId++;
|
967
|
+
|
968
|
+
function progress(entry) {
|
969
|
+
if (entry.done) {
|
970
|
+
// eslint-disable-next-line react-internal/safe-string-coercion
|
971
|
+
data.append(formFieldPrefix + streamId, 'C'); // Close signal
|
972
|
+
|
973
|
+
pendingParts--;
|
974
|
+
|
975
|
+
if (pendingParts === 0) {
|
976
|
+
resolve(data);
|
977
|
+
}
|
978
|
+
} else {
|
979
|
+
try {
|
980
|
+
// $FlowFixMe[incompatible-type]: While plain JSON can return undefined we never do here.
|
981
|
+
var partJSON = JSON.stringify(entry.value, resolveToJSON); // eslint-disable-next-line react-internal/safe-string-coercion
|
982
|
+
|
983
|
+
data.append(formFieldPrefix + streamId, partJSON);
|
984
|
+
reader.read().then(progress, reject);
|
985
|
+
} catch (x) {
|
986
|
+
reject(x);
|
987
|
+
}
|
988
|
+
}
|
989
|
+
}
|
990
|
+
|
991
|
+
reader.read().then(progress, reject);
|
992
|
+
return '$R' + streamId.toString(16);
|
993
|
+
}
|
994
|
+
|
995
|
+
function serializeReadableStream(stream) {
|
996
|
+
// Detect if this is a BYOB stream. BYOB streams should be able to be read as bytes on the
|
997
|
+
// receiving side. For binary streams, we serialize them as plain Blobs.
|
998
|
+
var binaryReader;
|
999
|
+
|
1000
|
+
try {
|
1001
|
+
// $FlowFixMe[extra-arg]: This argument is accepted.
|
1002
|
+
binaryReader = stream.getReader({
|
1003
|
+
mode: 'byob'
|
1004
|
+
});
|
1005
|
+
} catch (x) {
|
1006
|
+
return serializeReader(stream.getReader());
|
1007
|
+
}
|
1008
|
+
|
1009
|
+
return serializeBinaryReader(binaryReader);
|
1010
|
+
}
|
1011
|
+
|
1012
|
+
function serializeAsyncIterable(iterable, iterator) {
|
1013
|
+
if (formData === null) {
|
1014
|
+
// Upgrade to use FormData to allow us to stream this value.
|
1015
|
+
formData = new FormData();
|
1016
|
+
}
|
1017
|
+
|
1018
|
+
var data = formData;
|
1019
|
+
pendingParts++;
|
1020
|
+
var streamId = nextPartId++; // Generators/Iterators are Iterables but they're also their own iterator
|
1021
|
+
// functions. If that's the case, we treat them as single-shot. Otherwise,
|
1022
|
+
// we assume that this iterable might be a multi-shot and allow it to be
|
1023
|
+
// iterated more than once on the receiving server.
|
1024
|
+
|
1025
|
+
var isIterator = iterable === iterator; // There's a race condition between when the stream is aborted and when the promise
|
1026
|
+
// resolves so we track whether we already aborted it to avoid writing twice.
|
1027
|
+
|
1028
|
+
function progress(entry) {
|
1029
|
+
if (entry.done) {
|
1030
|
+
if (entry.value === undefined) {
|
1031
|
+
// eslint-disable-next-line react-internal/safe-string-coercion
|
1032
|
+
data.append(formFieldPrefix + streamId, 'C'); // Close signal
|
1033
|
+
} else {
|
1034
|
+
// Unlike streams, the last value may not be undefined. If it's not
|
1035
|
+
// we outline it and encode a reference to it in the closing instruction.
|
1036
|
+
try {
|
1037
|
+
// $FlowFixMe[incompatible-type]: While plain JSON can return undefined we never do here.
|
1038
|
+
var partJSON = JSON.stringify(entry.value, resolveToJSON);
|
1039
|
+
data.append(formFieldPrefix + streamId, 'C' + partJSON); // Close signal
|
1040
|
+
} catch (x) {
|
1041
|
+
reject(x);
|
1042
|
+
return;
|
1043
|
+
}
|
1044
|
+
}
|
1045
|
+
|
1046
|
+
pendingParts--;
|
1047
|
+
|
1048
|
+
if (pendingParts === 0) {
|
1049
|
+
resolve(data);
|
1050
|
+
}
|
1051
|
+
} else {
|
1052
|
+
try {
|
1053
|
+
// $FlowFixMe[incompatible-type]: While plain JSON can return undefined we never do here.
|
1054
|
+
var _partJSON = JSON.stringify(entry.value, resolveToJSON); // eslint-disable-next-line react-internal/safe-string-coercion
|
1055
|
+
|
1056
|
+
|
1057
|
+
data.append(formFieldPrefix + streamId, _partJSON);
|
1058
|
+
iterator.next().then(progress, reject);
|
1059
|
+
} catch (x) {
|
1060
|
+
reject(x);
|
1061
|
+
return;
|
1062
|
+
}
|
1063
|
+
}
|
1064
|
+
}
|
1065
|
+
|
1066
|
+
iterator.next().then(progress, reject);
|
1067
|
+
return '$' + (isIterator ? 'x' : 'X') + streamId.toString(16);
|
1068
|
+
}
|
898
1069
|
|
899
1070
|
function resolveToJSON(key, value) {
|
900
1071
|
var parent = this; // Make sure that `parent[key]` wasn't JSONified before `value` was passed to us
|
@@ -920,11 +1091,21 @@ function processReply(root, formFieldPrefix, temporaryReferences, resolve, rejec
|
|
920
1091
|
switch (value.$$typeof) {
|
921
1092
|
case REACT_ELEMENT_TYPE:
|
922
1093
|
{
|
923
|
-
if (temporaryReferences
|
924
|
-
|
1094
|
+
if (temporaryReferences !== undefined && key.indexOf(':') === -1) {
|
1095
|
+
// TODO: If the property name contains a colon, we don't dedupe. Escape instead.
|
1096
|
+
var parentReference = writtenObjects.get(parent);
|
1097
|
+
|
1098
|
+
if (parentReference !== undefined) {
|
1099
|
+
// If the parent has a reference, we can refer to this object indirectly
|
1100
|
+
// through the property name inside that parent.
|
1101
|
+
var reference = parentReference + ':' + key; // Store this object so that the server can refer to it later in responses.
|
1102
|
+
|
1103
|
+
writeTemporaryReference(temporaryReferences, reference, value);
|
1104
|
+
return serializeTemporaryReferenceMarker();
|
1105
|
+
}
|
925
1106
|
}
|
926
1107
|
|
927
|
-
|
1108
|
+
throw new Error('React Element cannot be passed to Server Functions from the Client without a ' + 'temporary reference set. Pass a TemporaryReferenceSet to the options.' + (describeObjectForErrorMessage(parent, key) ));
|
928
1109
|
}
|
929
1110
|
|
930
1111
|
case REACT_LAZY_TYPE:
|
@@ -946,7 +1127,7 @@ function processReply(root, formFieldPrefix, temporaryReferences, resolve, rejec
|
|
946
1127
|
// because it ensures a more deterministic encoding.
|
947
1128
|
|
948
1129
|
var lazyId = nextPartId++;
|
949
|
-
var partJSON =
|
1130
|
+
var partJSON = serializeModel(resolvedModel, lazyId); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
950
1131
|
|
951
1132
|
var data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
|
952
1133
|
|
@@ -965,7 +1146,7 @@ function processReply(root, formFieldPrefix, temporaryReferences, resolve, rejec
|
|
965
1146
|
// While the first promise resolved, its value isn't necessarily what we'll
|
966
1147
|
// resolve into because we might suspend again.
|
967
1148
|
try {
|
968
|
-
var _partJSON2 =
|
1149
|
+
var _partJSON2 = serializeModel(value, _lazyId); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
969
1150
|
|
970
1151
|
|
971
1152
|
var _data = formData; // eslint-disable-next-line react-internal/safe-string-coercion
|
@@ -1011,7 +1192,7 @@ function processReply(root, formFieldPrefix, temporaryReferences, resolve, rejec
|
|
1011
1192
|
|
1012
1193
|
_thenable.then(function (partValue) {
|
1013
1194
|
try {
|
1014
|
-
var _partJSON3 =
|
1195
|
+
var _partJSON3 = serializeModel(partValue, promiseId); // $FlowFixMe[incompatible-type] We know it's not null because we assigned it above.
|
1015
1196
|
|
1016
1197
|
|
1017
1198
|
var _data2 = formData; // eslint-disable-next-line react-internal/safe-string-coercion
|
@@ -1033,6 +1214,36 @@ function processReply(root, formFieldPrefix, temporaryReferences, resolve, rejec
|
|
1033
1214
|
return serializePromiseID(promiseId);
|
1034
1215
|
}
|
1035
1216
|
|
1217
|
+
var existingReference = writtenObjects.get(value);
|
1218
|
+
|
1219
|
+
if (existingReference !== undefined) {
|
1220
|
+
if (modelRoot === value) {
|
1221
|
+
// This is the ID we're currently emitting so we need to write it
|
1222
|
+
// once but if we discover it again, we refer to it by id.
|
1223
|
+
modelRoot = null;
|
1224
|
+
} else {
|
1225
|
+
// We've already emitted this as an outlined object, so we can
|
1226
|
+
// just refer to that by its existing ID.
|
1227
|
+
return existingReference;
|
1228
|
+
}
|
1229
|
+
} else if (key.indexOf(':') === -1) {
|
1230
|
+
// TODO: If the property name contains a colon, we don't dedupe. Escape instead.
|
1231
|
+
var _parentReference = writtenObjects.get(parent);
|
1232
|
+
|
1233
|
+
if (_parentReference !== undefined) {
|
1234
|
+
// If the parent has a reference, we can refer to this object indirectly
|
1235
|
+
// through the property name inside that parent.
|
1236
|
+
var _reference = _parentReference + ':' + key;
|
1237
|
+
|
1238
|
+
writtenObjects.set(value, _reference);
|
1239
|
+
|
1240
|
+
if (temporaryReferences !== undefined) {
|
1241
|
+
// Store this object so that the server can refer to it later in responses.
|
1242
|
+
writeTemporaryReference(temporaryReferences, _reference, value);
|
1243
|
+
}
|
1244
|
+
}
|
1245
|
+
}
|
1246
|
+
|
1036
1247
|
if (isArray(value)) {
|
1037
1248
|
// $FlowFixMe[incompatible-return]
|
1038
1249
|
return value;
|
@@ -1059,29 +1270,117 @@ function processReply(root, formFieldPrefix, temporaryReferences, resolve, rejec
|
|
1059
1270
|
}
|
1060
1271
|
|
1061
1272
|
if (value instanceof Map) {
|
1062
|
-
var
|
1273
|
+
var mapId = nextPartId++;
|
1274
|
+
|
1275
|
+
var _partJSON4 = serializeModel(Array.from(value), mapId);
|
1063
1276
|
|
1064
1277
|
if (formData === null) {
|
1065
1278
|
formData = new FormData();
|
1066
1279
|
}
|
1067
1280
|
|
1068
|
-
var mapId = nextPartId++;
|
1069
1281
|
formData.append(formFieldPrefix + mapId, _partJSON4);
|
1070
1282
|
return serializeMapID(mapId);
|
1071
1283
|
}
|
1072
1284
|
|
1073
1285
|
if (value instanceof Set) {
|
1074
|
-
var
|
1286
|
+
var setId = nextPartId++;
|
1287
|
+
|
1288
|
+
var _partJSON5 = serializeModel(Array.from(value), setId);
|
1075
1289
|
|
1076
1290
|
if (formData === null) {
|
1077
1291
|
formData = new FormData();
|
1078
1292
|
}
|
1079
1293
|
|
1080
|
-
var setId = nextPartId++;
|
1081
1294
|
formData.append(formFieldPrefix + setId, _partJSON5);
|
1082
1295
|
return serializeSetID(setId);
|
1083
1296
|
}
|
1084
1297
|
|
1298
|
+
{
|
1299
|
+
if (value instanceof ArrayBuffer) {
|
1300
|
+
var blob = new Blob([value]);
|
1301
|
+
var blobId = nextPartId++;
|
1302
|
+
|
1303
|
+
if (formData === null) {
|
1304
|
+
formData = new FormData();
|
1305
|
+
}
|
1306
|
+
|
1307
|
+
formData.append(formFieldPrefix + blobId, blob);
|
1308
|
+
return '$' + 'A' + blobId.toString(16);
|
1309
|
+
}
|
1310
|
+
|
1311
|
+
if (value instanceof Int8Array) {
|
1312
|
+
// char
|
1313
|
+
return serializeTypedArray('O', value);
|
1314
|
+
}
|
1315
|
+
|
1316
|
+
if (value instanceof Uint8Array) {
|
1317
|
+
// unsigned char
|
1318
|
+
return serializeTypedArray('o', value);
|
1319
|
+
}
|
1320
|
+
|
1321
|
+
if (value instanceof Uint8ClampedArray) {
|
1322
|
+
// unsigned clamped char
|
1323
|
+
return serializeTypedArray('U', value);
|
1324
|
+
}
|
1325
|
+
|
1326
|
+
if (value instanceof Int16Array) {
|
1327
|
+
// sort
|
1328
|
+
return serializeTypedArray('S', value);
|
1329
|
+
}
|
1330
|
+
|
1331
|
+
if (value instanceof Uint16Array) {
|
1332
|
+
// unsigned short
|
1333
|
+
return serializeTypedArray('s', value);
|
1334
|
+
}
|
1335
|
+
|
1336
|
+
if (value instanceof Int32Array) {
|
1337
|
+
// long
|
1338
|
+
return serializeTypedArray('L', value);
|
1339
|
+
}
|
1340
|
+
|
1341
|
+
if (value instanceof Uint32Array) {
|
1342
|
+
// unsigned long
|
1343
|
+
return serializeTypedArray('l', value);
|
1344
|
+
}
|
1345
|
+
|
1346
|
+
if (value instanceof Float32Array) {
|
1347
|
+
// float
|
1348
|
+
return serializeTypedArray('G', value);
|
1349
|
+
}
|
1350
|
+
|
1351
|
+
if (value instanceof Float64Array) {
|
1352
|
+
// double
|
1353
|
+
return serializeTypedArray('g', value);
|
1354
|
+
}
|
1355
|
+
|
1356
|
+
if (value instanceof BigInt64Array) {
|
1357
|
+
// number
|
1358
|
+
return serializeTypedArray('M', value);
|
1359
|
+
}
|
1360
|
+
|
1361
|
+
if (value instanceof BigUint64Array) {
|
1362
|
+
// unsigned number
|
1363
|
+
// We use "m" instead of "n" since JSON can start with "null"
|
1364
|
+
return serializeTypedArray('m', value);
|
1365
|
+
}
|
1366
|
+
|
1367
|
+
if (value instanceof DataView) {
|
1368
|
+
return serializeTypedArray('V', value);
|
1369
|
+
} // TODO: Blob is not available in old Node/browsers. Remove the typeof check later.
|
1370
|
+
|
1371
|
+
|
1372
|
+
if (typeof Blob === 'function' && value instanceof Blob) {
|
1373
|
+
if (formData === null) {
|
1374
|
+
formData = new FormData();
|
1375
|
+
}
|
1376
|
+
|
1377
|
+
var _blobId = nextPartId++;
|
1378
|
+
|
1379
|
+
formData.append(formFieldPrefix + _blobId, value);
|
1380
|
+
return serializeBlobID(_blobId);
|
1381
|
+
}
|
1382
|
+
}
|
1383
|
+
|
1085
1384
|
var iteratorFn = getIteratorFn(value);
|
1086
1385
|
|
1087
1386
|
if (iteratorFn) {
|
@@ -1089,13 +1388,14 @@ function processReply(root, formFieldPrefix, temporaryReferences, resolve, rejec
|
|
1089
1388
|
|
1090
1389
|
if (iterator === value) {
|
1091
1390
|
// Iterator, not Iterable
|
1092
|
-
var
|
1391
|
+
var iteratorId = nextPartId++;
|
1392
|
+
|
1393
|
+
var _partJSON6 = serializeModel(Array.from(iterator), iteratorId);
|
1093
1394
|
|
1094
1395
|
if (formData === null) {
|
1095
1396
|
formData = new FormData();
|
1096
1397
|
}
|
1097
1398
|
|
1098
|
-
var iteratorId = nextPartId++;
|
1099
1399
|
formData.append(formFieldPrefix + iteratorId, _partJSON6);
|
1100
1400
|
return serializeIteratorID(iteratorId);
|
1101
1401
|
}
|
@@ -1103,16 +1403,31 @@ function processReply(root, formFieldPrefix, temporaryReferences, resolve, rejec
|
|
1103
1403
|
return Array.from(iterator);
|
1104
1404
|
}
|
1105
1405
|
|
1406
|
+
{
|
1407
|
+
// TODO: ReadableStream is not available in old Node. Remove the typeof check later.
|
1408
|
+
if (typeof ReadableStream === 'function' && value instanceof ReadableStream) {
|
1409
|
+
return serializeReadableStream(value);
|
1410
|
+
}
|
1411
|
+
|
1412
|
+
var getAsyncIterator = value[ASYNC_ITERATOR];
|
1413
|
+
|
1414
|
+
if (typeof getAsyncIterator === 'function') {
|
1415
|
+
// We treat AsyncIterables as a Fragment and as such we might need to key them.
|
1416
|
+
return serializeAsyncIterable(value, getAsyncIterator.call(value));
|
1417
|
+
}
|
1418
|
+
} // Verify that this is a simple plain object.
|
1419
|
+
|
1106
1420
|
|
1107
1421
|
var proto = getPrototypeOf(value);
|
1108
1422
|
|
1109
1423
|
if (proto !== ObjectPrototype && (proto === null || getPrototypeOf(proto) !== null)) {
|
1110
1424
|
if (temporaryReferences === undefined) {
|
1111
1425
|
throw new Error('Only plain objects, and a few built-ins, can be passed to Server Actions. ' + 'Classes or null prototypes are not supported.');
|
1112
|
-
} // We
|
1426
|
+
} // We will have written this object to the temporary reference set above
|
1427
|
+
// so we can replace it with a marker to refer to this slot later.
|
1113
1428
|
|
1114
1429
|
|
1115
|
-
return
|
1430
|
+
return serializeTemporaryReferenceMarker();
|
1116
1431
|
}
|
1117
1432
|
|
1118
1433
|
{
|
@@ -1181,19 +1496,41 @@ function processReply(root, formFieldPrefix, temporaryReferences, resolve, rejec
|
|
1181
1496
|
return serializeServerReferenceID(_refId);
|
1182
1497
|
}
|
1183
1498
|
|
1184
|
-
if (temporaryReferences
|
1185
|
-
|
1499
|
+
if (temporaryReferences !== undefined && key.indexOf(':') === -1) {
|
1500
|
+
// TODO: If the property name contains a colon, we don't dedupe. Escape instead.
|
1501
|
+
var _parentReference2 = writtenObjects.get(parent);
|
1502
|
+
|
1503
|
+
if (_parentReference2 !== undefined) {
|
1504
|
+
// If the parent has a reference, we can refer to this object indirectly
|
1505
|
+
// through the property name inside that parent.
|
1506
|
+
var _reference2 = _parentReference2 + ':' + key; // Store this object so that the server can refer to it later in responses.
|
1507
|
+
|
1508
|
+
|
1509
|
+
writeTemporaryReference(temporaryReferences, _reference2, value);
|
1510
|
+
return serializeTemporaryReferenceMarker();
|
1511
|
+
}
|
1186
1512
|
}
|
1187
1513
|
|
1188
|
-
|
1514
|
+
throw new Error('Client Functions cannot be passed directly to Server Functions. ' + 'Only Functions passed from the Server can be passed back again.');
|
1189
1515
|
}
|
1190
1516
|
|
1191
1517
|
if (typeof value === 'symbol') {
|
1192
|
-
if (temporaryReferences
|
1193
|
-
|
1518
|
+
if (temporaryReferences !== undefined && key.indexOf(':') === -1) {
|
1519
|
+
// TODO: If the property name contains a colon, we don't dedupe. Escape instead.
|
1520
|
+
var _parentReference3 = writtenObjects.get(parent);
|
1521
|
+
|
1522
|
+
if (_parentReference3 !== undefined) {
|
1523
|
+
// If the parent has a reference, we can refer to this object indirectly
|
1524
|
+
// through the property name inside that parent.
|
1525
|
+
var _reference3 = _parentReference3 + ':' + key; // Store this object so that the server can refer to it later in responses.
|
1526
|
+
|
1527
|
+
|
1528
|
+
writeTemporaryReference(temporaryReferences, _reference3, value);
|
1529
|
+
return serializeTemporaryReferenceMarker();
|
1530
|
+
}
|
1194
1531
|
}
|
1195
1532
|
|
1196
|
-
|
1533
|
+
throw new Error('Symbols cannot be passed to a Server Function without a ' + 'temporary reference set. Pass a TemporaryReferenceSet to the options.' + (describeObjectForErrorMessage(parent, key) ));
|
1197
1534
|
}
|
1198
1535
|
|
1199
1536
|
if (typeof value === 'bigint') {
|
@@ -1201,10 +1538,25 @@ function processReply(root, formFieldPrefix, temporaryReferences, resolve, rejec
|
|
1201
1538
|
}
|
1202
1539
|
|
1203
1540
|
throw new Error("Type " + typeof value + " is not supported as an argument to a Server Function.");
|
1204
|
-
}
|
1541
|
+
}
|
1542
|
+
|
1543
|
+
function serializeModel(model, id) {
|
1544
|
+
if (typeof model === 'object' && model !== null) {
|
1545
|
+
var reference = serializeByValueID(id);
|
1546
|
+
writtenObjects.set(model, reference);
|
1547
|
+
|
1548
|
+
if (temporaryReferences !== undefined) {
|
1549
|
+
// Store this object so that the server can refer to it later in responses.
|
1550
|
+
writeTemporaryReference(temporaryReferences, reference, model);
|
1551
|
+
}
|
1552
|
+
}
|
1205
1553
|
|
1554
|
+
modelRoot = model; // $FlowFixMe[incompatible-return] it's not going to be undefined because we'll encode it.
|
1206
1555
|
|
1207
|
-
|
1556
|
+
return JSON.stringify(model, resolveToJSON);
|
1557
|
+
}
|
1558
|
+
|
1559
|
+
var json = serializeModel(root, 0);
|
1208
1560
|
|
1209
1561
|
if (formData === null) {
|
1210
1562
|
// If it's a simple data structure, we just use plain JSON.
|
@@ -1396,6 +1748,14 @@ function wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners) {
|
|
1396
1748
|
|
1397
1749
|
function triggerErrorOnChunk(chunk, error) {
|
1398
1750
|
if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
|
1751
|
+
{
|
1752
|
+
// If we get more data to an already resolved ID, we assume that it's
|
1753
|
+
// a stream chunk since any other row shouldn't have more than one entry.
|
1754
|
+
var streamChunk = chunk;
|
1755
|
+
var controller = streamChunk.reason; // $FlowFixMe[incompatible-call]: The error method should accept mixed.
|
1756
|
+
|
1757
|
+
controller.error(error);
|
1758
|
+
}
|
1399
1759
|
|
1400
1760
|
return;
|
1401
1761
|
}
|
@@ -1425,8 +1785,48 @@ function createInitializedTextChunk(response, value) {
|
|
1425
1785
|
return new Chunk(INITIALIZED, value, null, response);
|
1426
1786
|
}
|
1427
1787
|
|
1788
|
+
function createInitializedBufferChunk(response, value) {
|
1789
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
1790
|
+
return new Chunk(INITIALIZED, value, null, response);
|
1791
|
+
}
|
1792
|
+
|
1793
|
+
function createInitializedIteratorResultChunk(response, value, done) {
|
1794
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
1795
|
+
return new Chunk(INITIALIZED, {
|
1796
|
+
done: done,
|
1797
|
+
value: value
|
1798
|
+
}, null, response);
|
1799
|
+
}
|
1800
|
+
|
1801
|
+
function createInitializedStreamChunk(response, value, controller) {
|
1802
|
+
// We use the reason field to stash the controller since we already have that
|
1803
|
+
// field. It's a bit of a hack but efficient.
|
1804
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
1805
|
+
return new Chunk(INITIALIZED, value, controller, response);
|
1806
|
+
}
|
1807
|
+
|
1808
|
+
function createResolvedIteratorResultChunk(response, value, done) {
|
1809
|
+
// To reuse code as much code as possible we add the wrapper element as part of the JSON.
|
1810
|
+
var iteratorResultJSON = (done ? '{"done":true,"value":' : '{"done":false,"value":') + value + '}'; // $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
1811
|
+
|
1812
|
+
return new Chunk(RESOLVED_MODEL, iteratorResultJSON, null, response);
|
1813
|
+
}
|
1814
|
+
|
1815
|
+
function resolveIteratorResultChunk(chunk, value, done) {
|
1816
|
+
// To reuse code as much code as possible we add the wrapper element as part of the JSON.
|
1817
|
+
var iteratorResultJSON = (done ? '{"done":true,"value":' : '{"done":false,"value":') + value + '}';
|
1818
|
+
resolveModelChunk(chunk, iteratorResultJSON);
|
1819
|
+
}
|
1820
|
+
|
1428
1821
|
function resolveModelChunk(chunk, value) {
|
1429
1822
|
if (chunk.status !== PENDING) {
|
1823
|
+
{
|
1824
|
+
// If we get more data to an already resolved ID, we assume that it's
|
1825
|
+
// a stream chunk since any other row shouldn't have more than one entry.
|
1826
|
+
var streamChunk = chunk;
|
1827
|
+
var controller = streamChunk.reason;
|
1828
|
+
controller.enqueueModel(value);
|
1829
|
+
}
|
1430
1830
|
|
1431
1831
|
return;
|
1432
1832
|
}
|
@@ -1545,7 +1945,8 @@ function nullRefGetter() {
|
|
1545
1945
|
}
|
1546
1946
|
}
|
1547
1947
|
|
1548
|
-
function createElement(type, key, props, owner
|
1948
|
+
function createElement(type, key, props, owner, // DEV-only
|
1949
|
+
stack) // DEV-only
|
1549
1950
|
{
|
1550
1951
|
var element;
|
1551
1952
|
|
@@ -1583,6 +1984,10 @@ function createElement(type, key, props, owner) // DEV-only
|
|
1583
1984
|
writable: true,
|
1584
1985
|
value: null
|
1585
1986
|
});
|
1987
|
+
// _debugInfo later. We could move it into _store which remains mutable.
|
1988
|
+
|
1989
|
+
|
1990
|
+
Object.freeze(element.props);
|
1586
1991
|
}
|
1587
1992
|
|
1588
1993
|
return element;
|
@@ -1616,7 +2021,7 @@ function getChunk(response, id) {
|
|
1616
2021
|
return chunk;
|
1617
2022
|
}
|
1618
2023
|
|
1619
|
-
function createModelResolver(chunk, parentObject, key, cyclic, response, map) {
|
2024
|
+
function createModelResolver(chunk, parentObject, key, cyclic, response, map, path) {
|
1620
2025
|
var blocked;
|
1621
2026
|
|
1622
2027
|
if (initializingChunkBlockedModel) {
|
@@ -1633,6 +2038,10 @@ function createModelResolver(chunk, parentObject, key, cyclic, response, map) {
|
|
1633
2038
|
}
|
1634
2039
|
|
1635
2040
|
return function (value) {
|
2041
|
+
for (var i = 1; i < path.length; i++) {
|
2042
|
+
value = value[path[i]];
|
2043
|
+
}
|
2044
|
+
|
1636
2045
|
parentObject[key] = map(response, value); // If this is the root object for a model reference, where `blocked.value`
|
1637
2046
|
// is a stale `null`, the resolved value can be used directly.
|
1638
2047
|
|
@@ -1693,7 +2102,9 @@ function createServerReferenceProxy(response, metaData) {
|
|
1693
2102
|
return proxy;
|
1694
2103
|
}
|
1695
2104
|
|
1696
|
-
function getOutlinedModel(response,
|
2105
|
+
function getOutlinedModel(response, reference, parentObject, key, map) {
|
2106
|
+
var path = reference.split(':');
|
2107
|
+
var id = parseInt(path[0], 16);
|
1697
2108
|
var chunk = getChunk(response, id);
|
1698
2109
|
|
1699
2110
|
switch (chunk.status) {
|
@@ -1709,7 +2120,13 @@ function getOutlinedModel(response, id, parentObject, key, map) {
|
|
1709
2120
|
|
1710
2121
|
switch (chunk.status) {
|
1711
2122
|
case INITIALIZED:
|
1712
|
-
var
|
2123
|
+
var value = chunk.value;
|
2124
|
+
|
2125
|
+
for (var i = 1; i < path.length; i++) {
|
2126
|
+
value = value[path[i]];
|
2127
|
+
}
|
2128
|
+
|
2129
|
+
var chunkValue = map(response, value);
|
1713
2130
|
|
1714
2131
|
if (chunk._debugInfo) {
|
1715
2132
|
// If we have a direct reference to an object that was rendered by a synchronous
|
@@ -1737,7 +2154,7 @@ function getOutlinedModel(response, id, parentObject, key, map) {
|
|
1737
2154
|
case BLOCKED:
|
1738
2155
|
case CYCLIC:
|
1739
2156
|
var parentChunk = initializingChunk;
|
1740
|
-
chunk.then(createModelResolver(parentChunk, parentObject, key, chunk.status === CYCLIC, response, map), createModelReject(parentChunk));
|
2157
|
+
chunk.then(createModelResolver(parentChunk, parentObject, key, chunk.status === CYCLIC, response, map, path), createModelReject(parentChunk));
|
1741
2158
|
return null;
|
1742
2159
|
|
1743
2160
|
default:
|
@@ -1753,6 +2170,12 @@ function createSet(response, model) {
|
|
1753
2170
|
return new Set(model);
|
1754
2171
|
}
|
1755
2172
|
|
2173
|
+
function createBlob(response, model) {
|
2174
|
+
return new Blob(model.slice(1), {
|
2175
|
+
type: model[0]
|
2176
|
+
});
|
2177
|
+
}
|
2178
|
+
|
1756
2179
|
function createFormData(response, model) {
|
1757
2180
|
var formData = new FormData();
|
1758
2181
|
|
@@ -1820,61 +2243,63 @@ function parseModelString(response, parentObject, key, value) {
|
|
1820
2243
|
case 'F':
|
1821
2244
|
{
|
1822
2245
|
// Server Reference
|
1823
|
-
var
|
1824
|
-
|
1825
|
-
return getOutlinedModel(response, _id2, parentObject, key, createServerReferenceProxy);
|
2246
|
+
var ref = value.slice(2);
|
2247
|
+
return getOutlinedModel(response, ref, parentObject, key, createServerReferenceProxy);
|
1826
2248
|
}
|
1827
2249
|
|
1828
2250
|
case 'T':
|
1829
2251
|
{
|
1830
2252
|
// Temporary Reference
|
1831
|
-
var
|
1832
|
-
|
2253
|
+
var reference = '$' + value.slice(2);
|
1833
2254
|
var temporaryReferences = response._tempRefs;
|
1834
2255
|
|
1835
2256
|
if (temporaryReferences == null) {
|
1836
2257
|
throw new Error('Missing a temporary reference set but the RSC response returned a temporary reference. ' + 'Pass a temporaryReference option with the set that was used with the reply.');
|
1837
2258
|
}
|
1838
2259
|
|
1839
|
-
return readTemporaryReference(temporaryReferences,
|
2260
|
+
return readTemporaryReference(temporaryReferences, reference);
|
1840
2261
|
}
|
1841
2262
|
|
1842
2263
|
case 'Q':
|
1843
2264
|
{
|
1844
2265
|
// Map
|
1845
|
-
var
|
2266
|
+
var _ref = value.slice(2);
|
1846
2267
|
|
1847
|
-
return getOutlinedModel(response,
|
2268
|
+
return getOutlinedModel(response, _ref, parentObject, key, createMap);
|
1848
2269
|
}
|
1849
2270
|
|
1850
2271
|
case 'W':
|
1851
2272
|
{
|
1852
2273
|
// Set
|
1853
|
-
var
|
2274
|
+
var _ref2 = value.slice(2);
|
1854
2275
|
|
1855
|
-
return getOutlinedModel(response,
|
2276
|
+
return getOutlinedModel(response, _ref2, parentObject, key, createSet);
|
1856
2277
|
}
|
1857
2278
|
|
1858
2279
|
case 'B':
|
1859
2280
|
{
|
2281
|
+
// Blob
|
2282
|
+
{
|
2283
|
+
var _ref3 = value.slice(2);
|
1860
2284
|
|
1861
|
-
|
2285
|
+
return getOutlinedModel(response, _ref3, parentObject, key, createBlob);
|
2286
|
+
}
|
1862
2287
|
}
|
1863
2288
|
|
1864
2289
|
case 'K':
|
1865
2290
|
{
|
1866
2291
|
// FormData
|
1867
|
-
var
|
2292
|
+
var _ref4 = value.slice(2);
|
1868
2293
|
|
1869
|
-
return getOutlinedModel(response,
|
2294
|
+
return getOutlinedModel(response, _ref4, parentObject, key, createFormData);
|
1870
2295
|
}
|
1871
2296
|
|
1872
2297
|
case 'i':
|
1873
2298
|
{
|
1874
2299
|
// Iterator
|
1875
|
-
var
|
2300
|
+
var _ref5 = value.slice(2);
|
1876
2301
|
|
1877
|
-
return getOutlinedModel(response,
|
2302
|
+
return getOutlinedModel(response, _ref5, parentObject, key, extractIterator);
|
1878
2303
|
}
|
1879
2304
|
|
1880
2305
|
case 'I':
|
@@ -1938,9 +2363,9 @@ function parseModelString(response, parentObject, key, value) {
|
|
1938
2363
|
default:
|
1939
2364
|
{
|
1940
2365
|
// We assume that anything else is a reference ID.
|
1941
|
-
var
|
2366
|
+
var _ref6 = value.slice(1);
|
1942
2367
|
|
1943
|
-
return getOutlinedModel(response,
|
2368
|
+
return getOutlinedModel(response, _ref6, parentObject, key, createModel);
|
1944
2369
|
}
|
1945
2370
|
}
|
1946
2371
|
}
|
@@ -2001,9 +2426,41 @@ function resolveModel(response, id, model) {
|
|
2001
2426
|
function resolveText(response, id, text) {
|
2002
2427
|
var chunks = response._chunks;
|
2003
2428
|
|
2429
|
+
{
|
2430
|
+
var chunk = chunks.get(id);
|
2431
|
+
|
2432
|
+
if (chunk && chunk.status !== PENDING) {
|
2433
|
+
// If we get more data to an already resolved ID, we assume that it's
|
2434
|
+
// a stream chunk since any other row shouldn't have more than one entry.
|
2435
|
+
var streamChunk = chunk;
|
2436
|
+
var controller = streamChunk.reason;
|
2437
|
+
controller.enqueueValue(text);
|
2438
|
+
return;
|
2439
|
+
}
|
2440
|
+
}
|
2441
|
+
|
2004
2442
|
chunks.set(id, createInitializedTextChunk(response, text));
|
2005
2443
|
}
|
2006
2444
|
|
2445
|
+
function resolveBuffer(response, id, buffer) {
|
2446
|
+
var chunks = response._chunks;
|
2447
|
+
|
2448
|
+
{
|
2449
|
+
var chunk = chunks.get(id);
|
2450
|
+
|
2451
|
+
if (chunk && chunk.status !== PENDING) {
|
2452
|
+
// If we get more data to an already resolved ID, we assume that it's
|
2453
|
+
// a stream chunk since any other row shouldn't have more than one entry.
|
2454
|
+
var streamChunk = chunk;
|
2455
|
+
var controller = streamChunk.reason;
|
2456
|
+
controller.enqueueValue(buffer);
|
2457
|
+
return;
|
2458
|
+
}
|
2459
|
+
}
|
2460
|
+
|
2461
|
+
chunks.set(id, createInitializedBufferChunk(response, buffer));
|
2462
|
+
}
|
2463
|
+
|
2007
2464
|
function resolveModule(response, id, model) {
|
2008
2465
|
var chunks = response._chunks;
|
2009
2466
|
var chunk = chunks.get(id);
|
@@ -2045,6 +2502,245 @@ function resolveModule(response, id, model) {
|
|
2045
2502
|
}
|
2046
2503
|
}
|
2047
2504
|
|
2505
|
+
function resolveStream(response, id, stream, controller) {
|
2506
|
+
var chunks = response._chunks;
|
2507
|
+
var chunk = chunks.get(id);
|
2508
|
+
|
2509
|
+
if (!chunk) {
|
2510
|
+
chunks.set(id, createInitializedStreamChunk(response, stream, controller));
|
2511
|
+
return;
|
2512
|
+
}
|
2513
|
+
|
2514
|
+
if (chunk.status !== PENDING) {
|
2515
|
+
// We already resolved. We didn't expect to see this.
|
2516
|
+
return;
|
2517
|
+
}
|
2518
|
+
|
2519
|
+
var resolveListeners = chunk.value;
|
2520
|
+
var resolvedChunk = chunk;
|
2521
|
+
resolvedChunk.status = INITIALIZED;
|
2522
|
+
resolvedChunk.value = stream;
|
2523
|
+
resolvedChunk.reason = controller;
|
2524
|
+
|
2525
|
+
if (resolveListeners !== null) {
|
2526
|
+
wakeChunk(resolveListeners, chunk.value);
|
2527
|
+
}
|
2528
|
+
}
|
2529
|
+
|
2530
|
+
function startReadableStream(response, id, type) {
|
2531
|
+
var controller = null;
|
2532
|
+
var stream = new ReadableStream({
|
2533
|
+
type: type,
|
2534
|
+
start: function (c) {
|
2535
|
+
controller = c;
|
2536
|
+
}
|
2537
|
+
});
|
2538
|
+
var previousBlockedChunk = null;
|
2539
|
+
var flightController = {
|
2540
|
+
enqueueValue: function (value) {
|
2541
|
+
if (previousBlockedChunk === null) {
|
2542
|
+
controller.enqueue(value);
|
2543
|
+
} else {
|
2544
|
+
// We're still waiting on a previous chunk so we can't enqueue quite yet.
|
2545
|
+
previousBlockedChunk.then(function () {
|
2546
|
+
controller.enqueue(value);
|
2547
|
+
});
|
2548
|
+
}
|
2549
|
+
},
|
2550
|
+
enqueueModel: function (json) {
|
2551
|
+
if (previousBlockedChunk === null) {
|
2552
|
+
// If we're not blocked on any other chunks, we can try to eagerly initialize
|
2553
|
+
// this as a fast-path to avoid awaiting them.
|
2554
|
+
var chunk = createResolvedModelChunk(response, json);
|
2555
|
+
initializeModelChunk(chunk);
|
2556
|
+
var initializedChunk = chunk;
|
2557
|
+
|
2558
|
+
if (initializedChunk.status === INITIALIZED) {
|
2559
|
+
controller.enqueue(initializedChunk.value);
|
2560
|
+
} else {
|
2561
|
+
chunk.then(function (v) {
|
2562
|
+
return controller.enqueue(v);
|
2563
|
+
}, function (e) {
|
2564
|
+
return controller.error(e);
|
2565
|
+
});
|
2566
|
+
previousBlockedChunk = chunk;
|
2567
|
+
}
|
2568
|
+
} else {
|
2569
|
+
// We're still waiting on a previous chunk so we can't enqueue quite yet.
|
2570
|
+
var blockedChunk = previousBlockedChunk;
|
2571
|
+
|
2572
|
+
var _chunk2 = createPendingChunk(response);
|
2573
|
+
|
2574
|
+
_chunk2.then(function (v) {
|
2575
|
+
return controller.enqueue(v);
|
2576
|
+
}, function (e) {
|
2577
|
+
return controller.error(e);
|
2578
|
+
});
|
2579
|
+
|
2580
|
+
previousBlockedChunk = _chunk2;
|
2581
|
+
blockedChunk.then(function () {
|
2582
|
+
if (previousBlockedChunk === _chunk2) {
|
2583
|
+
// We were still the last chunk so we can now clear the queue and return
|
2584
|
+
// to synchronous emitting.
|
2585
|
+
previousBlockedChunk = null;
|
2586
|
+
}
|
2587
|
+
|
2588
|
+
resolveModelChunk(_chunk2, json);
|
2589
|
+
});
|
2590
|
+
}
|
2591
|
+
},
|
2592
|
+
close: function (json) {
|
2593
|
+
if (previousBlockedChunk === null) {
|
2594
|
+
controller.close();
|
2595
|
+
} else {
|
2596
|
+
var blockedChunk = previousBlockedChunk; // We shouldn't get any more enqueues after this so we can set it back to null.
|
2597
|
+
|
2598
|
+
previousBlockedChunk = null;
|
2599
|
+
blockedChunk.then(function () {
|
2600
|
+
return controller.close();
|
2601
|
+
});
|
2602
|
+
}
|
2603
|
+
},
|
2604
|
+
error: function (error) {
|
2605
|
+
if (previousBlockedChunk === null) {
|
2606
|
+
// $FlowFixMe[incompatible-call]
|
2607
|
+
controller.error(error);
|
2608
|
+
} else {
|
2609
|
+
var blockedChunk = previousBlockedChunk; // We shouldn't get any more enqueues after this so we can set it back to null.
|
2610
|
+
|
2611
|
+
previousBlockedChunk = null;
|
2612
|
+
blockedChunk.then(function () {
|
2613
|
+
return controller.error(error);
|
2614
|
+
});
|
2615
|
+
}
|
2616
|
+
}
|
2617
|
+
};
|
2618
|
+
resolveStream(response, id, stream, flightController);
|
2619
|
+
}
|
2620
|
+
|
2621
|
+
function asyncIterator() {
|
2622
|
+
// Self referencing iterator.
|
2623
|
+
return this;
|
2624
|
+
}
|
2625
|
+
|
2626
|
+
function createIterator(next) {
|
2627
|
+
var iterator = {
|
2628
|
+
next: next // TODO: Add return/throw as options for aborting.
|
2629
|
+
|
2630
|
+
}; // TODO: The iterator could inherit the AsyncIterator prototype which is not exposed as
|
2631
|
+
// a global but exists as a prototype of an AsyncGenerator. However, it's not needed
|
2632
|
+
// to satisfy the iterable protocol.
|
2633
|
+
|
2634
|
+
iterator[ASYNC_ITERATOR] = asyncIterator;
|
2635
|
+
return iterator;
|
2636
|
+
}
|
2637
|
+
|
2638
|
+
function startAsyncIterable(response, id, iterator) {
|
2639
|
+
var buffer = [];
|
2640
|
+
var closed = false;
|
2641
|
+
var nextWriteIndex = 0;
|
2642
|
+
var flightController = {
|
2643
|
+
enqueueValue: function (value) {
|
2644
|
+
if (nextWriteIndex === buffer.length) {
|
2645
|
+
buffer[nextWriteIndex] = createInitializedIteratorResultChunk(response, value, false);
|
2646
|
+
} else {
|
2647
|
+
var chunk = buffer[nextWriteIndex];
|
2648
|
+
var resolveListeners = chunk.value;
|
2649
|
+
var rejectListeners = chunk.reason;
|
2650
|
+
var initializedChunk = chunk;
|
2651
|
+
initializedChunk.status = INITIALIZED;
|
2652
|
+
initializedChunk.value = {
|
2653
|
+
done: false,
|
2654
|
+
value: value
|
2655
|
+
};
|
2656
|
+
|
2657
|
+
if (resolveListeners !== null) {
|
2658
|
+
wakeChunkIfInitialized(chunk, resolveListeners, rejectListeners);
|
2659
|
+
}
|
2660
|
+
}
|
2661
|
+
|
2662
|
+
nextWriteIndex++;
|
2663
|
+
},
|
2664
|
+
enqueueModel: function (value) {
|
2665
|
+
if (nextWriteIndex === buffer.length) {
|
2666
|
+
buffer[nextWriteIndex] = createResolvedIteratorResultChunk(response, value, false);
|
2667
|
+
} else {
|
2668
|
+
resolveIteratorResultChunk(buffer[nextWriteIndex], value, false);
|
2669
|
+
}
|
2670
|
+
|
2671
|
+
nextWriteIndex++;
|
2672
|
+
},
|
2673
|
+
close: function (value) {
|
2674
|
+
closed = true;
|
2675
|
+
|
2676
|
+
if (nextWriteIndex === buffer.length) {
|
2677
|
+
buffer[nextWriteIndex] = createResolvedIteratorResultChunk(response, value, true);
|
2678
|
+
} else {
|
2679
|
+
resolveIteratorResultChunk(buffer[nextWriteIndex], value, true);
|
2680
|
+
}
|
2681
|
+
|
2682
|
+
nextWriteIndex++;
|
2683
|
+
|
2684
|
+
while (nextWriteIndex < buffer.length) {
|
2685
|
+
// In generators, any extra reads from the iterator have the value undefined.
|
2686
|
+
resolveIteratorResultChunk(buffer[nextWriteIndex++], '"$undefined"', true);
|
2687
|
+
}
|
2688
|
+
},
|
2689
|
+
error: function (error) {
|
2690
|
+
closed = true;
|
2691
|
+
|
2692
|
+
if (nextWriteIndex === buffer.length) {
|
2693
|
+
buffer[nextWriteIndex] = createPendingChunk(response);
|
2694
|
+
}
|
2695
|
+
|
2696
|
+
while (nextWriteIndex < buffer.length) {
|
2697
|
+
triggerErrorOnChunk(buffer[nextWriteIndex++], error);
|
2698
|
+
}
|
2699
|
+
}
|
2700
|
+
};
|
2701
|
+
|
2702
|
+
var iterable = _defineProperty({}, ASYNC_ITERATOR, function () {
|
2703
|
+
var nextReadIndex = 0;
|
2704
|
+
return createIterator(function (arg) {
|
2705
|
+
if (arg !== undefined) {
|
2706
|
+
throw new Error('Values cannot be passed to next() of AsyncIterables passed to Client Components.');
|
2707
|
+
}
|
2708
|
+
|
2709
|
+
if (nextReadIndex === buffer.length) {
|
2710
|
+
if (closed) {
|
2711
|
+
// $FlowFixMe[invalid-constructor] Flow doesn't support functions as constructors
|
2712
|
+
return new Chunk(INITIALIZED, {
|
2713
|
+
done: true,
|
2714
|
+
value: undefined
|
2715
|
+
}, null, response);
|
2716
|
+
}
|
2717
|
+
|
2718
|
+
buffer[nextReadIndex] = createPendingChunk(response);
|
2719
|
+
}
|
2720
|
+
|
2721
|
+
return buffer[nextReadIndex++];
|
2722
|
+
});
|
2723
|
+
}); // TODO: If it's a single shot iterator we can optimize memory by cleaning up the buffer after
|
2724
|
+
// reading through the end, but currently we favor code size over this optimization.
|
2725
|
+
|
2726
|
+
|
2727
|
+
resolveStream(response, id, iterator ? iterable[ASYNC_ITERATOR]() : iterable, flightController);
|
2728
|
+
}
|
2729
|
+
|
2730
|
+
function stopStream(response, id, row) {
|
2731
|
+
var chunks = response._chunks;
|
2732
|
+
var chunk = chunks.get(id);
|
2733
|
+
|
2734
|
+
if (!chunk || chunk.status !== INITIALIZED) {
|
2735
|
+
// We didn't expect not to have an existing stream;
|
2736
|
+
return;
|
2737
|
+
}
|
2738
|
+
|
2739
|
+
var streamChunk = chunk;
|
2740
|
+
var controller = streamChunk.reason;
|
2741
|
+
controller.close(row === '' ? '"$undefined"' : row);
|
2742
|
+
}
|
2743
|
+
|
2048
2744
|
function resolveErrorDev(response, id, digest, message, stack) {
|
2049
2745
|
|
2050
2746
|
|
@@ -2086,7 +2782,127 @@ function resolveConsoleEntry(response, value) {
|
|
2086
2782
|
printToConsole(methodName, args, env);
|
2087
2783
|
}
|
2088
2784
|
|
2785
|
+
function mergeBuffer(buffer, lastChunk) {
|
2786
|
+
var l = buffer.length; // Count the bytes we'll need
|
2787
|
+
|
2788
|
+
var byteLength = lastChunk.length;
|
2789
|
+
|
2790
|
+
for (var i = 0; i < l; i++) {
|
2791
|
+
byteLength += buffer[i].byteLength;
|
2792
|
+
} // Allocate enough contiguous space
|
2793
|
+
|
2794
|
+
|
2795
|
+
var result = new Uint8Array(byteLength);
|
2796
|
+
var offset = 0; // Copy all the buffers into it.
|
2797
|
+
|
2798
|
+
for (var _i = 0; _i < l; _i++) {
|
2799
|
+
var chunk = buffer[_i];
|
2800
|
+
result.set(chunk, offset);
|
2801
|
+
offset += chunk.byteLength;
|
2802
|
+
}
|
2803
|
+
|
2804
|
+
result.set(lastChunk, offset);
|
2805
|
+
return result;
|
2806
|
+
}
|
2807
|
+
|
2808
|
+
function resolveTypedArray(response, id, buffer, lastChunk, constructor, bytesPerElement) {
|
2809
|
+
// If the view fits into one original buffer, we just reuse that buffer instead of
|
2810
|
+
// copying it out to a separate copy. This means that it's not always possible to
|
2811
|
+
// transfer these values to other threads without copying first since they may
|
2812
|
+
// share array buffer. For this to work, it must also have bytes aligned to a
|
2813
|
+
// multiple of a size of the type.
|
2814
|
+
var chunk = buffer.length === 0 && lastChunk.byteOffset % bytesPerElement === 0 ? lastChunk : mergeBuffer(buffer, lastChunk); // TODO: The transfer protocol of RSC is little-endian. If the client isn't little-endian
|
2815
|
+
// we should convert it instead. In practice big endian isn't really Web compatible so it's
|
2816
|
+
// somewhat safe to assume that browsers aren't going to run it, but maybe there's some SSR
|
2817
|
+
// server that's affected.
|
2818
|
+
|
2819
|
+
var view = new constructor(chunk.buffer, chunk.byteOffset, chunk.byteLength / bytesPerElement);
|
2820
|
+
resolveBuffer(response, id, view);
|
2821
|
+
}
|
2822
|
+
|
2089
2823
|
function processFullRow(response, id, tag, buffer, chunk) {
|
2824
|
+
{
|
2825
|
+
switch (tag) {
|
2826
|
+
case 65
|
2827
|
+
/* "A" */
|
2828
|
+
:
|
2829
|
+
// We must always clone to extract it into a separate buffer instead of just a view.
|
2830
|
+
resolveBuffer(response, id, mergeBuffer(buffer, chunk).buffer);
|
2831
|
+
return;
|
2832
|
+
|
2833
|
+
case 79
|
2834
|
+
/* "O" */
|
2835
|
+
:
|
2836
|
+
resolveTypedArray(response, id, buffer, chunk, Int8Array, 1);
|
2837
|
+
return;
|
2838
|
+
|
2839
|
+
case 111
|
2840
|
+
/* "o" */
|
2841
|
+
:
|
2842
|
+
resolveBuffer(response, id, buffer.length === 0 ? chunk : mergeBuffer(buffer, chunk));
|
2843
|
+
return;
|
2844
|
+
|
2845
|
+
case 85
|
2846
|
+
/* "U" */
|
2847
|
+
:
|
2848
|
+
resolveTypedArray(response, id, buffer, chunk, Uint8ClampedArray, 1);
|
2849
|
+
return;
|
2850
|
+
|
2851
|
+
case 83
|
2852
|
+
/* "S" */
|
2853
|
+
:
|
2854
|
+
resolveTypedArray(response, id, buffer, chunk, Int16Array, 2);
|
2855
|
+
return;
|
2856
|
+
|
2857
|
+
case 115
|
2858
|
+
/* "s" */
|
2859
|
+
:
|
2860
|
+
resolveTypedArray(response, id, buffer, chunk, Uint16Array, 2);
|
2861
|
+
return;
|
2862
|
+
|
2863
|
+
case 76
|
2864
|
+
/* "L" */
|
2865
|
+
:
|
2866
|
+
resolveTypedArray(response, id, buffer, chunk, Int32Array, 4);
|
2867
|
+
return;
|
2868
|
+
|
2869
|
+
case 108
|
2870
|
+
/* "l" */
|
2871
|
+
:
|
2872
|
+
resolveTypedArray(response, id, buffer, chunk, Uint32Array, 4);
|
2873
|
+
return;
|
2874
|
+
|
2875
|
+
case 71
|
2876
|
+
/* "G" */
|
2877
|
+
:
|
2878
|
+
resolveTypedArray(response, id, buffer, chunk, Float32Array, 4);
|
2879
|
+
return;
|
2880
|
+
|
2881
|
+
case 103
|
2882
|
+
/* "g" */
|
2883
|
+
:
|
2884
|
+
resolveTypedArray(response, id, buffer, chunk, Float64Array, 8);
|
2885
|
+
return;
|
2886
|
+
|
2887
|
+
case 77
|
2888
|
+
/* "M" */
|
2889
|
+
:
|
2890
|
+
resolveTypedArray(response, id, buffer, chunk, BigInt64Array, 8);
|
2891
|
+
return;
|
2892
|
+
|
2893
|
+
case 109
|
2894
|
+
/* "m" */
|
2895
|
+
:
|
2896
|
+
resolveTypedArray(response, id, buffer, chunk, BigUint64Array, 8);
|
2897
|
+
return;
|
2898
|
+
|
2899
|
+
case 86
|
2900
|
+
/* "V" */
|
2901
|
+
:
|
2902
|
+
resolveTypedArray(response, id, buffer, chunk, DataView, 1);
|
2903
|
+
return;
|
2904
|
+
}
|
2905
|
+
}
|
2090
2906
|
|
2091
2907
|
var stringDecoder = response._stringDecoder;
|
2092
2908
|
var row = '';
|
@@ -2161,26 +2977,56 @@ function processFullRow(response, id, tag, buffer, chunk) {
|
|
2161
2977
|
case 82
|
2162
2978
|
/* "R" */
|
2163
2979
|
:
|
2980
|
+
{
|
2981
|
+
{
|
2982
|
+
startReadableStream(response, id, undefined);
|
2983
|
+
return;
|
2984
|
+
}
|
2985
|
+
}
|
2164
2986
|
// Fallthrough
|
2165
2987
|
|
2166
2988
|
case 114
|
2167
2989
|
/* "r" */
|
2168
2990
|
:
|
2991
|
+
{
|
2992
|
+
{
|
2993
|
+
startReadableStream(response, id, 'bytes');
|
2994
|
+
return;
|
2995
|
+
}
|
2996
|
+
}
|
2169
2997
|
// Fallthrough
|
2170
2998
|
|
2171
2999
|
case 88
|
2172
3000
|
/* "X" */
|
2173
3001
|
:
|
3002
|
+
{
|
3003
|
+
{
|
3004
|
+
startAsyncIterable(response, id, false);
|
3005
|
+
return;
|
3006
|
+
}
|
3007
|
+
}
|
2174
3008
|
// Fallthrough
|
2175
3009
|
|
2176
3010
|
case 120
|
2177
3011
|
/* "x" */
|
2178
3012
|
:
|
3013
|
+
{
|
3014
|
+
{
|
3015
|
+
startAsyncIterable(response, id, true);
|
3016
|
+
return;
|
3017
|
+
}
|
3018
|
+
}
|
2179
3019
|
// Fallthrough
|
2180
3020
|
|
2181
3021
|
case 67
|
2182
3022
|
/* "C" */
|
2183
3023
|
:
|
3024
|
+
{
|
3025
|
+
{
|
3026
|
+
stopStream(response, id, row);
|
3027
|
+
return;
|
3028
|
+
}
|
3029
|
+
}
|
2184
3030
|
// Fallthrough
|
2185
3031
|
|
2186
3032
|
case 80
|
@@ -2233,7 +3079,31 @@ function processBinaryChunk(response, chunk) {
|
|
2233
3079
|
|
2234
3080
|
if (resolvedRowTag === 84
|
2235
3081
|
/* "T" */
|
2236
|
-
||
|
3082
|
+
|| (resolvedRowTag === 65
|
3083
|
+
/* "A" */
|
3084
|
+
|| resolvedRowTag === 79
|
3085
|
+
/* "O" */
|
3086
|
+
|| resolvedRowTag === 111
|
3087
|
+
/* "o" */
|
3088
|
+
|| resolvedRowTag === 85
|
3089
|
+
/* "U" */
|
3090
|
+
|| resolvedRowTag === 83
|
3091
|
+
/* "S" */
|
3092
|
+
|| resolvedRowTag === 115
|
3093
|
+
/* "s" */
|
3094
|
+
|| resolvedRowTag === 76
|
3095
|
+
/* "L" */
|
3096
|
+
|| resolvedRowTag === 108
|
3097
|
+
/* "l" */
|
3098
|
+
|| resolvedRowTag === 71
|
3099
|
+
/* "G" */
|
3100
|
+
|| resolvedRowTag === 103
|
3101
|
+
/* "g" */
|
3102
|
+
|| resolvedRowTag === 77
|
3103
|
+
/* "M" */
|
3104
|
+
|| resolvedRowTag === 109
|
3105
|
+
/* "m" */
|
3106
|
+
|| resolvedRowTag === 86)
|
2237
3107
|
/* "V" */
|
2238
3108
|
) {
|
2239
3109
|
rowTag = resolvedRowTag;
|