Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions packages/react-aria-components/test/ListBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2396,6 +2396,55 @@ describe('ListBox', () => {
expect(queryAllByRole('option')).toHaveLength(0);
});
}

if (React.version.startsWith('19')) {
it('supports Activity into a portal', async () => {
let ReactCanaryContext = React.createContext(null);
let RouterContext = React.createContext(null);

function Page() {
let {mode} = React.useContext(ReactCanaryContext);
let {pathname} = React.useContext(RouterContext);

return (
<>
<ol>
<li>{pathname}</li>
</ol>
<ListBox aria-label="Activity Listbox">
{mode === 'visible' && <ListBoxItem>Item 1</ListBoxItem>}
{mode === 'visible' && <ListBoxItem>Item 2</ListBoxItem>}
{mode === 'visible' && <ListBoxItem>Item 3</ListBoxItem>}
{mode === 'visible' && <ListBoxItem>Item 4</ListBoxItem>}
{mode === 'visible' && <ListBoxItem>Item 5</ListBoxItem>}
</ListBox>
</>
);
}

function App({mode, pathname = '/', ready = false}) {
let react = React.useMemo(() => ({mode}), [mode]);
let router = React.useMemo(() => ({pathname, ready}), [pathname, ready]);

let route = React.useMemo(() => <Page />, []);

return (
<RouterContext.Provider value={router}>
<ReactCanaryContext.Provider value={react}>
<React.Activity mode={mode}>{route}</React.Activity>
</ReactCanaryContext.Provider>
</RouterContext.Provider>
);
}

let {rerender, queryAllByRole} = render(<App mode="visible" pathname="/" ready />);
expect(queryAllByRole('option')).toHaveLength(5);
rerender(<App mode="hidden" pathname="/other" />);
rerender(<App mode="hidden" pathname="/other" ready />);
rerender(<App mode="visible" pathname="/" ready />);
expect(queryAllByRole('option')).toHaveLength(5);
});
}
});

describe('keyboard modifier keys', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/react-aria-components/test/Table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2976,12 +2976,12 @@ describe('Table', () => {

await act(() => stories.makePromise([]));

expect(mockCollectionUpdate).toHaveBeenCalledTimes(1);
expect(mockCollectionUpdate).toHaveBeenCalledTimes(2);

let button = tree.getByRole('button');
await act(() => button.click());

expect(mockCollectionUpdate).toHaveBeenCalledTimes(2);
expect(mockCollectionUpdate).toHaveBeenCalledTimes(3);
});
});

Expand Down
6 changes: 6 additions & 0 deletions packages/react-aria/src/collections/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,12 @@ export class Document<T, C extends BaseCollection<T> = BaseCollection<T>> extend

subscribe(fn: () => void) {
this.subscriptions.add(fn);
// Ensure that React reads the collection if we re-subscribe after updates were
// already queued. When a hidden Activity is revealed, child nodes re-attach and call
// queueUpdate before we can re-subscribe, so the notification is lost.
if (this.queuedRender) {
fn();
}
return (): boolean => this.subscriptions.delete(fn);
}

Expand Down