[Bug] Chat trigger menu: a trigger typed right after a token doesn't open (the token's NBSP isn't a boundary)
Description
After a token is inserted in ChatComposerInput, useChatComposerTokens puts a non-breaking space (' ') after it. useTriggerMenu does not treat that character as whitespace, so a trigger typed straight after a token never opens its menu.
Two checks in dist/Chat/useTriggerMenu.js (src/Chat/useTriggerMenu.tsx) only know ' ', '\t' and '\n':
isTriggerBoundary(char)— the character before@is the token's NBSP, so@is not seen as starting a trigger.- In
findActiveTrigger, the single-word query end checkif (char === ' ' || char === '\t')— an NBSP does not end an active single-word query either.
Expected: the NBSP Astryx itself inserts after a token counts as a word boundary, the same as a typed space, so @Ana @ opens the @ list for the second mention on the same line.
Suggested fix: add char === ' ' to both checks (or use a shared isWhitespace helper). A downstream app has carried exactly that two-line patch since 0.7.12 and the second-mention case works with it.
Reproduction
- Render
ChatComposerInputwith an@trigger that inserts a token on select. - Type
@, pick an item. The token is inserted followed by an NBSP, cursor after it. - Without typing a regular space, type
@again. - The trigger menu does not open. Typing a regular space first (
@Ana @) does open it.
The same applies to any trigger character (#, /) right after a token.
Astryx Version
@astryxdesign/[email protected] (also present in 0.7.12 and 0.7.18-canary.gfca8508)
Environment
Any browser; the behaviour is in the trigger parser and is not platform-specific.
I have a potential solution for this. I've started working on updating the trigger parser to recognise non-breaking spaces (NBSP) as valid whitespace boundaries, both when detecting trigger starts and when determining the end of single-word queries.
I'll test the fix against the consecutive mention/trigger scenario and check for any regressions. I'll raise a PR shortly with the changes for review.
Hi @StephenSHorton
I've been investigating #13676 and have a potential fix ready locally, along with regression tests covering both the trigger-boundary detection and single-word query termination.
While investigating, I noticed that the current ChatComposerInput specification (FR10) explicitly states that NBSP should not be treated as a boundary, which appears to conflict with the behaviour requested in this issue.
I also noticed that the specification is marked as current and wanted to check before making a PR that changes an explicitly documented requirement.
@cixzhang , could you please clarify whether NBSP is intended to be treated as a valid trigger boundary after an inserted token?
If this is the intended behaviour, I'm happy to include the corresponding FR10/FR11 specification updates alongside the implementation and tests.
I haven't raised a PR yet and wanted to get your input first. Thanks!
🤖 (Posted by Cindy's agent.) Thanks for the clear report, @StephenSHorton. Confirmed on main: useTriggerMenu treats only a space, a tab or a line break as a boundary. The current ChatComposerInput spec says on purpose that the no-break space after an inserted token is not a boundary, so making @Ana @ open the menu is a spec change, and a maintainer decision on it is pending. @LekhNayak, thanks for working on this! Please hold your pull request until that decision; if it's a yes, your fix is welcome, with credit. We'll update here.
Thanks!