UI freezes during streaming responses — main thread blocked ~1s per render burst (devtools element instrumentation + renderer commit cost)

Offen
#179 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
42/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
playwright, react, typescript

Rechercherichtung

Start with dist/core/devtools.js at rememberDevToolsElement() and inspect how the devtools enabled flag is set and checked by neighboring hooks. Then profile the production renderer during the reported streamed token updates, focusing on commit, project(), and reconciliation work. Done means the freeze is reproduced and its production cost is traced, with a fix and regression coverage showing the UI remains responsive.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Summary

In an app rendering with @tanstack/redact (0.3.1) as the React runtime, the UI freezes completely at the start of every streamed AI response — both in dev and production. Longtask observer shows ~1s of main-thread blocking concentrated in the response-start window; frame gaps reach ~1.1s.

Environment
  • @tanstack/redact: 0.3.1
  • react / react-dom: 19.3.1
  • Vite 8.3.8 + @tanstack/react-start 1.169.x, redact() plugin
  • Chrome (headless Chromium via Playwright)
Reproduction

Chat UI that re-renders on every streamed token (TanStack AI useChat → store update → message list render). Send any message; the first visible response freezes the entire page for ~1s, then continues.

Evidence

Dev-mode CPU profile (CDP Profiler, 100µs sampling, 6s window from send):

samples=26877 (~2.7s of 6s)
1.06s 39.4%  rememberDevToolsElement  dist/core/devtools.js:12
0.50s 18.5%  (idle)
0.13s  4.7%  (garbage collector)
0.10s  3.7%  (program)
... reconcile/commit each <1.5%

Longtasks: 3 tasks ≈ 1037ms inside the first 3s of the stream.

Production build: the same freeze reproduces, so the devtools path (compiled out under NODE_ENV=production) is not the whole story — the renderer's per-commit work during high-frequency updates appears to be the remaining cost.

Root cause (dev path)

dist/core/devtools.js → rememberDevToolsElement() runs for every JSX element in dev and captures new Error("react-stack-top-frame") — a full V8 stack trace — for up to 10k elements/sec, unconditionally, even when devToolsMetadata.enabled === false (no __REACT_DEVTOOLS_GLOBAL_HOOK__ connected). Every other devtools hook early-returns on !enabled; this one doesn't. ~100µs per stack capture × thousands of elements per render burst ≈ the observed ~1s block.

Requested fixes
  1. Gate the new Error() capture on devToolsMetadata.enabled (owner/source metadata can still be recorded — it's just WeakMap writes).
  2. Or add a redact({ devtools: false })-style flag for apps that don't use the DevTools bridge.
  3. Investigate the production path separately: per-commit commitDevTools/project() work or reconcile cost under token-rate updates — happy to provide a production CPU profile if useful.
Workaround applied — does NOT fix the bug

bun patch gating the capture on enabled reduced rememberDevToolsElement from 39.4% → 8.6% of dev samples, but the streaming freeze persisted in both dev and production. The patch only removes one measurable cost; it does not address the underlying freeze, which reproduces in the production build where this code path doesn't even exist. We removed Redact from the app entirely — the renderer itself needs investigation under streaming/high-frequency-update load.

Vorherrschende Sprache
TypeScript
Sterne
640
Forks
32
Ø Merge
1 Std. 15 Min.
Gemergte PRs (30 T.)
7

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus TanStack/redact

Alle Issues in TanStack/redact

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.