Skip to content

RangeError when serializing a large Blob with readAsDataURL on Edge runtimes (no Buffer) #38331

Open

Description

@swastiktawate

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:
const encoded = btoa(
  String.fromCharCode.apply(String, new Uint8Array(new ArrayBuffer(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:

  • packages/react-server/src/ReactServerStreamConfigEdge.js:264
  • packages/react-dom-bindings/src/server/ReactDOMLegacyServerStreamConfig.js:89

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.

React version

main at 7b22099 (2026-11-20).

Activity

  1. added
    Status: Unconfirmed
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Unconfirmed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy