mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[Flight] Add support BigInt support (#26479)
## Summary
Adds support for sending `BigInt` to Flight and Flight Reply
## How did you test this change?
- added tests
DiffTrain build for [fd0511c728](https://github.com/facebook/react/commit/fd0511c728e186905b7f0e71f072b4b247d6f29f)
This commit is contained in:
@@ -1 +1 @@
|
||||
85de6fde515148babd36eae2b7384ad8e62b732a
|
||||
fd0511c728e186905b7f0e71f072b4b247d6f29f
|
||||
|
||||
@@ -564,6 +564,11 @@ function parseModelString(response, parentObject, key, value) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
case "n": {
|
||||
// BigInt
|
||||
return BigInt(value.substring(2));
|
||||
}
|
||||
|
||||
default: {
|
||||
// We assume that anything else is a reference ID.
|
||||
var _id3 = parseInt(value.substring(1), 16);
|
||||
|
||||
@@ -564,6 +564,11 @@ function parseModelString(response, parentObject, key, value) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
case "n": {
|
||||
// BigInt
|
||||
return BigInt(value.substring(2));
|
||||
}
|
||||
|
||||
default: {
|
||||
// We assume that anything else is a reference ID.
|
||||
var _id3 = parseInt(value.substring(1), 16);
|
||||
|
||||
@@ -287,6 +287,8 @@ function parseModelString(response, parentObject, key, value) {
|
||||
}
|
||||
case "u":
|
||||
return;
|
||||
case "n":
|
||||
return BigInt(value.substring(2));
|
||||
default:
|
||||
value = parseInt(value.substring(1), 16);
|
||||
response = getChunk(response, value);
|
||||
|
||||
@@ -287,6 +287,8 @@ function parseModelString(response, parentObject, key, value) {
|
||||
}
|
||||
case "u":
|
||||
return;
|
||||
case "n":
|
||||
return BigInt(value.substring(2));
|
||||
default:
|
||||
value = parseInt(value.substring(1), 16);
|
||||
response = getChunk(response, value);
|
||||
|
||||
@@ -1771,6 +1771,10 @@ function serializeUndefined() {
|
||||
return "$undefined";
|
||||
}
|
||||
|
||||
function serializeBigInt(n) {
|
||||
return "$n" + n.toString(10);
|
||||
}
|
||||
|
||||
function serializeClientReference(request, parent, key, clientReference) {
|
||||
var clientReferenceKey = getClientReferenceKey(clientReference);
|
||||
var writtenClientReferences = request.writtenClientReferences;
|
||||
@@ -2110,12 +2114,7 @@ function resolveModelToJSON(request, parent, key, value) {
|
||||
}
|
||||
|
||||
if (typeof value === "bigint") {
|
||||
throw new Error(
|
||||
"BigInt (" +
|
||||
value +
|
||||
") is not yet supported in Client Component props." +
|
||||
describeObjectForErrorMessage(parent, key)
|
||||
);
|
||||
return serializeBigInt(value);
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
|
||||
@@ -1771,6 +1771,10 @@ function serializeUndefined() {
|
||||
return "$undefined";
|
||||
}
|
||||
|
||||
function serializeBigInt(n) {
|
||||
return "$n" + n.toString(10);
|
||||
}
|
||||
|
||||
function serializeClientReference(request, parent, key, clientReference) {
|
||||
var clientReferenceKey = getClientReferenceKey(clientReference);
|
||||
var writtenClientReferences = request.writtenClientReferences;
|
||||
@@ -2110,12 +2114,7 @@ function resolveModelToJSON(request, parent, key, value) {
|
||||
}
|
||||
|
||||
if (typeof value === "bigint") {
|
||||
throw new Error(
|
||||
"BigInt (" +
|
||||
value +
|
||||
") is not yet supported in Client Component props." +
|
||||
describeObjectForErrorMessage(parent, key)
|
||||
);
|
||||
return serializeBigInt(value);
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
|
||||
@@ -909,13 +909,7 @@ function resolveModelToJSON(request, parent, key, value) {
|
||||
element.set(value, key);
|
||||
return "$" + key.toString(16);
|
||||
}
|
||||
if ("bigint" === typeof value)
|
||||
throw Error(
|
||||
"BigInt (" +
|
||||
value +
|
||||
") is not yet supported in Client Component props." +
|
||||
describeObjectForErrorMessage(parent, key)
|
||||
);
|
||||
if ("bigint" === typeof value) return "$n" + value.toString(10);
|
||||
throw Error(
|
||||
"Type " +
|
||||
typeof value +
|
||||
|
||||
@@ -909,13 +909,7 @@ function resolveModelToJSON(request, parent, key, value) {
|
||||
element.set(value, key);
|
||||
return "$" + key.toString(16);
|
||||
}
|
||||
if ("bigint" === typeof value)
|
||||
throw Error(
|
||||
"BigInt (" +
|
||||
value +
|
||||
") is not yet supported in Client Component props." +
|
||||
describeObjectForErrorMessage(parent, key)
|
||||
);
|
||||
if ("bigint" === typeof value) return "$n" + value.toString(10);
|
||||
throw Error(
|
||||
"Type " +
|
||||
typeof value +
|
||||
|
||||
Reference in New Issue
Block a user