From c49cacaf17386dd39699aff415facd56cc637847 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Wed, 29 Mar 2023 16:48:12 +0000 Subject: [PATCH] [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 [fd0511c728e186905b7f0e71f072b4b247d6f29f](https://github.com/facebook/react/commit/fd0511c728e186905b7f0e71f072b4b247d6f29f) --- compiled/facebook-www/REVISION | 2 +- .../ReactFlightDOMRelayClient-dev.classic.js | 5 +++++ .../ReactFlightDOMRelayClient-dev.modern.js | 5 +++++ .../ReactFlightDOMRelayClient-prod.classic.js | 2 ++ .../ReactFlightDOMRelayClient-prod.modern.js | 2 ++ .../ReactFlightDOMRelayServer-dev.classic.js | 11 +++++------ .../ReactFlightDOMRelayServer-dev.modern.js | 11 +++++------ .../ReactFlightDOMRelayServer-prod.classic.js | 8 +------- .../ReactFlightDOMRelayServer-prod.modern.js | 8 +------- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/compiled/facebook-www/REVISION b/compiled/facebook-www/REVISION index dac374ec89a05..c026626c9fd8e 100644 --- a/compiled/facebook-www/REVISION +++ b/compiled/facebook-www/REVISION @@ -1 +1 @@ -85de6fde515148babd36eae2b7384ad8e62b732a +fd0511c728e186905b7f0e71f072b4b247d6f29f diff --git a/compiled/facebook-www/ReactFlightDOMRelayClient-dev.classic.js b/compiled/facebook-www/ReactFlightDOMRelayClient-dev.classic.js index 01ece9c61c01c..6209190a6d5d6 100644 --- a/compiled/facebook-www/ReactFlightDOMRelayClient-dev.classic.js +++ b/compiled/facebook-www/ReactFlightDOMRelayClient-dev.classic.js @@ -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); diff --git a/compiled/facebook-www/ReactFlightDOMRelayClient-dev.modern.js b/compiled/facebook-www/ReactFlightDOMRelayClient-dev.modern.js index 01ece9c61c01c..6209190a6d5d6 100644 --- a/compiled/facebook-www/ReactFlightDOMRelayClient-dev.modern.js +++ b/compiled/facebook-www/ReactFlightDOMRelayClient-dev.modern.js @@ -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); diff --git a/compiled/facebook-www/ReactFlightDOMRelayClient-prod.classic.js b/compiled/facebook-www/ReactFlightDOMRelayClient-prod.classic.js index 2890dc8d2b602..94bc45cb7e132 100644 --- a/compiled/facebook-www/ReactFlightDOMRelayClient-prod.classic.js +++ b/compiled/facebook-www/ReactFlightDOMRelayClient-prod.classic.js @@ -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); diff --git a/compiled/facebook-www/ReactFlightDOMRelayClient-prod.modern.js b/compiled/facebook-www/ReactFlightDOMRelayClient-prod.modern.js index 2890dc8d2b602..94bc45cb7e132 100644 --- a/compiled/facebook-www/ReactFlightDOMRelayClient-prod.modern.js +++ b/compiled/facebook-www/ReactFlightDOMRelayClient-prod.modern.js @@ -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); diff --git a/compiled/facebook-www/ReactFlightDOMRelayServer-dev.classic.js b/compiled/facebook-www/ReactFlightDOMRelayServer-dev.classic.js index 745cd7062c64f..29aab488a67db 100644 --- a/compiled/facebook-www/ReactFlightDOMRelayServer-dev.classic.js +++ b/compiled/facebook-www/ReactFlightDOMRelayServer-dev.classic.js @@ -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( diff --git a/compiled/facebook-www/ReactFlightDOMRelayServer-dev.modern.js b/compiled/facebook-www/ReactFlightDOMRelayServer-dev.modern.js index 745cd7062c64f..29aab488a67db 100644 --- a/compiled/facebook-www/ReactFlightDOMRelayServer-dev.modern.js +++ b/compiled/facebook-www/ReactFlightDOMRelayServer-dev.modern.js @@ -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( diff --git a/compiled/facebook-www/ReactFlightDOMRelayServer-prod.classic.js b/compiled/facebook-www/ReactFlightDOMRelayServer-prod.classic.js index 7a0878bee561c..ebc5e938ee469 100644 --- a/compiled/facebook-www/ReactFlightDOMRelayServer-prod.classic.js +++ b/compiled/facebook-www/ReactFlightDOMRelayServer-prod.classic.js @@ -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 + diff --git a/compiled/facebook-www/ReactFlightDOMRelayServer-prod.modern.js b/compiled/facebook-www/ReactFlightDOMRelayServer-prod.modern.js index 7a0878bee561c..ebc5e938ee469 100644 --- a/compiled/facebook-www/ReactFlightDOMRelayServer-prod.modern.js +++ b/compiled/facebook-www/ReactFlightDOMRelayServer-prod.modern.js @@ -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 +