Skip to content

Commit c49caca

Browse files
committed
[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 [fd0511c](fd0511c)
1 parent fc1026b commit c49caca

9 files changed

+27
-27
lines changed

compiled/facebook-www/REVISION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
85de6fde515148babd36eae2b7384ad8e62b732a
1+
fd0511c728e186905b7f0e71f072b4b247d6f29f

compiled/facebook-www/ReactFlightDOMRelayClient-dev.classic.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,11 @@ function parseModelString(response, parentObject, key, value) {
564564
return undefined;
565565
}
566566

567+
case "n": {
568+
// BigInt
569+
return BigInt(value.substring(2));
570+
}
571+
567572
default: {
568573
// We assume that anything else is a reference ID.
569574
var _id3 = parseInt(value.substring(1), 16);

compiled/facebook-www/ReactFlightDOMRelayClient-dev.modern.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,11 @@ function parseModelString(response, parentObject, key, value) {
564564
return undefined;
565565
}
566566

567+
case "n": {
568+
// BigInt
569+
return BigInt(value.substring(2));
570+
}
571+
567572
default: {
568573
// We assume that anything else is a reference ID.
569574
var _id3 = parseInt(value.substring(1), 16);

compiled/facebook-www/ReactFlightDOMRelayClient-prod.classic.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ function parseModelString(response, parentObject, key, value) {
287287
}
288288
case "u":
289289
return;
290+
case "n":
291+
return BigInt(value.substring(2));
290292
default:
291293
value = parseInt(value.substring(1), 16);
292294
response = getChunk(response, value);

compiled/facebook-www/ReactFlightDOMRelayClient-prod.modern.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ function parseModelString(response, parentObject, key, value) {
287287
}
288288
case "u":
289289
return;
290+
case "n":
291+
return BigInt(value.substring(2));
290292
default:
291293
value = parseInt(value.substring(1), 16);
292294
response = getChunk(response, value);

compiled/facebook-www/ReactFlightDOMRelayServer-dev.classic.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,10 @@ function serializeUndefined() {
17711771
return "$undefined";
17721772
}
17731773

1774+
function serializeBigInt(n) {
1775+
return "$n" + n.toString(10);
1776+
}
1777+
17741778
function serializeClientReference(request, parent, key, clientReference) {
17751779
var clientReferenceKey = getClientReferenceKey(clientReference);
17761780
var writtenClientReferences = request.writtenClientReferences;
@@ -2110,12 +2114,7 @@ function resolveModelToJSON(request, parent, key, value) {
21102114
}
21112115

21122116
if (typeof value === "bigint") {
2113-
throw new Error(
2114-
"BigInt (" +
2115-
value +
2116-
") is not yet supported in Client Component props." +
2117-
describeObjectForErrorMessage(parent, key)
2118-
);
2117+
return serializeBigInt(value);
21192118
}
21202119

21212120
throw new Error(

compiled/facebook-www/ReactFlightDOMRelayServer-dev.modern.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,10 @@ function serializeUndefined() {
17711771
return "$undefined";
17721772
}
17731773

1774+
function serializeBigInt(n) {
1775+
return "$n" + n.toString(10);
1776+
}
1777+
17741778
function serializeClientReference(request, parent, key, clientReference) {
17751779
var clientReferenceKey = getClientReferenceKey(clientReference);
17761780
var writtenClientReferences = request.writtenClientReferences;
@@ -2110,12 +2114,7 @@ function resolveModelToJSON(request, parent, key, value) {
21102114
}
21112115

21122116
if (typeof value === "bigint") {
2113-
throw new Error(
2114-
"BigInt (" +
2115-
value +
2116-
") is not yet supported in Client Component props." +
2117-
describeObjectForErrorMessage(parent, key)
2118-
);
2117+
return serializeBigInt(value);
21192118
}
21202119

21212120
throw new Error(

compiled/facebook-www/ReactFlightDOMRelayServer-prod.classic.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -909,13 +909,7 @@ function resolveModelToJSON(request, parent, key, value) {
909909
element.set(value, key);
910910
return "$" + key.toString(16);
911911
}
912-
if ("bigint" === typeof value)
913-
throw Error(
914-
"BigInt (" +
915-
value +
916-
") is not yet supported in Client Component props." +
917-
describeObjectForErrorMessage(parent, key)
918-
);
912+
if ("bigint" === typeof value) return "$n" + value.toString(10);
919913
throw Error(
920914
"Type " +
921915
typeof value +

compiled/facebook-www/ReactFlightDOMRelayServer-prod.modern.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -909,13 +909,7 @@ function resolveModelToJSON(request, parent, key, value) {
909909
element.set(value, key);
910910
return "$" + key.toString(16);
911911
}
912-
if ("bigint" === typeof value)
913-
throw Error(
914-
"BigInt (" +
915-
value +
916-
") is not yet supported in Client Component props." +
917-
describeObjectForErrorMessage(parent, key)
918-
);
912+
if ("bigint" === typeof value) return "$n" + value.toString(10);
919913
throw Error(
920914
"Type " +
921915
typeof value +

0 commit comments

Comments
 (0)