Skip to content

[Flight] Avoid main-thread stalls from large debug strings#36570

Merged
unstubbable merged 4 commits into
facebook:mainfrom
unstubbable:cap-large-debug-strings
May 29, 2026
Merged

[Flight] Avoid main-thread stalls from large debug strings#36570
unstubbable merged 4 commits into
facebook:mainfrom
unstubbable:cap-large-debug-strings

Conversation

@unstubbable
Copy link
Copy Markdown
Collaborator

When the React Flight Server serializes a very large string (multiple megabytes) as part of the debug info for a Server Component — the resolved value of an awaited I/O Promise, a replayed console.log argument, props, etc. — two places in the client stalled the main thread:

  • The Flight Client's parser synchronously decodes the entire string while reading the debug chunk.
  • React DevTools' performance tracks then JSON.stringify the same value to build a property description, and Chrome's tracing UI does not handle multi-megabyte description strings gracefully.

Every debug string flows through the string branch of renderDebugModel — console arguments via emitConsoleChunk, awaited values and other Promise-resolved values via emitOutlinedDebugModelChunk. So this caps it there: strings longer than 1,000,000 characters are omitted and replaced with a short placeholder that states how long the original string was, in the spirit of the existing OMITTED_PROP_ERROR. Handling it in this one spot covers every source with a single check.

As a second layer of defense, addValueToProperties in ReactPerformanceTrackProperties truncates string descriptions to 1023 characters plus an ellipsis before JSON.stringify. This prevents Chrome DevTools from blocking the main thread on the description and then bailing out of showing the performance track spans entirely. 1023 mirrors the existing "large string" boundary the Flight server uses when serializing text (values 1024 and longer are outlined via serializeLargeTextString). This truncation only affects the performance track description; the full value (below the 1 MB server cap) is still shown in the Suspense and Components panels under "suspended by" and "props".

When the React Flight Server serializes a very large string (multiple
megabytes) as part of the debug info for a Server Component — the
resolved value of an awaited I/O Promise, a replayed `console.log`
argument, props, etc. — two places in the client stalled the main
thread:

- The Flight Client's parser synchronously decodes the entire string
while reading the debug chunk.
- React DevTools' performance tracks then `JSON.stringify` the same
value to build a property description, and Chrome's tracing UI does not
handle multi-megabyte description strings gracefully.

Every debug string flows through the string branch of `renderDebugModel`
— console arguments via `emitConsoleChunk`, awaited values and other
Promise-resolved values via `emitOutlinedDebugModelChunk`. So this caps
it there: strings longer than 1,000,000 characters are omitted and
replaced with a short placeholder that states how long the original
string was, in the spirit of the existing `OMITTED_PROP_ERROR`. Handling
it in this one spot covers every source with a single check.

As a second layer of defense, `addValueToProperties` in
`ReactPerformanceTrackProperties` truncates string descriptions to 1023
characters plus an ellipsis before `JSON.stringify`. This prevents
Chrome DevTools from blocking the main thread on the description and
then bailing out of showing the performance track spans entirely. 1023
mirrors the existing "large string" boundary the Flight server uses when
serializing text (values 1024 and longer are outlined via
`serializeLargeTextString`). This truncation only affects the
performance track description; the full value (below the 1 MB server
cap) is still shown in the Suspense and Components panels under
"suspended by" and "props".
@meta-cla meta-cla Bot added the CLA Signed label May 29, 2026
@github-actions github-actions Bot added the React Core Team Opened by a member of the React Core Team label May 29, 2026
@react-sizebot
Copy link
Copy Markdown

react-sizebot commented May 29, 2026

Comparing: 6b5ea12...6a44d94

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.84 kB 6.84 kB +0.05% 1.88 kB 1.88 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 614.26 kB 614.26 kB = 108.57 kB 108.57 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.84 kB 6.84 kB = 1.88 kB 1.88 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 680.19 kB 680.19 kB = 119.51 kB 119.51 kB
facebook-www/ReactDOM-prod.classic.js = 700.61 kB 700.61 kB = 123.09 kB 123.09 kB
facebook-www/ReactDOM-prod.modern.js = 690.93 kB 690.93 kB = 121.48 kB 121.48 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 6a44d94

@unstubbable unstubbable marked this pull request as ready for review May 29, 2026 11:37
@unstubbable unstubbable requested a review from eps1lon May 29, 2026 11:37
Comment thread fixtures/flight/src/FileReader.js Outdated
@unstubbable unstubbable requested a review from eps1lon May 29, 2026 11:52
@unstubbable unstubbable merged commit f0dfee3 into facebook:main May 29, 2026
237 checks passed
@unstubbable unstubbable deleted the cap-large-debug-strings branch May 29, 2026 12:28
github-actions Bot pushed a commit that referenced this pull request May 29, 2026
github-actions Bot pushed a commit that referenced this pull request May 29, 2026
github-actions Bot pushed a commit to code/lib-react that referenced this pull request May 31, 2026
github-actions Bot pushed a commit to code/lib-react that referenced this pull request May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants