Repository navigation
feat(Typeahead): show local matches at once and append server results (spec:AST-092) - #7962
Conversation
…ge remote results for the same query
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC |
|---|---|---|
| Typeahead | 65.6 kB (+1.1 kB) · 11.6 kB CSS (+17 B) | — |
| PowerSearch | 172.9 kB (+1.1 kB) · 20.3 kB CSS (0) | — |
| Tokenizer · Storybook | 72.7 kB (+1.1 kB) · 16.9 kB CSS (0) | 1,963 (+10) |
6 more components
| Component | Size | LoC |
|---|---|---|
| lab/MobilePowerSearch | 159.2 kB (+1.0 kB) · 1.2 kB CSS (0) | — |
| BaseTypeahead | 57.9 kB (+1017 B) · 10.2 kB CSS (+17 B) | — |
| TypeaheadItem | 6.3 kB (0) · 3.6 kB CSS (0) | — |
| lab/CommentComposer | 97.2 kB (0) · 1.9 kB CSS (0) | — |
| lab/Comments | 224.8 kB (0) · 2.5 kB CSS (0) | — |
| lab/CommentThread | 220.2 kB (0) · 2.4 kB CSS (0) | — |
Package size: @astryxdesign/core 6.53 MB packed (+7.9 kB); no new dependencies.
Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.
Generated by PR Enrichment workflow | View full report
… rejection after close
3a6ccf5 to
61a27be
Compare
…ose keys off the current query
…xt.update (spec:AST-092)
…y, docs, Changeset
…he field, silent rejection after close
…ction keeps only this query's rows; above-field story
61a27be to
ca5cef9
Compare
There was a problem hiding this comment.
This pull request is on hold until an engineering owner approves spec:AST-092 for the current head: the spec-owner-approval check is still pending, and the record's own approved_by field is not that approval, so the owner needs to settle FR1–FR10 and DEC-1–DEC-3, including item-keyed option ids (FR7) and keeping partial results when the server fails (FR9). Whatever that decision, these need fixing before merge:
- The popup height held for a later list is cleared only by the next query's first list (
BaseTypeahead.tsx:849), so after a selection or a cleared field the bootstrap list opens at the old height with two of eight rows visible; reset it wherever a query ends. - The description needs the
## Writing rubric resultssection that a pull request adding a knowledge record reports. - The incremental stories'
cancel()clears the timer without settling the promise, so pressing Escape leaves the field busy; reject or resolve the pending search there.
[Automated review]
| : displayOrder(shownRows)[0]?.id; | ||
| holdPopupInPlace(); | ||
| } else { | ||
| setHeldHeight(null); |
There was a problem hiding this comment.
This is the only place heldHeight is cleared, so a hold set for one query survives a selection, a cleared field and the bootstrap list. With hasEntriesOnFocus, clearing the field after a held query opens the eight-row bootstrap list in a 72 px popup. Consider resetting it wherever a query stops being current (handleSelect, the short-query branch of handleQueryChange, applyBootstrapResults, handleLayerHide), with a test that clears the field after a held list.
| let pendingDirectoryRequest: ReturnType<typeof setTimeout> | null = null; | ||
| const incrementalPeopleSource: SearchSource = { | ||
| bootstrap: () => localPeople, | ||
| cancel() { |
There was a problem hiding this comment.
cancel() clears the timer, so the promise search returned never settles. Pressing Escape over the local rows calls cancel(), and the field stays busy until the next keystroke. Rejecting the pending promise here (or resolving it with local) lets the query settle the way FR9 expects.
…y cancel settles the search
There was a problem hiding this comment.
This pull request is on hold until an engineering owner approves spec:AST-092 for the current head: the spec-owner-approval check is still pending, and the owner also needs to settle whether FR6's rule that a popup below the field grows only within the room below it amends the layer runtime's rule that no layer size is capped to the space beside its trigger, or whether FR6 changes. Whatever that decision, two fixes are needed before merge:
- Every later list re-runs the highlighted-row scroll (
useHighlightedOptionScroll, fed byBaseTypeahead.tsx:1314-1335), so a partial list someone has scrolled jumps back to its first row when the server rows arrive; skip that scroll when the highlighted item is unchanged and add a browser check that scrolls a partial list. - Unmounting while a partial list shows lets the cancelled search announce "2 results" after the field is gone; end the search generation in the unmount cleanup before calling
cancel().
[Automated review]
| (index: number) => `${listboxId}-option-${index}`, | ||
| [listboxId], | ||
| (index: number) => optionIds[index] ?? `${listboxId}-option-${index}`, | ||
| [optionIds, listboxId], |
There was a problem hiding this comment.
getItemId changes identity with every list, and useHighlightedOptionScroll re-runs scrollIntoView({block: 'nearest'}) when getOptionId or itemCount changes. So each later list for the same query scrolls the popup back to the highlighted row: in Chromium a partial list scrolled to 200 px jumped to 4 px when two server rows appended, which moves the rows under a touch or scrollbar user. Consider skipping the scroll when the highlighted item is unchanged (for example keying it on the highlighted option id, which FR7 keeps stable), with a browser check that scrolls a partial list before the final list lands.
| } else if (shownRows != null) { | ||
| // A failed server answer keeps the last non-empty list the source | ||
| // showed for this query, which settles it. | ||
| announceCount(showList(shownRows, true).length); |
There was a problem hiding this comment.
The unmount cleanup (prevSearchSourceRef.current.cancel?.(), around line 1347) cancels without bumping searchGenRef, and the popup-close marker is not set on unmount. A source whose cancel() rejects then lands here and announces "2 results" after the field is gone; Chromium shows it in the polite region. Bumping the generation in the unmount cleanup before cancel() would drop it, as FR4 describes for unmount.
| // Below the field, grow only within the room below, so the layer runtime | ||
| // never flips the popup above the field. | ||
| const layer = dropdown.closest<HTMLElement>('[popover]') ?? dropdown; | ||
| const layerBox = layer.getBoundingClientRect(); | ||
| const gutter = parseFloat(getComputedStyle(layer).marginBlockEnd) || 0; | ||
| const viewportHeight = window.visualViewport?.height ?? window.innerHeight; | ||
| const room = | ||
| viewportHeight - | ||
| box.top - | ||
| Math.max(0, layerBox.bottom - box.bottom) - | ||
| gutter; | ||
| setHeldHeight( | ||
| current => | ||
| current ?? Math.min(DROPDOWN_MAX_HEIGHT, Math.max(box.height, room)), | ||
| ); |
There was a problem hiding this comment.
This caps the listbox to the room below the field, measured here from the viewport, the listbox top and the layer gutter. architecture:layer-runtime INV11 says "no consumer defines its own, no size is capped to the span beside the trigger", and AST-092 does not amend it, so either the layer runtime record changes for this hold or FR6's below-field clause and this branch do.
…ter, scroll keyed to the list, mounted flag; slow-bootstrap, unmount and StrictMode tests
There was a problem hiding this comment.
This pull request is on hold until an engineering owner approves spec:AST-092 for the current head: the spec-owner-approval check is still pending, and the owner also needs to settle whether FR6's rule that a popup below the field grows only within the room below it amends the layer runtime's rule that no layer size is capped to the space beside its trigger, or whether FR6 changes. Whatever that decision, these need fixing before merge:
- In a grouped
TokenizerwithhasCreate, the create row is appended in source order but displayed above the groups, so the rows a partial list showed move down a row when the query settles (BaseTypeahead.tsx:835-837); displaying query entries after the groups, with a test for that state, would fix it. - The
lintcheck fails onBaseTypeahead.incremental.test.tsx:517(promise-function-async, cleared by declaring thatbootstraparrowasync), and the two new stories are not listed in the CI story play guard, so their play assertions never run.
[Automated review]
| const shown = isFinal | ||
| ? [...fetched, ...(__queryEntries?.(searchQuery, fetched) ?? [])] | ||
| : fetched; |
There was a problem hiding this comment.
The create row is appended in source order here, but the popup displays ungrouped rows first (displayOrder), so with grouped results it renders above the group and every row a partial list showed moves down a row when the query settles; in Chromium, Benita Ruiz moves from 144 to 176 px. The append check at :819-821 compares only the source rows, so no development warning fires either. Displaying query entries after every group would keep FR1's create row after the rows; a test that settles a grouped list with hasCreate after a partial list would cover it.
| // Below the field, grow only within the room below, so the layer runtime | ||
| // never flips the popup above the field. | ||
| const layer = dropdown.closest<HTMLElement>('[popover]') ?? dropdown; | ||
| const layerBox = layer.getBoundingClientRect(); | ||
| const gutter = parseFloat(getComputedStyle(layer).marginBlockEnd) || 0; | ||
| const viewportHeight = window.visualViewport?.height ?? window.innerHeight; | ||
| const room = | ||
| viewportHeight - | ||
| box.top - | ||
| Math.max(0, layerBox.bottom - box.bottom) - | ||
| gutter; | ||
| setHeldHeight( | ||
| current => | ||
| current ?? Math.min(DROPDOWN_MAX_HEIGHT, Math.max(box.height, room)), | ||
| ); |
There was a problem hiding this comment.
This caps the listbox to the room below the field (viewport height, listbox top, layer padding and the layer's gutter): in Chromium an eight-row final list stays below at max-height: 138px, where the layer runtime flips it above at its full height. architecture:layer-runtime INV11 says "no size is capped to the span beside the trigger", and AST-092 neither cites nor amends it, so either that record changes for this hold or FR6's below-field clause and this branch go.
| const {source, latest} = createPendingSource({ | ||
| ben: [benOrtiz, benitaRuiz], | ||
| }); | ||
| source.bootstrap = () => |
There was a problem hiding this comment.
CI's lint job fails here with @typescript-eslint/promise-function-async ("Functions that return promises must be async"); declaring this arrow async clears it.
… the CI guard; lint
There was a problem hiding this comment.
This pull request is on hold until an engineering owner approves spec:AST-092 for the current head: the spec-owner-approval check is still pending, and the owner also needs to settle whether FR6's rule that a popup below the field grows only within the room below it amends the layer runtime's rule that no layer size is capped to the space beside its trigger, or whether FR6 changes. Whatever that decision, these need fixing before merge:
- Unless that layer-runtime rule is amended, the below-field cap in
holdPopupInPlace(BaseTypeahead.tsx:620-634) has to go: it holds a seven-row list to the 158 px below a low field where the layer runtime would show it above at full height. - The Changeset says existing sources are unchanged; it should name the two changes every source sees, item-keyed option ids and a grouped
Tokenizer's create row moving after the groups.
The grouped create-row reflow, the lint error and the missing story play guard entries from the previous review are fixed, and the three failing CI checks come from MobilePowerSearch on main, not from this change.
[Automated review]
| // Below the field, grow only within the room below, so the layer runtime | ||
| // never flips the popup above the field. | ||
| const layer = dropdown.closest<HTMLElement>('[popover]') ?? dropdown; | ||
| const layerBox = layer.getBoundingClientRect(); | ||
| const gutter = parseFloat(getComputedStyle(layer).marginBlockEnd) || 0; | ||
| const viewportHeight = window.visualViewport?.height ?? window.innerHeight; | ||
| const room = | ||
| viewportHeight - | ||
| box.top - | ||
| Math.max(0, layerBox.bottom - box.bottom) - | ||
| gutter; | ||
| setHeldHeight( | ||
| current => | ||
| current ?? Math.min(DROPDOWN_MAX_HEIGHT, Math.max(box.height, room)), | ||
| ); |
There was a problem hiding this comment.
This caps the listbox to the room below the field (viewport height minus the listbox top, the layer padding and its gutter), so a final list that does not fit stays below and scrolls: in Chromium a seven-row list under a low field is held at max-height: 158px, where the layer runtime places it above the field at its full 232 px. architecture:layer-runtime INV11 says "no size is capped to the span beside the trigger", and AST-092 neither cites nor amends it, so either that record changes for this hold or FR6's below-field clause and this branch go.
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [feat] A `SearchSource` can show results before its search settles. `search(query, context)` may call `context.update(items)` (new exported type `SearchContext`) to show matches it already has, such as people the page loaded earlier, and then return the server's answer. `BaseTypeahead`, `Typeahead` and `Tokenizer` show each list for the current query, change the list at most once per keystroke, and add later rows only after the ones already shown, so the highlighted row never moves; the field stays busy and the result count is announced once, when the search settles. A later list that moves or removes shown rows is shown as given with a development warning. Existing sources are unchanged. To show local matches at once, pass `debounceMs={0}` and delay the server request inside the source (`spec:AST-092`). |
There was a problem hiding this comment.
"Existing sources are unchanged" reads as no change for current callers, but two changes reach every source here: option ids follow the item id instead of the row index, and a grouped Tokenizer with hasCreate shows its create row after the groups instead of first. Naming both keeps the Changeset an accurate compatibility note.
There was a problem hiding this comment.
This change can't be approved yet: spec:AST-092 is now current on main, but its FR6 rule that a popup below the field grows only within the room below it conflicts with the layer runtime's current INV11 (no layer size is capped to the space beside its trigger), so an engineering owner needs to amend one of those two records before the below-field cap can stand or go. Whatever that decision, two things need fixing:
- A row appended under a resting mouse pointer takes the highlight, so Enter can select a person the user never aimed at (FR6); rebasing onto
main, which usesonMouseMovefor option hover, fixes it, and the branch needs that rebase anyway because it conflicts withmain. - AST-092's verification asks for real-browser checks of a scrolled partial list and of a list below the field that outgrows the room below, so please add story plays for those and for the resting-pointer case.
[Automated review]
| // Below the field, grow only within the room below, so the layer runtime | ||
| // never flips the popup above the field. | ||
| const layer = dropdown.closest<HTMLElement>('[popover]') ?? dropdown; | ||
| const layerBox = layer.getBoundingClientRect(); | ||
| const gutter = parseFloat(getComputedStyle(layer).marginBlockEnd) || 0; | ||
| const viewportHeight = window.visualViewport?.height ?? window.innerHeight; | ||
| const room = | ||
| viewportHeight - | ||
| box.top - | ||
| Math.max(0, layerBox.bottom - box.bottom) - | ||
| gutter; | ||
| setHeldHeight( | ||
| current => | ||
| current ?? Math.min(DROPDOWN_MAX_HEIGHT, Math.max(box.height, room)), | ||
| ); |
There was a problem hiding this comment.
This caps the listbox to the room below the field, which current AST-092 FR6 asks for and current layer-runtime INV11 rules out (“no consumer defines its own, no size is capped to the span beside the trigger”). In Chromium a seven-row list under a low field stays below at max-height: 198px where the layer runtime would flip it above at 232 px. One of the two records needs an engineering owner's amendment before this branch can stay or go.
| (index: number) => highlightedOptionId ?? `${listboxId}-option-${index}`, | ||
| [highlightedOptionId, listboxId], | ||
| ); | ||
| const highlightOnHover = useHighlightedOptionScroll({ |
There was a problem hiding this comment.
highlightOnHover is still wired to each option's onMouseEnter (line 1512), so a row appended under a resting pointer takes the highlight: in Chromium, Ben Ortiz is highlighted while pending, Bento Silva takes it when the server rows land, and Enter selects Bento Silva (FR6). main switched this handler to onMouseMove; keeping that when resolving the conflict with main fixes it.
…en Typeahead popup; story plays for a scrolled list, a below-field overflow and a resting pointer
There was a problem hiding this comment.
This can't be approved yet: the head adds an exception to current architecture:layer-runtime INV11 so a Typeahead's later list can stay below the field, and an engineering owner needs to record that decision by commenting /approve-spec <full head SHA> on the corrected head (the author can do this if they are an engineering owner), or ask for spec:AST-092 FR6's below-field clause to change instead. Two fixes are needed either way:
- The merge with
mainreverted #9182, #9183 and #9198 in.github/REVIEW_GATE.md,docs/architecture/interaction-modality.md,docs/architecture/knowledge-contracts.md,docs/architecture/public-component-api.mdanddocs/specs/AST-030/spec.md(it deletes public-component-api INV23); please restoremain's versions, since an approval binds the head's whole spec content. - The FR9 failure path (
BaseTypeahead.tsx:970-973) announces the count without dropping a pending busy start, so a source that fails a few milliseconds after a partial list leaves the live region reading “2 results Loading”; callingsettleBusyAnnouncement()there, as the settle path does, with a test, fixes it.
[Automated review]
| `useTouchTrigger`, `useTableRowExpansion`, and `useTableColumnResize`. A hook | ||
| whose current signature cannot delegate gains a ref-taking signature beside | ||
| it; the old signature is deprecated under INV9. | ||
| - **INV23 — Each private data attribute has one owner module.** A |
There was a problem hiding this comment.
The merge with main dropped #9182 here: this deletes current INV23 with its verification row and gap list. The same merge reverts #9183 in interaction-modality.md and #9198 in AST-030/spec.md, knowledge-contracts.md and REVIEW_GATE.md. Restoring main's versions of those five files keeps the diff to the Typeahead work.
| } else if (shownRows != null) { | ||
| // A failed server answer keeps the last non-empty list the source | ||
| // showed for this query, which settles it. | ||
| announceCount(showList(shownRows, true).length); |
There was a problem hiding this comment.
This announces the count without settleBusyAnnouncement(), which the settle path calls at line 951. A source that shows a partial list and fails about 5 ms after the busy start leaves the polite region reading “2 results Loading”, against spec:AST-086 FR8. Calling settleBusyAnnouncement() first (when searchQuery.length > 0), with a test for a fast rejection, fixes it.
| beside the trigger, except that a later list for the same query keeps an open | ||
| Typeahead popup on its side and grows it only within the room there | ||
| (`spec:AST-092` FR6); the first list for a query places it normally, and a | ||
| consumer minimum is clamped by the runtime's cap. |
There was a problem hiding this comment.
This adds a new exception to current INV11. It needs an engineering owner's /approve-spec on the head once the merge reversions are restored, or AST-092 FR6's below-field clause changes instead.
…estore main's records the merge dropped
There was a problem hiding this comment.
This can't be approved yet: the head adds an exception to the current architecture:layer-runtime INV11 rule so that a Typeahead's later list stays below the field and grows only within the room there (spec:AST-092 FR6), and that new clause needs an engineering owner's decision. An engineering owner records it by commenting /approve-spec <full head SHA> on this pull request (the author can do this as an engineering owner), or asks for FR6's below-field clause to change instead. The earlier record reversions and the failure-path busy announcement are fixed, and nothing else needs to change.
[Automated review]
| beside the trigger, except that a later list for the same query keeps an open | ||
| Typeahead popup on its side and grows it only within the room there | ||
| (`spec:AST-092` FR6); the first list for a query places it normally, and a | ||
| consumer minimum is clamped by the runtime's cap. |
There was a problem hiding this comment.
This adds a new exception to current INV11, which licenses the below-field cap in BaseTypeahead.tsx (holdPopupInPlace). It needs an engineering owner's /approve-spec <full head SHA> on this head, or AST-092 FR6's below-field clause changes instead.
|
/approve-spec 4b95367 |
There was a problem hiding this comment.
This is ready to approve: it implements spec:AST-092, the architecture:layer-runtime INV11 exception has an engineering owner's approval on this head, and the Typeahead, Tokenizer, PowerSearch, CommandPalette and Chat suites and the five new story plays pass. Optional follow-up: add regression tests for a new query's first list releasing a held popup height and for maxMenuItems capping a partial list, two states the INV11 and AST-092 verification rows name that no committed test covers yet.
[Automated review]
| const previous = shownState; | ||
| const previousEntryCount = shownEntryCount; | ||
| if (previous == null) { | ||
| setHeldHeight(null); |
There was a problem hiding this comment.
Optional: nothing in BaseTypeahead.incremental.test.tsx fails if this release is removed (all 22 tests stay green), although INV11's new verification row names a first list that stays capped as a failure signal. A test that holds the height for one query (as the above-field test does) and then types a second query with its own first list would pin it.
Implements
spec:AST-092(incremental search results).User need
People picking from a typeahead backed by a server wait for the debounce plus the round trip before they see anything, even when the page already holds most of the matches. A source can now show what it already has the moment they type and add the server's answer below it, without rows moving under the pointer or the highlight.
Problem and solution fit
SearchSource.search(query, context?): a source callscontext.update(items)to show a list before it settles; the return value stays the final list.BaseTypeaheadshows the latest list for the current query, keeps the highlighted item and its option id across later lists, keeps the popup on its side of the field (holds its height above, grows only within the room below), stays busy until the query settles, and announces the count once. Highlight indexes now follow displayed (grouped) order, so Enter picks the row that is highlighted.Tokenizerforwards partial lists with committed values removed, and shows its create row only once a searched query settles.Current specification
spec:AST-092FR1–FR10, DEC-1–DEC-3.Consistency edit: layer-runtime INV11
spec:AST-092FR6 andarchitecture:layer-runtimeINV11 are both current. FR6 is the later and more specific owner-approved decision, so it governs. INV11 gains one clause after "no size is capped to the span beside the trigger": a later list for the same query keeps an open Typeahead popup on its side and grows it only within the room there (spec:AST-092FR6), while the first list for a query places it normally. Its verification row names the evidence and the failure signal for that exception.Public delta and caller burden
SearchSource.search, new exported typeSearchContext. No new props.debounceMs={0}and delays its own server request;cancel()still runs before every new search.Design and alternatives
As decided in the spec: the source merges (DEC-1); partial lists arrive through a per-call context so every caller that awaits an array keeps working (DEC-2); later lists only append (DEC-3).
Evidence
BaseTypeahead.incremental.test.tsx: partial then final, highlight and option id kept, Enter on the kept item, one announcement, stale lists dropped, update after settle ignored, empty update, failure after non-empty and after only empty updates, dev warning (list and displayed/grouped order), first-list replacement without a warning, fresher data in place, popup above the field holds its height, popup below grows only within the room below, rejection after the popup closes announces nothing and keeps only this query's rows, held height released when the query ends.Tokenizer.test.tsx: committed values removed from partial lists; create row only after settle.Incremental results(local rows at once while busy, server rows appended, highlight kept, Enter selects) andIncremental results above the field(popup opens above; shown rows keep their screen position as server rows append).Incremental results in a scrolled list(the scroll offset and shown rows stay put while server rows append),Incremental results below the field, outgrowing the room(the popup stays below, inside the viewport, with the first row in place), andIncremental results under a resting pointer(rows that arrive under a still pointer don't take the highlight, and Enter picks the highlighted row). All five Typeahead plays pass in Chrome.main(a merge commit): option hover now usesonMouseMove, so a resting pointer no longer takes the highlight; the busy announcement (spec:AST-086FR8) and the replaced-source ArrowDown path (spec:AST-092FR4) are kept, and three existing assertions now expect the search context argument.Writing rubric results
This branch carries the
spec:AST-092record from its spec pull request until that merges; the record's results are reported there and repeated here.Scope
Testing
pnpm vitest run packages/core/src/Typeahead packages/core/src/Tokenizer packages/core/src/PowerSearch packages/core/src/CommandPalette packages/core/src/Chat; story play runs in CI.