Skip to content

fix(PowerSearch): replace an open value menu when the field or operator changes - #6357

Merged
nynexman4464 merged 1 commit into
mainfrom
fix/powersearch-stale-value-menu
Sep 18, 2026
Merged

nynexman4464 merged 1 commit into
mainfrom
fix/powersearch-stale-value-menu

Conversation

@nynexman4464

Copy link
Copy Markdown
Contributor

User impact

Anyone editing a PowerSearch filter whose value editor is a Tokenizer (enum_list, entity_list, string_list). With the "Select values" menu open, changing the field selector (e.g. Creator → Owner) or the operator leaves the previous field's options in the open menu. Reopening the menu shows the right options; only the already-open menu goes stale. Display-only — an applied filter computes against the right field — but a user picking from the stale list gets a filter that matches nothing. Reproduces on stock field types with no custom editors, and on nested sub-filter rows.

Problem and solution fit

  • Why does the defect occur? PowerSearchEditPopover renders one unkeyed PowerSearchValueEditor. When the old and new fields share a value type, React reuses the editor instance, so the Tokenizer — and the BaseTypeahead under it — keeps its open menu, query text and fetched results across the searchSource swap. PowerSearchFilterEditor's existing key={filter.field} doesn't help: it responds to the outer filter prop, which doesn't change until Apply; the field switch is private partialFilter state inside the popover.
  • Why does it harm the task? The menu is the only affordance for choosing a value; a menu that shows the wrong field's values invites a selection that produces an empty result set.
  • Why does that matter? The editor is explicitly designed to reset on field change (handleFieldChange clears the value); the stale menu contradicts the state the user can see in the field chip.

The fix gives the value editor the identity it semantically has — the (field, operator) pair it edits — so React discards the old editor rather than reconciling it. That is the same approach Tokenizer/Typeahead consumers are expected to take, and matches the "editor identity follows the operator" pattern used by the internal predecessor.

Expected behavior and authority

  • PowerSearchEditPopover.handleFieldChange / handleOperatorChange already define the intent: field or operator change resets the value.
  • BaseTypeahead.spec.md FR3 / PR1 (draft): one generation counter rejects stale asynchronous work; this PR adds source replacement to the list of invalidation triggers so the spec and the code agree.

Smallest restoration

  1. PowerSearchEditPopover — the value editor is rendered as ValueEditorCell keyed on valueEditorKey(partialFilter) (field + operator). The mount-time focus handoff moves into that cell rather than living on the popover, so "mount" covers both the popover opening and a field/operator switch: the freshly mounted editor is focused and bootstraps its own suggestions. Nested sub-filter rows key their editor the same way (they have no focus handoff today and none is added).
  2. BaseTypeahead — the existing [searchSource] cleanup effect (which already clears the debounce and calls cancel?.()) also advances searchGenRef, so a response from a source that has since been replaced fails the generation check instead of committing.

Deliberately not done here:

  • No dev warning on searchSource identity change: Tokenizer rebuilds its filtered source on every value change by design, so a warning would fire on every token add.
  • No change to handleOperatorChange's keep-value rule (it compares value.type only; stricter option-set compatibility is a separate behavior change).
  • No new public API.

Evidence

  • Reproduction before the change: PowerSearchEditPopover.test.tsx › value editor identity follows the field and operator — both tests fail on main (the Creator Person option is still in the document after switching to Owner); Typeahead.test.tsx › discards a response from a source that was replaced while it was in flight fails on main (the late Apple result renders).
  • Result after the change: all three pass. Creator Person is gone and Owner Person appears without any further interaction; the stale response is discarded and a search against the new source still lands.
  • Representative unchanged path: edit popover resets state when switching between filter tokens and the rest of the PowerSearch / Typeahead / Tokenizer suites are unchanged and green (390 tests across the three directories).
  • Regression test or other mutation-sensitive proof: each of the three new tests was run with the corresponding source change stashed and confirmed to fail, then re-run with it restored.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

pnpm vitest run --project ui packages/core/src/PowerSearch packages/core/src/Typeahead packages/core/src/Tokenizer
# 13 files, 390 tests passed
pnpm -F @astryxdesign/core exec tsc --noEmit -p .
pnpm exec eslint packages/core/src/PowerSearch/PowerSearchEditPopover.tsx packages/core/src/Typeahead/BaseTypeahead.tsx
pnpm check:knowledge && pnpm check:changesets

Behavior under test is DOM/state, not layout or pixels, so jsdom coverage is sufficient; no real-browser states depend on this change.

…or changes

Switching the field selector while a value Tokenizer's menu is open left the
previous field's suggestions showing. Two fields with the same value type
(two `enum_list` fields, say) were rendered through one unkeyed
PowerSearchValueEditor, so React reused the editor instance and the
Tokenizer's open menu, query, and fetched results all survived the switch.

Key the value editor on the (field, operator) pair it edits so it remounts
when either changes. The mount-time focus handoff moves into the keyed cell,
so the freshly mounted editor is focused and bootstraps its own suggestions
whether the popover just opened or the user just picked a different field.
Nested sub-filter rows get the same key.

BaseTypeahead also advances its search generation when `searchSource` is
replaced, so a late response from the old source can no longer populate a
menu that now reads a different source.
@vercel

vercel Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Sep 17, 2026 2:55pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 17, 2026
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Sep 17, 2026
@astracat-bot

astracat-bot Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
📝 Draft — not reviewed automatically (for maintainers only) Sep 18, 2026, 1:34 AM UTC

github-actions Bot added a commit that referenced this pull request Sep 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

Preview availability: Storybook and Sandbox were not published for this CI run.

Modified Components

PowerSearch (@astryxdesign/core)
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 3851 -
Complexity N/A Very High (335) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: 36 accessibility violation(s) found — 2 critical, 34 serious.

Button pattern - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/18 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
ChatComposer - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/18 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
ChatComposerInput - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/14 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
ChatReasoning - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 4/5 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
ChatToolCalls - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 10/11 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Checkbox pattern - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/33 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
CheckboxList - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 4/17 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
ClickableCard - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/5 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
CodeEditor - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 3/7 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
CodeEditorPerf - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/2 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
CodeEditorTheme - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 13/14 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
CodeTheme - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 14/16 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
DateRangeInput - 1 issue(s)
  • 🔴 critical: Ensure an element's role supports its ARIA attributes
    • Rule: aria-allowed-attr · Affects 1/21 stories · Learn more
    • WCAG: 4.1.2 (Level A)
FileInput - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 3/15 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
GridMasonry - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/3 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Heading - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/16 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Icon - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/18 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
LogStream - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/3 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
MediaTheme Auto - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/5 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
PowerSearch - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/26 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
ProgressBar - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/18 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Radio group pattern - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 3/26 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
RadioList - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 3/13 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
RichTextEditor - 2 issue(s)
  • 🟠 serious: Ensure every ARIA input field has an accessible name
    • Rule: aria-input-field-name · Affects 2/18 stories · Learn more
    • WCAG: 4.1.2 (Level A)
  • 🔴 critical: Ensure every form element has a label
    • Rule: label · Affects 1/18 stories · Learn more
    • WCAG: 4.1.2 (Level A)
SelectableCard - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/4 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Stepper - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/30 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
TableGroupedRows - 1 issue(s)
  • 🟠 serious: Ensure ARIA attributes are used as described in the specification of the element's role
    • Rule: aria-conditional-attr · Affects 3/3 stories · Learn more
    • WCAG: 4.1.2 (Level A)
TableTree - 1 issue(s)
  • 🟠 serious: Ensure ARIA attributes are used as described in the specification of the element's role
    • Rule: aria-conditional-attr · Affects 8/9 stories · Learn more
    • WCAG: 4.1.2 (Level A)
Text - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/23 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Theme - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/5 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
PopArt - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 3/6 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Thumbnail - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/12 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Timestamp - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/20 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Token - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/10 stories · Learn more
    • WCAG: 1.4.3 (Level AA)
Tokenizer - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/24 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Visual Regression

Status: No visual change across 4 compared shot(s).


Generated by PR Enrichment workflow | View full report

@nynexman4464
nynexman4464 marked this pull request as ready for review September 18, 2026 16:36
@nynexman4464
nynexman4464 merged commit da998a2 into main Sep 18, 2026
36 checks passed
nynexman4464 added a commit that referenced this pull request Sep 18, 2026
…, not in an effect (#6370)

* refactor(Typeahead): invalidate a replaced searchSource during render, not in an effect

Follow-up to #6357. A source swap is a fact of the render that carries it,
so compare against the previous source there: cancel it, adopt the new one,
and advance the search generation. The effect that did this on cleanup — and
the lint suppression it needed to read a live ref — go away; what remains is
a pure unmount cleanup for the debounce timer and the current source.

Also trims the PowerSearchEditPopover comments added in #6357 to the
non-obvious "why".

* chore: plain-language changelog for the PowerSearch value-menu fix

* chore: comments say why, not how
@github-actions
github-actions Bot deleted the fix/powersearch-stale-value-menu branch September 19, 2026 06:20

This branch was successfully deployed

1 active deployment
Preview — 8843e87f Deployed Sep 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant