Skip to content

Commit

Permalink
Updated the utfDecodeString() method to avoid call stack exceeded err…
Browse files Browse the repository at this point in the history
…or (#22330)
  • Loading branch information
Brian Vaughn authored Sep 17, 2021
1 parent b0803f2 commit f2fd1b8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/react-devtools-shared/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ export function getUID(): number {
}

export function utfDecodeString(array: Array<number>): 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<number> {
Expand Down

0 comments on commit f2fd1b8

Please sign in to comment.