Repository navigation
fix(Tokenizer): keep choices open after selection - #6360
fullstackhacker wants to merge 5 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewModified ComponentsTokenizer (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. Tokenizer - 1 issue(s)
Visual Regression46 of 494 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 26 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
fec89ef to
b39ca1e
Compare
b39ca1e to
5ed32df
Compare
03e04d4 to
b0c9e5d
Compare
There was a problem hiding this comment.
Thanks for the consecutive-selection fix — the Tokenizer behavior itself (committed choices filtered by ID, focus and menu staying open, safe closure at maximum/disabled/exhaustion) matches its approved contract. Changes are requested for separable items bundled with it:
- Direct
BaseTypeahead/Typeaheadbehavior changed: an already-open highlighted option can no longer be selected after a focusable-disabled transition, and the docs now promise that. The approved Tokenizer decision requires direct single-select behavior to stay unchanged, so please scope the new guard to the Tokenizer path (and restore the direct docs) or split that change for separate owner approval. - This PR also removes the global review-routing machinery (the knowledge-contracts routing claims, its validator/tests, and the baselines script, plus routing blocks across many records) and deletes the ChartSwatch spec and most of its consumer documentation. Neither is mentioned in the PR description; please split both into their own changes.
- The required exact-head browser interaction evidence for the retained menu (pointer/keyboard, terminal and disabled states, dismissal, stale results, unchanged direct behavior) still needs to be provided.
[Automated review]
There was a problem hiding this comment.
Thanks for the consecutive-selection fix — the Tokenizer behavior itself matches its approved contract: committed choices are filtered by ID, focus and the menu stay open with the next choice active, terminal states close safely, and direct BaseTypeahead/Typeahead behavior (including selection after a focusable-disabled transition) is preserved. No implementation changes are requested.
One step remains before approval: the governing contract requires reviewer-collected exact-head browser evidence for this retained-menu behavior, and that collection could not run on this branch revision because the branch is behind current main. Please sync the branch with current main so a clean changed-file set can be verified, and the pointer/keyboard, terminal, disabled, dismissal, and unchanged-direct-behavior matrix can be collected. The CI and independently reported browser evidence already on the PR is credited and does not need to be recreated.
[Automated review]
eff3614 to
89fd8b0
Compare
There was a problem hiding this comment.
Thanks for the consecutive-selection fix — the Tokenizer behavior itself matches its approved contract: committed choices are filtered by ID, focus and the menu stay open with the next choice active, terminal states close safely, and direct BaseTypeahead/Typeahead behavior (including selection after a focusable-disabled transition) is preserved. The focused unit tests pass, and no implementation changes are requested.
One step remains before approval: the governing contract requires reviewer-collected exact-head browser evidence for this retained-menu behavior. That collection was attempted on this revision — the changed-file gate passed and Storybook served the new stories — but no browser engine could open a page in this review environment, so the pointer/keyboard, last-choice fallback, terminal, disabled, dismissal, and unchanged-direct-behavior matrix still needs to be collected in a browser-capable environment. The CI and independently reported browser evidence already on the PR is credited and does not need to be recreated.
[Automated review]
There was a problem hiding this comment.
Thanks for the consecutive-selection fix — Tokenizer now matches its approved contract: committed choices are filtered by ID, focus and the menu stay open with the next choice active, terminal states (exhaustion, maximum, disabled, Escape, focus departure) close safely, and direct BaseTypeahead/Typeahead behavior, including selection of an already-open option after a focusable-disabled transition, is preserved.
The focused unit tests pass (212), and the retained-menu browser behavior was verified on this revision: pointer and keyboard consecutive selection, last-choice fallback, terminal closure, dismissal, and the unchanged direct path. No implementation changes are requested.
[Automated review]
There was a problem hiding this comment.
Thanks for the consecutive-selection fix: the Tokenizer behavior itself matches its current contract, but changes are needed before this can merge. The shared BaseTypeahead rewrite also changes direct single-select and typed-search behavior that the Tokenizer record (AV6, DEC-2) says must stay unchanged, the new layout effects conflict with the React runtime architecture, and the branch needs a rebase onto main, where five of these files now conflict.
- Replacing
searchSourcenow clears a pending typed query, so a caller that passes an inline source and re-renders ononChangeQuerynever gets results (the testclears a replaced source debounce without canceling unstarted workcodifies this); please keep the pending query and keep the new cancellation sequence on the Tokenizer path only. - The highlight-sync layout effect keeps the highlighted item in refs that render reads and sets state from an effect; please derive it from state and name the external system each remaining effect synchronizes.
- At 2,781 authored lines, please scope or split the change so the tests cover the Tokenizer verification map rather than the direct-path rewrite.
[Automated review]
| ); | ||
|
|
||
| useIsomorphicLayoutEffect(() => { | ||
| if (searchLeaseRef.current.source !== searchSource) { |
There was a problem hiding this comment.
Any searchSource identity change now runs releaseSearch(true), which clears the pending debounce timer. A caller that passes an inline source and re-renders on onChangeQuery never gets its typed query searched, in direct Typeahead/BaseTypeahead and in Tokenizer; the base searched it. The Tokenizer record (AV6, DEC-2) keeps direct single-select and typed-query behavior unchanged, so please keep the pending query and run it against the new source.
| ? menuItems[highlightedIndex]?.id | ||
| : undefined; | ||
| if (isTokenizer && highlightedIndex !== highlightedIndexState) { | ||
| // eslint-disable-next-line @eslint-react/set-state-in-effect -- controlled filtering shifted the same logical option to a new index |
There was a problem hiding this comment.
This effect copies a derived index back into state, and the preserved highlight comes from highlightedItemIdRef, which render reads. architecture:react-component-runtime INV3 and INV4 ask effects to name the external system they synchronize and keep refs out of rendered output; keeping the highlighted item id in state, or deriving the index during render, would remove the effect.
| await waitFor(() => expect(cancel).toHaveBeenCalledTimes(1)); | ||
| }); | ||
|
|
||
| it('clears a replaced source debounce without canceling unstarted work', async () => { |
There was a problem hiding this comment.
This test asserts that a typed query pending at source replacement is never searched by either source. On the base the pending query still runs, so this codifies a direct-path behavior change; please expect the new source to search the pending query instead.
The merge pre-commit formatter changed unrelated main files. Restore their exact upstream bytes; repository checks run explicitly because lint-staged would rewrite the same upstream files again.
There was a problem hiding this comment.
Thanks for the consecutive-selection work: the Tokenizer menu now stays open after each pick, as its contract asks, but changes are needed before this can merge. After a pointer pick, clicking another control closes the menu yet leaves focus in the Tokenizer. Three shared-engine changes contradict current contracts, and the change is still over 2,000 lines.
- Keep focus on the control a person clicks after a pointer pick, and add a Chromium case for it.
- Keep the highlighted item in state instead of in refs that render reads (
BaseTypeahead.tsxlines 571–595). - Call
SearchSource.cancelbeforeonChangeagain for direct single-select picks. - Cap grouped bootstrap results in source order, so the first open shows the same values as before.
- Remove the pull-request status from
Tokenizer.spec.md, reword the source-replacement changeset, and split the direct-path work into its own change.
[Automated review]
| ? menuItems[highlightedIndex]?.id | ||
| : undefined; | ||
| if (isTokenizer && highlightedIndex !== highlightedIndexState) { | ||
| // eslint-disable-next-line @eslint-react/set-state-in-effect -- controlled filtering shifted the same logical option to a new index |
There was a problem hiding this comment.
This layout effect copies a derived index back into state, and the rendered highlight (aria-activedescendant) comes from highlightedItemIdRef, which render reads (architecture:react-component-runtime INV4; INV3 asks an effect to name the external system it synchronizes). Keeping the highlighted item id in state and deriving the index during render would remove the effect.
| resultsGenRef.current = searchGenRef.current; | ||
| setHighlightedIndex(Math.max(menuItems.indexOf(item), 0)); | ||
| } else { | ||
| invalidatePending(true); |
There was a problem hiding this comment.
On the direct path this now runs after onChange(item), so SearchSource.cancel fires after onChange (the base cancelled first) and the close-time cancel disappears. Tokenizer AV6 keeps direct single-select behavior unchanged; please invalidate before onChange when the menu is not retained.
| const ordered = groupItems(projected, {ungroupedFirst: true}).flatMap( | ||
| group => group.items, | ||
| ); | ||
| return query.length === 0 ? ordered.slice(0, maxMenuItems) : ordered; |
There was a problem hiding this comment.
Capping after group ordering changes the first-open cohort: grouped bootstrap results beyond maxMenuItems now show later ungrouped values (Solo Carol, Solo Dan) instead of the caller's first ones (Team Alice, Team Bob). Slicing the projected list in source order before grouping keeps the base cohort and still reveals the next value after a pick.
| | End-user impact | People selecting several loaded values can continue without reopening the menu, while disabled, loading, exhausted, and dismissed states remain non-interactive. | | ||
| | Builder impact | None. Existing opt-in callers need no migration or refetch, and typed-query selection remains unchanged. | | ||
| | Compatibility/readiness | The default `hasEntriesOnFocus={false}` path and direct single-select BaseTypeahead remain unchanged. This decision is current and owner-approved; implementation and exact-head interaction evidence remain pending in #6360. | | ||
| | Compatibility/readiness | The default `hasEntriesOnFocus={false}` path and direct single-select BaseTypeahead remain unchanged. This decision is current and owner-approved; #6360 supplies the implementation, with exact-head interaction evidence required before merge. | |
There was a problem hiding this comment.
architecture:knowledge-contracts INV10 keeps pull requests out of current records. "#6360 supplies the implementation, with exact-head interaction evidence required before merge" (and the FR13–FR15 status below) goes stale at merge; please state the durable status instead.
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] Typeahead and Tokenizer preserve pending debounced queries when the search source is replaced, and search the latest source without delaying the query again. |
There was a problem hiding this comment.
On the released package a query pending at source replacement was already searched, by the replaced source. What changes for consumers is that the new source runs it, so the note should say that rather than that pending queries are now preserved.
|
(Posted by Cindy's agent.) Thank you, @fullstackhacker! Your work here shaped what shipped: #11031 landed a Tokenizer that keeps its choices open after you pick one, with the focus list narrowed to the text you typed, and it credits you as co-author. Closing this one since that change delivers it. |
Conflict resolution and pending-search restoration
Current source head:
3e706b2e36ec8c017d83652170054b95b39e6244. The branch includesmainatfccd7713e4eac12666477ea5b34fc35466ec5037without rewriting the author's history.The five conflicts were resolved by combining the Tokenizer retained-selection path with main's current API, in-flow caret/layout, selected-label Create suppression, rendered empty-state announcements, trailing consumer key handlers, source-change busy reset, and focused-input click reopening. Pending debounced searches survive source replacement and use the latest committed source at their original deadline.
Focused regression coverage also preserves pending autofocus work through StrictMode replay for both Typeahead and Tokenizer; actual unmount releases its source lifetime once.
Validation of the resolved head
Merged-head frames
Sensor receipts verified the exact served merged source, neutral/light/LTR, 1280×800 at DPR1, fine pointer/hover, query/focus/option/active-descendant state, visible non-zero geometry, settled fonts, and no page/console errors.
Remaining review scope
This conflict resolution does not claim to clear the earlier review's independent concerns about shared cancellation ordering, highlight-state representation, or test scope. The new head needs its own review and all required checks. No merge to
mainhas been performed.Writing rubric results
R1 narration: the inherited Tokenizer readiness table still references implementation status; this PR changes status/evidence only, not behavioral requirements.
R2 research: no new research in the record; runtime evidence stays in this description.
R3 evidence: inherited basis references remain; no new behavioral authority is inferred from commits or pull requests.
R4 alternatives: no new alternative or decision is introduced.
R5 change references: inherited PR references remain outside this conflict-resolution scope; no new standing change reference is added.
R6 open questions: the component record has none; no policy question is answered by this merge.
Original background and earlier-head evidence
The description below records the original implementation and earlier-head captures; the current resolved-head results are above.
Problem
Tokenizer's multi-value editor inheritedBaseTypeahead's single-select closure and async lifecycle. Selecting one value cleared and closed the choices, forcing people to refocus the input or type again before choosing another value.Correct fix
Tokenizernow opts into additive selection through package-private behavior governed bycomponent:TokenizerDEC-2; no public API is added. Committed values are filtered bySearchableItem.id, so distinct IDs remain eligible even when labels match. Focus and the popup stay open while another loaded choice remains. Disabled Tokenizer blocks additions and removals; enabled Tokenizer atmaxEntriesstill permits removal. Both states block additions, query changes, search, bootstrap, navigation, Create, and already-open selection.One nullable-generation search lease owns each bootstrap or search lifetime and cancels it exactly once on replacement, terminal closure, or unmount. Direct
BaseTypeaheadand publicTypeaheadpreserve their established select-clear-close lifecycle and callback order. Their focusable-disabled state still prevents query and text mutation, while an option that was already open and highlighted before the transition remains selectable through the established keyboard or pointer path.Implementation
Tokenizeralways supplies its committed-ID-filtered source and rejects additions at the maximum or while disabled; disabled state also blocks removals.BaseTypeaheadrefreshes the remaining loaded choices after a committed Tokenizer selection, keeps a stable active item, and prevents dismissed or stale async work from reopening the popup.maxEntriespermits removal. DirectBaseTypeaheadandTypeaheadretain their established already-open Enter and pointer selection behavior, then clear and close normally.Scope
Exact two-commit stack:
2e7c02139f9372959a98bac6fbeed2b41f511e20followed byc2e153fe18787750aaf8c7f7972cb6136a95671a.The canonical PR patch at head
c2e153fe18787750aaf8c7f7972cb6136a95671acontains exactly these nine feature paths:.changeset/keep-tokenizer-s-bootstrap-menu-open-and-focused-quln.mdapps/storybook/stories/TokenizerSelectionA11y.stories.tsxpackages/core/src/Tokenizer/Tokenizer.doc.mjspackages/core/src/Tokenizer/Tokenizer.spec.mdpackages/core/src/Tokenizer/Tokenizer.test.tsxpackages/core/src/Tokenizer/Tokenizer.tsxpackages/core/src/Tokenizer/__tests__/TokenizerSelection.a11y.chromium.spec.tspackages/core/src/Typeahead/BaseTypeahead.tsxpackages/core/src/Typeahead/Typeahead.test.tsxpackages/core/src/Typeahead/BaseTypeahead.doc.mjsis restored to the base inside the stack and is absent from the net diff. No review-routing or ChartSwatch path is in the canonical PR patch.Verification Steps
An independent Storybook build directly from exact head
c2e153fe18787750aaf8c7f7972cb6136a95671awas served on loopback in a Linux container with networking disabled. A fresh headless Chromium149.0.7827.0used a unique profile, with Playwright connected over CDP. All seven retained-menu and direct-compatibility running-browser scenarios passed:Alice Johnson, kept the input focused witharia-expanded="true", and movedaria-activedescendantto the visibleBob Smith; selectingBob Smiththen closed the exhausted menu and cleared the active descendant.Bob Smithdescendant; the terminal Enter closed the popup and cleared the active descendant.maxEntriesalso closed it, cleared the active descendant, and left the mounted input read-only.BaseTypeaheadkept the already-openReactoption active after becoming focusable-disabled; Enter committedreact, cleared the query, and closed the popup.Typeaheadkept the already-openReactoption active after becoming focusable-disabled; pointer selection committedreact, cleared the query, and closed the popup.A separate current-main integration scenario also passed:
NearFullTokenRowLTR and RTL runs at1280 × 900with a coarse pointer passed: with the placeholder temporarily removed, the ordinary in-flow editing input wrapped below the final token (47 >= 44), while the real one-space-placeholder input stayed on the token row (22 < 44); focus and Clear-all/token hit targets passed.The runs recorded no console errors, page errors, request failures, or HTTP errors.
The reviewed exact-head PixelCloud capture comes from standalone story
a11y-tokenizer-consecutive-selection--capped-cohortand showsAlice Johnsoncommitted withBob Smithvisible and active. PixelCloud revision 1 now has a title and description naming exact headc2e153fe18787750aaf8c7f7972cb6136a95671a; its screenshot bytes remain SHA-256b9cd8cd11e7d359f8c005a73d980058600b93f999b7a2b6e967b7c893a69b400,1280 × 813.Package release
The existing
.changeset/keep-tokenizer-s-bootstrap-menu-open-and-focused-quln.mdrecords an@astryxdesign/corepatch release. Smoldata consumes the fix after that package release.