Skip to content
Closed
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
3 changes: 3 additions & 0 deletions packages/@react-spectrum/listbox/test/ListBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ describe('ListBox', function () {
</ListBox>
</Provider>
);
act(() => jest.runAllTimers());

let items = getAllByRole('option');
for (let item of items) {
Expand All @@ -992,6 +993,7 @@ describe('ListBox', function () {
</ListBox>
</Provider>
);
act(() => jest.runAllTimers());

let items = getAllByRole('option');
for (let item of items) {
Expand Down Expand Up @@ -1026,6 +1028,7 @@ describe('ListBox', function () {
</ListBox>
</Provider>
);
act(() => jest.runAllTimers());

let items = getAllByRole('option');
trigger(items[0]);
Expand Down
26 changes: 20 additions & 6 deletions packages/@react-stately/virtualizer/src/Virtualizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {Layout} from './Layout';
import {LayoutInfo} from './LayoutInfo';
import {OverscanManager} from './OverscanManager';
import {Point} from './Point';
import React from 'react';
import {Rect} from './Rect';
import {ReusableView} from './ReusableView';
import {Size} from './Size';
Expand Down Expand Up @@ -184,11 +185,18 @@ export class Virtualizer<T extends object, V, W> {
this._visibleRect = rect;

if (shouldInvalidate) {
// We are already in a layout effect when this method is called, so relayoutNow is appropriate.
this.relayoutNow({
offsetChanged: !rect.pointEquals(current),
sizeChanged: !rect.sizeEquals(current)
});
if (React.version.startsWith('16.') || React.version.startsWith('17.')) {
this.relayout({
offsetChanged: !rect.pointEquals(current),
sizeChanged: !rect.sizeEquals(current)
});
} else {
// We are already in a layout effect when this method is called, so relayoutNow is appropriate.
this.relayoutNow({
offsetChanged: !rect.pointEquals(current),
sizeChanged: !rect.sizeEquals(current)
});
}
} else {
this.updateSubviews(forceUpdate);
}
Expand Down Expand Up @@ -460,6 +468,12 @@ export class Virtualizer<T extends object, V, W> {
}

this._invalidationContext = context;
if (React.version.startsWith('16.') || React.version.startsWith('17.')) {
this._relayoutRaf = requestAnimationFrame(() => {
this._relayoutRaf = null;
this.relayoutNow();
});
}
}

/**
Expand Down Expand Up @@ -812,7 +826,7 @@ export class Virtualizer<T extends object, V, W> {
afterRender() {
if (this._transactionQueue.length > 0) {
this._processTransactionQueue();
} else if (this._invalidationContext) {
} else if (this._invalidationContext && !React.version.startsWith('16.') && !React.version.startsWith('17.')) {
this.relayoutNow();
}

Expand Down