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

未关闭
#179 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
playwright, react, typescript

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
640
派生
32
平均合并
1 小时 15 分钟
30 天内合并 PR
7

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/redact 的其他 Issue

查看 TanStack/redact 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。