Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(web): typing no longer re-renders the composer's footer controls #32323

MergedOmarAlex24(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/32323/headmerged by juliusmarminge View on GitHub

Problem

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:

    scenariorenders
    app-type-in-composer542 → 293 (−46%)
    app-open-settings619 → 559
    app-switch-settings-section703 → 663
    app-switch-thread3524 → 3361
    app-mount-thread2956 → 2847

    In app-type-in-composer: ComposerControlsBar, ComposerModelPicker and ComposerControl go from 21 → 1, CompactComposerControlsMenu 21 → 0, PopoverTrigger 42 → 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:

    beforeafter
    React render time per 20 keystrokes357 ms212 ms
    keystroke → next paint, median40 ms24 ms
    keystroke → next paint, p9048 ms40 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:changed passes (format, lint, knip, typecheck, React Compiler coverage).

Things I could not check, and notes:

  • On macOS, warm up and app-toggle-diff-panel time out on a clean main, because the scenario sends {Control>}d for mod+d. app-stream-assistant-turn also fails its MarkdownParagraph count 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

    2. Approvability

      Verdict: Approved at ecafd4e

      Macroscope'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).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The composer now calls useManagedPolicy before deriving compatible runtime modes. The typing scenario asserts that ComposerControlsBar renders 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.tsx
      useManagedPolicy runs before compatible runtime-mode derivation. The typing scenario asserts that ComposerControlsBar renders once.

      Estimated code review effort: 2 (Simple) | ~8 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge, yuruzuu

      Merge Risk: Minimal · up to 7a51f

      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: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe 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 checkPassedThe 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 checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck 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 #27197 and #12689 without 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

      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.tsx
      • apps/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.

    4. tanstack-source added labelsbug

    5. juliusmarminge added labelstakeover:in-progress

    6. 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 fox at 150 ms/key, then waited two seconds. Nine measured repetitions followed ten warm-ups on each commit.

      BeforeAfter
      f00afc6cda7a51fbdf04
      Before: repeated measurement outputAfter: repeated measurement output
      React render duration: 909.1 ms median, range 716.7–1104.5490.4 ms median, range 420.2–576.7
      Footer renders: 21 in every run1 in every run
      Total renders: median 730472 in every run
      Before: preserved typed textAfter: preserved typed text
      Before interaction recordingAfter 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.
    7. juliusmarminge added labelstakeover:ready

    8. juliusmarminge removed labelstakeover:in-progress

    9. juliusmarminge merged thise2afd25

    10. juliusmarminge closed this

    11. juliusmarminge removed labelstakeover:ready

Sign in to join this conversation.