petyosi / react-virtuoso

The most powerful virtual list component for React
https://virtuoso.dev
MIT License
5.26k stars 301 forks source link

[BUG] endReached is not called when initialItemCount and totalCount are specified #961

Closed lithdew closed 1 year ago

lithdew commented 1 year ago

Describe the bug endReached is not called when initialItemCount and totalCount are specified.

Reproduction https://codesandbox.io/s/boring-sara-rf9jry?file=/App.js

To Reproduce Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/boring-sara-rf9jry?file=/App.js
  2. Open Devtools
  3. Scroll to end

Expected behavior Expect 'END REACHED' to be logged to console, but nothing was logged.

Desktop (please complete the following information):

petyosi commented 1 year ago

I'm a confused. Your issue says initialItemIndex (there's no such property), but your sandbox uses initialItemCount. If you mean to use initialItemCount then what you're doing is rendering all items in the initial render (this stops endReached from being called), only to have them removed by the virtualization logic. What are you trying to do here?

lithdew commented 1 year ago

Apologies, I meant initialItemCount (will rename title).

My intent was to have an infinite-scrolling list where initialItemCount rows are server-side rendered, and further rows may be loaded when the end is reached (the same behavior as specifying initialItemCount with data, but specifying totalCount instead of data).

This was an attempt in circumventing this issue to do with the infinite list re-rendering/blinking on mount despite the list being initially server-side rendered in NextJS: https://github.com/petyosi/react-virtuoso/issues/763 (contrary to the issue, the blinking on mount does appear to happen on NextJS. Happy to provide a reproduction w/ NextJS).

petyosi commented 1 year ago

I see. You can use count - 1 as the initialItemCount, this should enable endReached. I am aware of #763 being applicable to next too - that's why the issue is still open.

To be honest, what you're doing seems more like an endless scroll that does not really need virtualization. Virtuoso can still be used in that scenario, but obviously, this is not what it's meant for.

petyosi commented 1 year ago

@lithdew FYI, #763 has been closed, give it a try.

lithdew commented 1 year ago

@lithdew FYI, #763 has been closed, give it a try.

Seem to still hit the same issue of endReached not being called. Tried set initialItemCount to be the same as totalCount, and also tried alternatively set data instead of totalCount.

petyosi commented 1 year ago

Sorry for the confusion. endReached will not be called when initialItemCount equals the totalCount - fixing that would be a breaking change in the behavior.

The fix I've mentioned is related to the flickering in #763.