You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RangeError when serializing a large Blob with readAsDataURL on Edge runtimes (no Buffer) #38331
When a Server Component returns a Blob larger than roughly 150-200 KB and the server runs in an environment without Node's Buffer (for example an Edge runtime), React throws RangeError: Maximum call stack size exceeded instead of returning a data URL.
Reproduction
// In an Edge runtime (no Buffer), render a Server Component that returns// a Blob of about 200 KB, or call the fallback directly:constencoded=btoa(String.fromCharCode.apply(String,newUint8Array(newArrayBuffer(200000))));// RangeError: Maximum call stack size exceeded
A 100 KB Blob works, a 200 KB Blob throws, so the threshold sits between those sizes on V8 (Node v24).
Root cause
readAsDataURL falls back to btoa(String.fromCharCode.apply(...)) when Buffer is unavailable, in two places:
String.fromCharCode.apply passes every byte as a separate argument, and engines cap the argument count, so large buffers blow the stack. The Node, Bun, and FB configs use Buffer.from(arrayBuffer).toString('base64') and are not affected.
Suggested fix
Convert the buffer to a binary string in chunks (for example 32 KB per fromCharCode.apply call) before passing it to btoa, in both fallback branches. A previous PR (#37004) proposed the same fix for these two files but was closed without merging, and the vulnerable code is still present on main.
Activity