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

Đang mở
#179 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
playwright, react, typescript
Lĩnh vực
frontend, performance

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
640
Fork
32
Merge trung bình
1 giờ 15 phút
Pull request đã merge (30 ngày)
7

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/redact

Tất cả issue của TanStack/redact

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.