An open source design system that's fully customizable and agent ready
TypeScript
refactor(Tokenizer): check sheet rows for action during render, not in an Effect (#9808)
Cindy Zhanga5e334b4909f
diff --git a/.changeset/tokenizer-sheet-action-warning-render.md b/.changeset/tokenizer-sheet-action-warning-render.mdnew file mode 100644index 0000000000..b8664dbe71--- /dev/null+++ b/.changeset/tokenizer-sheet-action-warning-render.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[chore] Internal: the Tokenizer bottom sheet checks its result rows for `action` while it renders, not in an Effect after the commit. The development warning, its text and the rows are unchanged. Not exported from the package entry point.++@cixzhangdiff --git a/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx b/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsxindex 23f1318cd4..47333b3a80 100644--- a/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx+++ b/packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx@@ -25,7 +25,7 @@ import {waitFor,within,} from '@testing-library/react';-import {createRef, useState} from 'react';+import {StrictMode, createRef, useState} from 'react';import * as stylex from '@stylexjs/stylex';import {Tokenizer,@@ -1817,6 +1817,38 @@ describe('Tokenizer sheet presentation (single-sheet touch flow)', () => {warn.mockRestore();});+ it('warns about a row action once under StrictMode double renders', async () => {+ __resetDevWarnings();+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});+ const withAction: SearchSource<SearchableItem> = {+ search: () => [],+ bootstrap: () => [+ {+ id: 'design',+ label: 'Design',+ action: <button type="button">Go</button>,+ },+ ],+ };+ render(+ <StrictMode>+ <Tokenizer+ label="Tags"+ searchSource={withAction}+ value={[]}+ onChange={() => {}}+ debounceMs={0}+ experimental={{presentation: 'bottom-sheet'}}+ />+ </StrictMode>,+ );+ fireEvent.click(openTrigger());+ await screen.findByRole('checkbox', {name: 'Design'});+ expect(warn).toHaveBeenCalledTimes(1);+ expect(warn.mock.calls[0][0]).toMatch(/bottom-sheet rows/);+ warn.mockRestore();+ });+it('keeps focus when adaptive stops resolving to the sheet while it is open (FR16)', async () => {// A matchMedia stub whose match can flip, with a change listener the// test fires, as a phone turned to landscape would.diff --git a/packages/core/src/Tokenizer/TokenizerBottomSheet.tsx b/packages/core/src/Tokenizer/TokenizerBottomSheet.tsxindex e43d93f792..6d68af425d 100644--- a/packages/core/src/Tokenizer/TokenizerBottomSheet.tsx+++ b/packages/core/src/Tokenizer/TokenizerBottomSheet.tsx@@ -614,16 +614,14 @@ function TokenizerSheetContent<T extends SearchableItem>({// `action` is declared on `SearchableItem` for the grid-adopting hosts; the// sheet rows have not adopted it, so a row renders the item without the// control and says so (`spec:AST-058` FR9), as the inline panel does.- useEffect(() => {- if (results.some(item => item.action != null)) {- warnOnce(- 'tokenizer-sheet:item-action',- 'Tokenizer',- 'A result carries `action`, which the bottom-sheet rows do not render ' +- 'yet; the item is shown without it.',- );- }- }, [results]);+ if (results.some(item => item.action != null)) {+ warnOnce(+ 'tokenizer-sheet:item-action',+ 'Tokenizer',+ 'A result carries `action`, which the bottom-sheet rows do not render ' ++ 'yet; the item is shown without it.',+ );+ }// The pending Spinner below stays named, as the inline field's does// (`family:input-fields` FR7), but is not a live region; the sheet announces