fix(composer): flush debounced autocomplete detection on Tab/Enter#1541
Open
wesbillman wants to merge 1 commit into
Open
fix(composer): flush debounced autocomplete detection on Tab/Enter#1541wesbillman wants to merge 1 commit into
wesbillman wants to merge 1 commit into
Conversation
Composer autocomplete detection is debounced 120ms, but Tab/Enter committed suggestions synchronously from the previous query's list. A fast "type @cl, hit Tab" inside that window inserted the top of the stale unfiltered list (e.g. @fizz) instead of the typed match. On Tab/Enter, flush the pending detection: re-detect the query from the latest text and commit the fresh top match (mentions, channel links), or refresh the dropdown instead of committing when results are async (emoji). Start indices move to refs so the replaced range can't go stale the same way. Extracts mention candidate helpers to mentionCandidates.ts to keep useMentions.ts under the file-size limit. Co-authored-by: Brain <21994759fc7a6fa6b965551d35cfd7897d262f2495467f2d78694ddcfa6a5c7e@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Wes <wesbillman@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.
Problem
Reported by DK: typing
@cland quickly hitting Tab right after the composer regains focus commits "@fizz" (the first entry of the unfiltered list) instead of the intended match, forcing him to back it out and retype.Root cause
Composer autocomplete detection is debounced 120 ms (
MENTION_DEBOUNCE_MS, introduced in #222 to reduce input lag): keystrokes only stash the latest text in refs and schedulesetMentionQueryfor later. ButhandleMentionKeyDowncommits Tab/Enter synchronously againstsuggestions[selectedIndex]— a list ranked for the previous query. Type inside the debounce window and Tab commits the stale list's top entry. The#channeland:emoji:autocompletes share the identical pattern.Fix
On Tab/Enter, if a detection is pending, flush it synchronously:
useMentions.tscrossed the 1000-line guard with the flush branch, so the pure candidate helpers (MentionCandidatetype, label/owner formatters) moved to a newmentionCandidates.ts— no logic changes there.Testing
@, typebo+ Tab inside the debounce window, assert@bobis inserted. Verified it fails against the unpatched code and passes with the fix.mentions.spec.tse2e suite: 31/31 passing.pnpm test(1625 unit tests),pnpm typecheck,pnpm check(biome + file sizes) all green.Fixes the race DK reported in typing-improvements.