adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.22k stars 1.07k forks source link

TableView in Dialog onLoadMore triggered multiple times on dialog open #2822

Open CezCz opened 2 years ago

CezCz commented 2 years ago

๐Ÿ› Bug Report

When opening a dialog, the embedded TableView will invoke "loadMore" function several times. https://codesandbox.io/s/brave-merkle-uji7e?file=/src/App.tsx

๐Ÿค” Expected Behavior

loadMore is invoked only when needed

๐Ÿ”ฆ Context

I am integrating @quarry/inventory container into a dialog, I have quite a heavy loadMore function which is being triggered indefinitely making my app go non-responsive.

๐Ÿงข Your Company/Team

AEM Sites/Odin

reidbarber commented 2 years ago

Looks like a similar issue to https://github.com/adobe/react-spectrum/issues/2365 (in ComboBox) (fixed via https://github.com/adobe/react-spectrum/commit/74e31fa34386364dde7d62fec3e987f142f892be#diff-5dab6d4552ae847698b818580fc5e362bcd53952faf37a2d66b1b4b65a7f197a)

LFDanLu commented 2 years ago

@CezCz The TableView will try to load in enough items to cover roughly 2 times its height so the codesandbox is actually showing the correct behavior. It definitely shouldn't be loading infinitely though, are there any significant differences between your app's dialog setup and the sandbox? Are new items being indefinitely loaded in in your app or is there an infinite spinner with no items coming in?

reidbarber commented 2 years ago

In that example, I have enough height to show 5 items. It initially loads 27 items (9 items x 3 API calls). Not seeing any infinite behavior though.

LFDanLu commented 2 years ago

I've reached out to @CezCz and I believe we have a resolution for the infinite loading (had to do with applying a height to the wrapping V2 Provider). The bug that will be fixed here for this issue is a refinement to the TableView virtualizer to prevent it from calling onLoadMore 1 extra time than necessary.