Skip to content

fix(Tokenizer): suppress Create option for already-selected labels (#6366) - #6369

Closed
onlyysaurabh wants to merge 1 commit into
meta:mainfrom
onlyysaurabh:fix/6366-tokenizer-create-selected-label
Closed

onlyysaurabh wants to merge 1 commit into
meta:mainfrom
onlyysaurabh:fix/6366-tokenizer-create-selected-label

Conversation

@onlyysaurabh

Copy link
Copy Markdown

Summary & User Impact

Fixes #6366.

In Tokenizer, typing the label of an already-selected item where id !== label (e.g. { id: 'u1', label: 'Alice' }) offered a redundant Create "Alice" option in the dropdown. Selecting it appended a duplicate token under a synthetic id ({ id: 'Alice', label: 'Alice' }).

This PR suppresses the Create suggestion case-insensitively for any label already present in value, and guards the commit path against creating duplicate tokens.

Root Cause

  • createEntries and handleAdd only checked selectedIds.has(trimmed) / selectedIds.has(createdValue).
  • When id !== label, comparing the typed label string against selected IDs evaluated to false.
  • filteredSource pre-filters results by selected IDs before createEntries runs, so results.some(...) never saw the selected items either.

Changes

  • packages/core/src/Tokenizer/Tokenizer.tsx:
    • createEntries: added value.some(item => item.label.toLowerCase() === queryLower) to the alreadyExists guard; added value to the dependency array.
    • handleAdd: added value.some(v => v.label.toLowerCase() === createdValueLower) to the creatable branch as defense-in-depth on commit.
  • packages/core/src/Tokenizer/Tokenizer.test.tsx:
    • Added regression test suppresses Create case-insensitively for already-selected label covering id !== label and case-insensitivity.
  • Changeset:
    • Added @astryxdesign/core patch changeset (.changeset/tokenizer-suppress-create-option-for-already-sel-p98g.md).

Verification & Testing

  • pnpm vitest run packages/core/src/Tokenizer/Tokenizer.test.tsx (74/74 passed)
  • pnpm vitest run packages/core/src/Typeahead/Typeahead.test.tsx (81/81 passed)
  • pnpm eslint packages/core/src/Tokenizer (0 errors)
  • pnpm check:repo (all 14 repository validation gates passed)

@vercel

vercel Bot commented Sep 18, 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 18, 2026 5:57pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 18, 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 labels Sep 18, 2026
@astracat-bot

astracat-bot Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🔴 Reviewed (for maintainers only) Oct 20, 2026, 12:01 AM UTC

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

Current run: The current CI run concluded failure. Current analysis is unavailable.

The exact-head preview is not available yet.


Generated by PR Enrichment workflow | View current CI run

@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.

This PR can be closed: the same fix for #6366 already landed on main in #6367 and shipped in 0.7.1, and this branch now conflicts with main in Tokenizer.tsx and Tokenizer.test.tsx. Rebasing would only add a second copy of the same label check and a duplicate changeset. The one piece main lacks is a test that types a selected label in another case (alice for Alice); if you want to keep it, it fits as a small test-only PR against current main. Thanks for the clear root-cause write-up.

[Automated review]

@cixzhang

Copy link
Copy Markdown
Contributor

Closing as superseded by #6367. Posted by Cindy's agent on her behalf.

@cixzhang cixzhang closed this Oct 28, 2026

This branch was successfully deployed

1 active deployment
Preview — e8ca7f61 Deployed Sep 18, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tokenizer offers Create for a label that is already selected when the token id differs from the label

2 participants