Skip to content

Stabilize composer provider state while typing#3507

Merged
juliusmarminge merged 1 commit into
mainfrom
cursor/component-performance-optimization-7e06
Jun 22, 2026
Merged

Stabilize composer provider state while typing#3507
juliusmarminge merged 1 commit into
mainfrom
cursor/component-performance-optimization-7e06

Conversation

@cursor

@cursor cursor Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What Changed

  • Split composer provider state derivation from raw prompt text by introducing a small prompt-injection state (none / ultrathink).
  • Kept ultrathink styling behavior intact while avoiding provider option dispatch/model selection recomputation for ordinary prompt edits.
  • Updated existing provider-state tests and removed placeholder empty prompt arguments from model selection call sites.

Why

React Doctor and a manual hot-path pass pointed at the chat composer/model controls as a performance-sensitive typing path. Previously, every keystroke invalidated getComposerProviderState, rebuilt provider option dispatch state, and changed selectedModelSelection identity even when the prompt did not cross the ultrathink boundary. The new dependency is stable for ordinary typing and only changes when prompt-injected effort state actually changes.

React Doctor scan after the fix still reports the broader existing repo baseline (166 performance issues; top unrelated items include HostedBrowserWebview, BranchToolbarBranchSelector, and ChatView), so this PR intentionally fixes one focused hotspot.

UI Changes

No intentional UI change. React Scan before/after recordings captured the real composer route with React Scan enabled:

  • react_scan_before_provider_state_count.mp4: before state, repeated [react-scan] getComposerProviderState count logs during typing.
  • react_scan_after_provider_state_count.mp4: after state, React Scan remains active while ordinary typing no longer triggers those provider-state count logs.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Validation:

  • corepack pnpm --filter @t3tools/web test -- src/components/chat/composerProviderState.test.tsx (web unit suite passed)
  • corepack pnpm exec vp check
  • corepack pnpm exec vp run typecheck
  • corepack pnpm dlx react-doctor@latest --category performance --no-telemetry (completed; exits non-zero due existing baseline issues)
Open in Web View Automation 

Note

Stabilize composer provider state by separating prompt injection state from raw prompt string

  • Introduces ComposerPromptInjectionState (a 'none' | 'ultrathink' union) and getComposerPromptInjectionState in composerProviderState.tsx to map a prompt string to a discrete state value.
  • Updates getComposerProviderState to accept promptInjectionState instead of prompt, defaulting to 'none', so the provider state no longer recomputes on every keystroke.
  • Memoizes composerPromptInjectionState in ChatComposer.tsx and passes it to getComposerProviderState, decoupling provider state changes from raw prompt edits.
  • Removes the prompt argument from getComposerProviderState call sites in modelSelection.ts, where no injection state is needed.

Macroscope summarized 2655576.


Note

Low Risk
Focused memoization/API tweak on the composer typing path with unit tests; ultrathink styling logic is unchanged aside from when recomputation runs.

Overview
Reduces chat composer work on every keystroke by deriving provider/model dispatch state from a coarse prompt injection state (none | ultrathink) instead of the full prompt string.

getComposerPromptInjectionState maps the prompt via isClaudeUltrathinkPrompt; getComposerProviderState now takes promptInjectionState (default none) so ultrathink frame/chroma styling still toggles at the same boundary, but ordinary typing no longer invalidates modelOptionsForDispatch or selectedModelSelection on each character.

ChatComposer memoizes injection state separately and passes it into provider state; modelSelection call sites drop the unused empty prompt argument. Tests cover the new helper and updated ultrathink cases.

Reviewed by Cursor Bugbot for commit 2655576. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Jun 22, 2026
@juliusmarminge
juliusmarminge marked this pull request as ready for review June 22, 2026 19:38
@macroscopeapp

macroscopeapp Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

This is a performance optimization that memoizes prompt injection state derivation, preventing unnecessary recomputation on every keystroke. The functional behavior remains identical—only the timing of when the state is computed changes.

You can customize Macroscope's approvability policy. Learn more.

@juliusmarminge
juliusmarminge merged commit f5f98cf into main Jun 22, 2026
20 checks passed
@juliusmarminge
juliusmarminge deleted the cursor/component-performance-optimization-7e06 branch June 22, 2026 19:52
imabdulazeez added a commit to imabdulazeez/t3code that referenced this pull request Jun 23, 2026
…top of upstream

Incoming: pingdotgg#3480 (persistent word-wrap), pingdotgg#3507 (composer provider state),
pingdotgg#3496 (mobile composer draft persistence).

- Word-wrap feature converged with upstream's pingdotgg#3480: took upstream's wordWrap
  setting/wiring everywhere it overlapped (settings.ts, ChatMarkdown,
  FilePreviewPanel, DiffPanel, SettingsPanels, DesktopClientSettings.test).
  Removed the now-redundant word-wrap row from FORK-CHANGES.md.
- Re-applied fork-only settings on top of upstream's settings.ts/test fixture
  (branch sort/sync, font pickers, VCS prompt instructions, auto-create-PR,
  changed-files-expanded, delete-remote-branch, buildTimestamp).
- ChatComposer: upstream's pingdotgg#3507 provider-state refactor + fork's plan actions.
simonbetton pushed a commit to simonbetton/reviewer that referenced this pull request Jun 29, 2026
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants