perf(web): typing no longer re-renders the composer's footer controls #32323
main fromrefs/pull/32323/head·merged by juliusmarminge View on GitHubProblem#
Every keystroke in the chat composer re-renders the whole footer controls subtree: ComposerControlsBar, the model picker, the compact controls menu and their popovers. A prop probe showed the only ComposerControlsBar prop that changes per keystroke is compatibleRuntimeModeOptions, which is a new array on every ChatComposer render.
Compiling ChatComposer.tsx with React Compiler (same options as reactCompilerCoverage.test.ts) shows why. The useManagedPolicy(environmentId) hook call sat between deriving the runtime modes and using them, so the compiler emitted that stretch without a $[n] guard:
const { modes: compatibleRuntimeModes, mode: compatibleRuntimeMode } = resolveCompatibleRuntimeMode(runtimeMode, selectedProviderEntry?.snapshot.supportedRuntimeModes);
const managedPolicy = useManagedPolicy(environmentId);
const compatibleRuntimeModeOptions = resolveRuntimeModeOptions(compatibleRuntimeModes, managedPolicy);
This is a regression from #27197 (managed policy). At d897d3f3f0^ the options were memoized on runtimeMode and supportedRuntimeModes; from d897d3f3f0 on, they are rebuilt every render. #30275 later moved the same code into runtimeModeConfig.ts without changing this.
Change#
useManagedPolicy is now called before the derivation. Hook order is unchanged. The compiler then caches the modes, the options, the ceiling denial and the fallback in one scope, keyed on managedPolicy, runtimeMode and supportedRuntimeModes. A short comment says why the call has to come first.
app-type-in-composer in apps/web/test/appScenarios.renders.tsx now asserts that ComposerControlsBar renders once while 20 characters are typed (for the empty-to-non-empty transition on the first character). It fails on main with expected 21 to be 1.
Scope and approval#
This is a very small, focused fix for an obvious performance regression: one hook call moves a few lines up, with no behavior change. That fits the exception for small obvious bug fixes. Typing in the composer is the hottest path in the app, and the composer typing-lag reports (for example #12689) make that path more expensive than it should be.
Verification#
Render counts with
scripts/render-metrics.ts(renders project, 20-turn fake thread), before → after:scenario renders app-type-in-composer 542 → 293 (−46%) app-open-settings 619 → 559 app-switch-settings-section 703 → 663 app-switch-thread 3524 → 3361 app-mount-thread 2956 → 2847 In
app-type-in-composer:ComposerControlsBar,ComposerModelPickerandComposerControlgo from 21 → 1,CompactComposerControlsMenu21 → 0,PopoverTrigger42 → 2. Every other scenario is unchanged.Typing latency under 4× CPU throttle (temporary, uncommitted harness on the same fake app: React Profiler plus the Event Timing API, CDP
Emulation.setCPUThrottlingRate). 20 keystrokes, medians of 3 runs:before after React render time per 20 keystrokes 357 ms 212 ms keystroke → next paint, median 40 ms 24 ms keystroke → next paint, p90 48 ms 40 ms Checked the React Compiler output before and after the change. After, the guard is
if ($[140] !== managedPolicy || $[141] !== runtimeMode || $[142] !== selectedProviderEntry?.snapshot.supportedRuntimeModes).vp run check:changedpasses (format, lint, knip, typecheck, React Compiler coverage).
Things I could not check, and notes:
- On macOS,
warm upandapp-toggle-diff-paneltime out on a cleanmain, because the scenario sends{Control>}dformod+d.app-stream-assistant-turnalso fails itsMarkdownParagraphcount there. So I ran the renders project directly three times per side and compared the reports. Those three scenarios aren't in the table. - There's no visual change, so there are no screenshots.
Written with Claude Opus 5.5 in Claude Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
Approvability#
Verdict: Approved at
ecafd4eMacroscope's review found this PR approvable — Reorders an existing policy hook to let React Compiler cache composer footer options during typing. Product defaults and policy enforcement remain unchanged, with risk limited to UI rendering behavior.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review.
Walkthrough
-
The composer now calls
useManagedPolicybefore deriving compatible runtime modes. The typing scenario asserts thatComposerControlsBarrenders once.Changes: Composer Policy Evaluation
Layer / File(s) Summary Policy evaluation and render check
apps/web/src/components/chat/ChatComposer.tsx,apps/web/test/appScenarios.renders.tsxuseManagedPolicyruns before compatible runtime-mode derivation. The typing scenario asserts thatComposerControlsBarrenders once.Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge,yuruzuu
Merge Risk:
Minimal · up to7a51f-
This is a small performance change that reduces unnecessary re-renders of the composer footer controls while typing. It has no visible behavior change and no identified merge-blocking risk.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the main change: typing no longer re-renders the composer footer controls. It follows the conventional commit form with a clear scope. The diff moves one hook call in ChatComposer.tsx … Description check The description follows the template. It has Problem, Change, Scope, and Verification sections. The Problem section gives the cause, with a prop probe and compiler output. The Change section explains … Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Title check
-
Explanation
The title names the main change: typing no longer re-renders the composer footer controls. It follows the conventional commit form with a clear scope. The diff moves one hook call in ChatComposer.tsx so React Compiler can cache the derived runtime-mode options, and it adds a render assertion for the same behavior, so the title matches the changeset.
Full details: Description check
-
Explanation
The description follows the template. It has Problem, Change, Scope, and Verification sections. The Problem section gives the cause, with a prop probe and compiler output. The Change section explains the one-line reordering and the cache keys. The Scope section argues the small-obvious-bug exception and does not link an issue for the regression itself, though it cites related issues. Verification includes before/after render counts, a throttled latency table, a compiler guard check, and a check run. It also states what could not be checked on macOS and that no screenshots apply. The template asks for a link to the issue that shows the bug, and the PR cites
#27197and#12689without stating that they are the bug report, so this is a minor gap. Overall the description is mostly complete.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: c6a120a
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
32cd1e2f-79a5-4df9-8d07-2d767bd93984
Commits-
Reviewing files that changed from the base of the PR and between 31cf4b5a9c1389634c3dba3b176ec1c0900176bd and 7a51fbdf04c1a432db283f6ff2695f75e47f318e.
Files selected for processing: 2-
apps/web/src/components/chat/ChatComposer.tsxapps/web/test/appScenarios.renders.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
-
tanstack-source added labelsbug
juliusmarminge added labelstakeover:in-progress
Evidence#
Measured the real web app on the same Linux machine: headless Chromium 156, GPU disabled, 1280×800, dark theme, 4× CPU throttling. Seeded 20 completed replay turns on each fresh database. Cleared the composer, typed
the quick brown foxat 150 ms/key, then waited two seconds. Nine measured repetitions followed ten warm-ups on each commit.Before After f00afc6cda 7a51fbdf04 

React render duration: 909.1 ms median, range 716.7–1104.5 490.4 ms median, range 420.2–576.7 Footer renders: 21 in every run 1 in every run Total renders: median 730 472 in every run 

Before interaction recording After interaction recording The 418.7 ms CPU render-time improvement (46%) exceeds both full run ranges, 387.8 ms and 156.5 ms. Every head run used less React render time than every base run. Both retained the exact typed text in all measured repetitions and displayed the same model selection. Videos were recorded separately with two warm-ups; only the machine label was concealed.
Presentation latency remains unverified against the required margin: Event Timing medians fell 72→56 ms, but the 16 ms improvement was smaller than the widest 32 ms run range. The next-paint proxy similarly improved 92.5→60.6 ms without clearing its 36 ms range.
Measurement driver · Seed script · Raw data, earlier series, scripts, and methodology
Not shown:
- A keystroke-to-paint improvement exceeding run-to-run spread was not established. Neither Event Timing nor the next-paint proxy cleared that threshold; the positive verdict concerns React CPU render duration.
- The historical absolute figures of 542→293 renders and 40→24 ms latency were not reproduced. This merge-base comparison measured median totals of 730→472 renders.
- Provider-specific runtime-mode choices and administrator policy ceilings were not exercised; behavioral verification covered typing, clearing, text preservation, and the displayed replay model.
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge merged thise2afd25
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes