Avoid extra composer menu highlight renders#2794
Draft
cursor[bot] wants to merge 3 commits into
Draft
Conversation
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
docs/react-scan-recordings/composer-menu-highlight-before.webmdocs/react-scan-recordings/composer-menu-highlight-after.webmWhy
React Doctor flagged the menu highlight sync as derived state updated from an effect, causing an avoidable follow-up render when the composer command menu opens or filters. The new approach follows React's “you might not need an effect” guidance by keeping the active menu item as render-time derived data and reserving state updates for user navigation.
React Doctor full scan found the wider app still has existing issues, but the targeted diff score is 95 and the removed
no-derived-state/highlight-sync finding is gone.UI Changes
No intended visual change. The committed React Scan recordings exercise the same
/mcomposer command-menu interaction before and after the fix with React Scan enabled.Checklist
Verification:
bun run test src/components/chat/composerMenuHighlight.test.ts(fromapps/web)npx -y react-doctor@latest apps/web --project @t3tools/web --diff main --offline --jsonbun fmtbun lintbun typecheckNote
Reduce extra renders in composer menu highlight by computing nudge from active item
useEffectin ChatComposer.tsx that synced highlight state with menu open/close and dependency changes, so highlight state no longer resets when the menu closes.resolveComposerMenuNudgedItemIdin composerMenuHighlight.ts, a utility that computes the next/previous item id with wrap-around, used by thenudgeComposerMenuHighlightcallback instead of readingcomposerHighlightedItemIddirectly.activeComposerMenuItem?.id(the server-resolved active item) rather than the previously stored highlighted id, keeping keyboard navigation consistent with actual menu state.Macroscope summarized 83a0044.