From 03518adccbfc90183305a512ff1d37ca692c96f9 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 17 Sep 2021 09:24:06 -0400 Subject: [PATCH] Updated the utfDecodeString() method to avoid a RangeError Previously we were spreading the array of encoded values into String.fromCodePoint(...array). Functions arguments are first placed on the stack before the function is called though, which caused an error to be thrown for very large encoded strings. --- packages/react-devtools-shared/src/utils.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/react-devtools-shared/src/utils.js b/packages/react-devtools-shared/src/utils.js index 901aecbac6d06..7c9e2fbd25f8a 100644 --- a/packages/react-devtools-shared/src/utils.js +++ b/packages/react-devtools-shared/src/utils.js @@ -126,7 +126,16 @@ export function getUID(): number { } export function utfDecodeString(array: Array): string { - return String.fromCodePoint(...array); + // Avoid spreading the array (e.g. String.fromCodePoint(...array)) + // Functions arguments are first placed on the stack before the function is called + // which throws a RangeError for large arrays. + // See github.com/facebook/react/issues/22293 + let string = ''; + for (let i = 0; i < array.length; i++) { + const char = array[i]; + string += String.fromCodePoint(char); + } + return string; } export function utfEncodeString(string: string): Array {