Conversation
…oundary handling - Updated `useSuggestionMenu` to apply synchronous `getItems` results without rendering an empty loading state, improving user experience during typing. - Enhanced `resolveSuggestionMenuTarget` to anchor on the last whitespace-triggered character, allowing for more intuitive query handling. - Introduced tests to validate the new behavior for both synchronous and asynchronous item fetching, ensuring stability and correctness. No breaking changes introduced.
Member
Author
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit cc0b350. Configure here.
This branch has not been deployed
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
resolveSuggestionMenuTarget: withboundary: "whitespace", the match now anchors on the last trigger that has whitespace (or the start of the lookbehind) before it, instead of rejecting when the last trigger character does not. A later trigger character is part of the query, so@ada@exampleresolves as one query rather than closing the menu at the second@.boundary: "any"is unchanged.useSuggestionMenu:getItemsresult is applied in the same state update as the new target, with no intermediateloadingrender.getItems, a query refined on the same trigger keeps the previousitemswhilestatusisloading. Stale responses are still dropped.getItemsthat throws synchronously now resolves to theerrorstate instead of escaping the refresh.@input/pen-types: newisPromiseLikeguard, used by the hook and by core's extension lifecycle in place of two inline thenable checks.Why
A host that renders the menu only while it has items saw it close and reopen on every keystroke, and a whitespace-bounded trigger could not be used for queries that contain the trigger character, such as email addresses.
Breaking
Yes, for hosts using
boundary: "whitespace"that relied on a second trigger character closing the menu (for example:smile:). SetclosingCharto keep that behaviour.Specs and changesets
spec/rules/selection.md(N6) andspec/packages/rendering/react.mdamended.@input/pen-coreminor (breaking), and@input/pen-react/@input/pen-core/@input/pen-typespatch.Testing
resolveSuggestionMenuTarget.n6.test.tsfor the anchoring and the no-valid-trigger case.suggestionMenu.staleResults.test.tsxfor the synchronous path, retained items during loading, and the synchronous throw.Note
Medium Risk
Breaking change to whitespace-boundary trigger resolution affects mention/emoji hosts; menu refresh logic changes observable loading/error behavior in React suggestion UIs.
Overview
Suggestion menus get steadier UX and more predictable trigger matching.
resolveSuggestionMenuTargetwithboundary: "whitespace"now anchors on the last@(or trigger) that has whitespace or lookbehind start before it, so text like@ada@exampleis one query instead of reopening at the second trigger. Hosts that depended on a second trigger character to close the menu (e.g.:smile:) should setclosingChar.boundary: "any"is unchanged.useSuggestionMenuavoids blanking the list on each keystroke: synchronousgetItemsapplies items in the same update (no flash of emptyloading); async refreshes on the same trigger keep prioritemswhileloading; synchronous throws surface aserror.isPromiseLikeis exported from@input/pen-typesand shared by the hook and extension activate/deactivate lifecycle.Reviewed by Cursor Bugbot for commit cc0b350. Bugbot is set up for automated code reviews on this repo. Configure here.