Skip to content

feat(Tokenizer): add isLoading and changeAction - #6000

Closed
AKnassa wants to merge 6 commits into
meta:mainfrom
AKnassa:ak-5941-tokenizer-transition-action
Closed

AKnassa wants to merge 6 commits into
meta:mainfrom
AKnassa:ak-5941-tokenizer-transition-action

Conversation

@AKnassa

@AKnassa AKnassa commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What this does

Tokenizer can now show that its value is busy, and can run a save step after every change to the token list. isLoading marks the value as resolving or saving. changeAction runs after onChange, inside a React transition, and the field shows the proposed tokens as busy until the parent's value catches up.

Why

The input-field family contract gives every field the same two ideas: a busy value (FR5) and a Transition Action (FR6). Tokenizer only knew how to show a search in flight, and a caller who wanted "saving…" after adding or removing a token had nothing to reach for. #5941 lists this as a gap. AST-001 also applies: isLoading must never be read as "the suggestions are still loading", and this keeps the two meanings apart.

What changed

  • New optional isLoading prop: the end-lane Spinner shows and the combobox carries aria-busy. The search source and its results are untouched.
  • New optional changeAction prop, called with the same (items, change) that onChange receives, on every value path: add, create, remove, Backspace, and clear-all. onChange still runs first; the Action runs in a transition; the tokens show the proposed list at once; if the parent never accepts it, the field falls back to the accepted list.
  • One Spinner and one aria-busy for both meanings (FR7).
  • The busy signal reaches the combobox through a package-internal context rather than a new public prop on BaseTypeahead.
  • Hidden form inputs keep submitting the accepted value, never the proposed one. The clear-all control follows the accepted value too, as Selector's clear does, while the tokens follow the proposal.
  • Fixes found while hardening: while the field is disabled with a reason, the focusable-disabled input still receives keys and an already-open menu stays on screen, so four edits slipped through. Backspace on an empty input removed the last token; ArrowDown then Enter selected one of the entries shown on focus; clicking an option in a menu still open from before the field was disabled committed it; and a custom token's remove callback still committed. All four are blocked now, by guards in the base combobox's keydown and selection paths that are byte-identical in the Typeahead PR. Dismissal is not an edit: Tab still closes that open menu on the keydown itself (skipping it would let the blur-time hide strand focus on body in Chrome), and Escape still closes it through the shared layer stack.
  • Callers that pass neither prop see no change beyond those fixes.
  • Docs: prop entries, the component spec records the API delta (before → after plus a verification row), the family adoption table row, two Storybook stories, and a patch changeset.

How to see it

Storybook → Tokenizer → "Value busy" and "Transition action". In the second story, add a name: the token appears at once with the Spinner, and settles about a second later. Screenshots of the busy, pending and settled states follow in a comment.

Evidence

The input busy: isLoading and changeAction suite has 27 tests (file total 103; a post-open review round added three focusable-disabled regression tests to the disabledMessage suite — Tab's keydown dismissal, the Escape invariant, and the option click on a menu left open by a mid-flight disable — each kept red under a one-line mutation). The first 9 were red before the change. Of the 18 edge-case tests, two were red on the change as written (the Backspace path and the custom token's remove callback) and are green after the fixes, and extending the focusable-disabled test with ArrowDown then Enter turned it red and green after the base guard; the rest pass on the change as written, so each was kept only after a one-line mutation made it fail: building the next list from the accepted value instead of the proposed one, deduplicating against the accepted list, reading the hidden inputs from the proposed list, counting maxEntries against the accepted list, swallowing a rejected Action, awaiting a void Action as a promise, and dropping the Spinner's accessible name each turn one specific test red.

Covered: a second add while the first Action is pending, with both Actions running in order; removing from the proposed list mid-Action; create-on-Enter through the Action; a withdrawn remove restoring the token; busy holding while either isLoading or an Action is active; isLoading turning off mid-search keeps the single Spinner; the duplicate guard and maxEntries counting the proposed list; hidden form inputs and the clear-all control staying on the accepted value, with a second clear during a pending clear being a no-op; a parent replacing the list mid-Action; every Action path blocked while focusable-disabled; a rejected Action reaching the nearest error boundary once; a synchronous Action; unmounting mid-Action; aria-describedby order while busy; and the Spinner named from the i18n catalog.

Local checks, all on top of the current upstream main: Tokenizer and Typeahead suites (192 tests), Selector and InputGroup suites (211 tests), core typecheck and docs typecheck, eslint with only the three pre-existing BaseTypeahead warnings, prettier, and the knowledge, changeset and SYNC checks.

Pre-existing behaviour seen along the way, not changed here

  • When a token that has focus is withdrawn, focus lands on body. The optimistic path behaves exactly like the existing controlled path.

Rubric

Triage: new API surface · non-breaking · low blast radius → deep path (the API shape is the maintainers' call; this is the shape #5941 and family FR5–FR7 ask for) · checks: §1 A1–A7/A11–A12, §3 P1–P7/P15–P18, §7 C1–C8/C11, §8 X5/X9–X12, §9 I1–I5, §3 P11–P12 · X20 changeset, §5b screenshots

Part of #5941 (Tokenizer isLoading + changeAction checkbox). The busy-context change in busyIndicatorLane.tsx and BaseTypeahead.tsx is byte-identical to the Typeahead PR for the same issue, so whichever lands second rebases clean.

Adopt the input-field family's busy and Transition Action contracts.
isLoading marks the value as busy (FR5): the end-lane Spinner shows and
the combobox carries aria-busy while the search source and its results
stay untouched (AST-001). changeAction runs after onChange with the same
(items, change) arguments, in a transition, on every value path (add,
create, remove, Backspace, clear-all), with the proposed tokens shown
optimistically until value catches up (FR6). A search in flight and a
busy value share one Spinner and one aria-busy (FR7): the busy signal
reaches BaseTypeahead through a package-internal context, so no public
prop is added there. Hidden form inputs keep the accepted value, and
the clear-all control follows the accepted value like Selector's clear.

Also closes three edits that slipped through while the field is
disabled with a reason (FR4): Backspace on an empty input removing the
last token, ArrowDown then Enter selecting one of the entries shown on
focus (the base key handler now returns while disabled; that hunk is
byte-identical to the Typeahead change for meta#5941), and a custom token's
remove callback.

The component spec records the API delta per AST-002 FR12/FR13, and
27 tests pin the behaviour: Action ordering and change payloads for
every path, concurrent Actions, rollback, the duplicate guard and
maxEntries on the proposed list, hidden inputs on the accepted list,
the error boundary path, unmount while pending, and every Action path
blocked while focusable-disabled.

Part of meta#5941 (Tokenizer checkbox).

Claude-Session: https://claude.ai/code/session_01N5RkmXVgx725F6rqZTGecR
@vercel

vercel Bot commented Sep 4, 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 26, 2026 4:29am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 4, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Sep 4, 2026
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Sep 4, 2026
github-actions Bot added a commit that referenced this pull request Sep 4, 2026
@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

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

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

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/26 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Visual Regression

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


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

…sable-disabled

The disabled key guard swallowed Tab, skipping the keydown dismissal
that stops Chrome dropping focus to <body> when the open menu hides
during focusout. Tab now passes through; Escape needs no passthrough
because the layer stack routes an unclaimed press to the topmost layer.
Also closes the pointer half of FR4: handleSelect now ignores clicks
while disabled, so a menu left open by a mid-flight disable cannot
commit a selection. Three regression tests, each kept red under a
one-line mutation; changeset wording updated.
@AKnassa
AKnassa marked this pull request as ready for review September 8, 2026 03:11
github-actions Bot added a commit that referenced this pull request Sep 8, 2026

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An external value update can leave users looking at stale tokens until a pending save settles. The current test explicitly keeps the old proposal on screen, but the input-family contract says optimism ends when the controlled value accepts or replaces it. Please let the replacement win immediately.

Tokenizer.spec.md also says no public concept or declaration changed, although this adds two exported props. Please make the current component record describe the actual public delta.

[Reviewed by Robohands]

@kentonquatman kentonquatman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The design looks good! Thanks @AKnassa!

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adopting the input family's busy and Transition Action contracts in Tokenizer — the mutation coverage across add, create, remove, Backspace, and clear-all, and the focusable-disabled fixes, are thorough.

One change is needed before this can be approved. When a parent replaces the controlled value while a changeAction is still pending, the older proposed tokens stay on screen until the Action settles. The family contract (input-fields FR6) ends the optimistic presentation when the controlled value accepts or replaces the proposal, so the replacement should become visible immediately. The focused test "holds the proposal when the parent replaces value mid-Action" currently asserts the stale display — please update the behaviour and that test so the replacement (Bob) replaces the proposal (Alice) before settlement. Until then, what a person sees can disagree with what a form would submit.

Smaller, non-blocking: in Tokenizer.spec.md, "No public concept is introduced" sits next to the new isLoading/changeAction props. Qualifying it to say no Tokenizer-owned concept is invented — the two family concepts are newly exposed as props — would prevent a misreading.

[Automated review]

Resolved conflicts:
- packages/core/src/Tokenizer/Tokenizer.spec.md: kept both sides. The
  Compatibility section keeps the isLoading/changeAction bullets and main's
  hasEntriesOnFocus FR13-FR15 correction, folding main's "public API is
  unchanged" bullet into the released-default bullet (the props change the
  API). Main's committed-value retention bullet now notes that a pending
  changeAction proposal is filtered like committed tokens until it ends.
  Public concepts keeps the family-concept paragraph and main's sentence;
  the verification map keeps main's rows plus the Input busy row.
- docs/families/input-fields.md: Tokenizer adoption row lists isLoading and
  changeAction and keeps main's DEC-5 exception, dropping "no family
  isLoading or changeAction"; main's iOS anti-zoom paragraph is kept.
- packages/core/src/Typeahead/BaseTypeahead.tsx: aria-busy keeps
  `isLoading || isInputBusy` with main's renamed inputAriaDescribedBy /
  inputAriaLabelledBy.

Merge fallout: the "isLoading turns off while a search is still in flight"
test re-rendered with a fresh `value={[]}`, which now re-derives the filtered
source mid-search, and BaseTypeahead drops a replaced source's in-flight
search since meta#6370. The test now passes one array across renders.
…once

astracat F1 (and cixzhang's 09-08 review): a parent that replaced `value`
while a changeAction was pending kept seeing the stale proposed tokens and
aria-busy until that Action settled, so the field showed one list while a
form would submit another. input-fields.md FR6 ends optimism when the
controlled value accepts or replaces the proposal.

The pending proposal is now the optimistic state, carrying the value it was
proposed against, and it shows only while `value` still holds those token
ids: a replacement arriving mid-Action wins immediately and ends that
proposal's busy state. The base is compared by id, not array identity, so a
parent re-rendering with a fresh array of the same tokens (an inline
`value={[...]}`) keeps the proposal. Stacked proposals keep the latest, and
React still reverts each one as its Action settles.

Tests: the mid-Action replacement test now asserts Bob shows, Alice is gone,
and no Spinner or aria-busy remains before the old Action resolves (red
before the fix: Bob's token was absent), and settles its Action in a
finally so a failure cannot entangle later tests. A new guard keeps the
proposal across a fresh array of the same ids; it fails if the base is
compared with `===`. The changeAction prop description, doc and changeset
now say "until value accepts or replaces them" instead of "catches up".
astracat F2 (and cixzhang's 09-08 review): Tokenizer.spec.md said no public
concept or declaration changed, beside two new exported props.

- Contract at a glance: Public contract names the two optional
  TokenizerProps members instead of "None"; Builder impact lists them as new
  optional caller choices.
- Compatibility class records the declaration delta (`isLoading?: boolean`,
  `changeAction?: (items, change) => void | Promise<void>`) instead of saying
  the declaration is unchanged, and names the disabled-reason fix as
  `family:input-fields` FR4, not this record's FR4.
- Public concepts: no Tokenizer-owned concept is introduced; the two family
  concepts are newly exposed as optional props.
- The proposal is busy until `value` "accepts or replaces" it, and the Input
  busy verification row adds the replaced-mid-Action state and its failure.

Docs only, no red state: scripts/check-knowledge.mjs passes before and after.
…arlier one

astracat F1, follow-up to ca6eecd. Each pending proposal recorded only
the `value` it was proposed against. A parent that accepts each change once
its save settles, with a plain update after the await (the TransitionAction
story's pattern), turns `value` into the earlier proposal's tokens while a
later Action is still pending. That value matched neither base, so the later
token disappeared and the Spinner and aria-busy dropped until its own save
settled, then the token came back: FR6's "optimistic feedback disappears"
and the spec's "aria-busy drops while busy".

A proposal now carries the chain of values it may stand on: the value it
was proposed against and, when stacked on a proposal still standing, that
proposal's bases and tokens. It stands while `value` holds the ids of any
of them. Accepting an earlier stacked proposal leaves the later one standing;
a genuine replacement matches no base and still wins at once.

Tests: new "keeps a later proposal and busy while the parent accepts an
earlier one" (stateful parent, add Alice, add Bob, settle Alice's save,
then Bob, Spinner and aria-busy must remain). Red at bfd9610: Bob's
remove button was null at Tokenizer.test.tsx:2508. It passes on the
pre-fix merge source (e50b39c) and after this change; the replacement
and fresh-array tests still pass. Settles in a finally so a red run cannot
entangle later tests.

Docs: the Chinese changeAction description in Tokenizer.doc.mjs still said
"until value catches up"; it now matches the English "accepts or replaces
them".
@AKnassa

AKnassa commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @cixzhang, and thanks astracat. You were both right, and I'm sorry this sat so long after the 09-08 review. Pushed at 7320fb7:

  • A replacement value wins right away (ca6eecd). A pending proposal now remembers the value it was proposed against, compared by token id. If the parent replaces value in the middle of an Action, the replacement shows at once and that proposal's Spinner and aria-busy end. A parent that re-renders with a fresh array of the same tokens (an inline value={[...]}) still keeps the proposal. I flipped the mid-Action test so it asserts that Bob replaces Alice before the old Action resolves, and I added a test for the same-ids case.
  • Stacked proposals (7320fb7). When the parent accepts an earlier change after its save resolves (the TransitionAction story's save-then-setValue pattern), a later pending token and its busy state now stay on screen. I added a test for this. The Chinese changeAction doc string now says "accepts or replaces" too.
  • The spec records the public delta (bfd9610). Tokenizer.spec.md now lists the two new optional TokenizerProps members in Contract at a glance and in Compatibility class, and it no longer says the declaration is unchanged. It says no Tokenizer-owned concept is introduced and that the family concepts are exposed as props. "Accepts it" now reads "accepts or replaces it".

I also merged main (e50b39c). That meant resolving conflicts in the spec, the family adoption row and the aria-busy line in BaseTypeahead.tsx, which #5999 also touches.

Still to do on my side: the screenshots the description says will follow in a comment.

Could you take another look?

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up — the two issues from the last review are both addressed, and this now matches the input family's busy and Transition Action contracts.

  • A parent replacement now wins right away: the pending proposal remembers the token-id chain it stands on, so a replacement shows immediately and that proposal's Spinner and aria-busy end, while a fresh array of the same tokens keeps the proposal and accepting an earlier stacked change keeps a later one standing. The mid-Action test now asserts the replacement, with new tests for the same-ids and stacked cases.
  • Tokenizer.spec.md now records the public delta: both new optional props are listed in the contract and compatibility sections, and the public-concepts wording now says no Tokenizer-owned concept is introduced while the two family concepts are newly exposed as props.

One non-blocking remainder: the screenshots mentioned in the description are still listed as to do in your latest comment — please add the busy, pending, and settled shots when you get a chance.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up: the replacement and spec-delta points from the earlier reviews are fixed, and both new props match the input family's busy and Transition Action contracts. Approval now waits on a maintainer decision: Tokenizer.spec.md adds three rules the current Tokenizer record does not state, and the record's owner needs to approve or reject them. Those rules are that pending changeAction tokens leave the suggestions (lines 87–90, where current FR13 keeps an unaccepted proposal eligible), that Clear all follows the accepted value (lines 82–84), and the new Input busy verification row (line 339). Separately, please:

  • Drop the aria-expanded premise and its “auto-closing would flicker” rationale from openMenuThenDisable (Tokenizer.test.tsx:1171–1201), because the current Tokenizer record requires an open popup to close when the field becomes disabled.
  • Add ## Writing rubric results for the two changed records to the description, as docs/contributing/spec-writing.md describes, and rewrite the “Before it … After it” narration at Tokenizer.spec.md:78–80 in the present tense.
  • Rebase onto main, where Tokenizer.tsx, Tokenizer.test.tsx, Tokenizer.doc.mjs and BaseTypeahead.tsx now conflict.

[Automated review]

Comment on lines +87 to +90
available. The one addition is a `changeAction` proposal still pending: its
tokens are on screen, so FR13 filters them from the cohorts like committed
ones until the proposal ends, and one the caller did not accept is eligible
again.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes FR13 treat a pending changeAction proposal like a committed value. The current FR13 excludes only committed ids and keeps an unaccepted proposed value eligible, so this rule needs the record owner's approval before it lands as written.

Comment on lines +82 to +84
(`family:input-fields` FR5–FR7). The clear-all control follows the
accepted `value`, as Selector's clear does, while the tokens follow the
proposal.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a behaviour rule. During a pending clear, Clear all stays on screen with no tokens, and a pending first add shows a token without Clear all. The family contract does not decide this, so it also waits on the record owner.

// The premise the tests below stand on: the flip itself leaves the
// menu open. If a future change closes it here, these tests would
// pass without exercising anything.
expect(input).toHaveAttribute('aria-expanded', 'true');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This premise asserts the menu stays open after the field becomes disabled. The current Tokenizer record's Disabled state says “an open popup closes and clears its active descendant”. Dropping this assertion, and the “auto-closing would flicker” rationale above, keeps the edit-blocking checks without locking in the gap.

@cixzhang

Copy link
Copy Markdown
Contributor

Closing as stale to reduce CI load; feel free to reopen or push a fresh branch if it's still needed. Posted by Cindy's agent on her behalf.

@cixzhang cixzhang closed this Oct 28, 2026
@github-actions
github-actions Bot deleted the ak-5941-tokenizer-transition-action branch October 29, 2026 12:17

This branch was successfully deployed

1 active deployment
Preview — 7320fb78 Deployed Sep 26, 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. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review needs:spec-owner-review Current knowledge records await owner approval

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants