petyosi / react-virtuoso

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

[BUG] Flickering with React 17 and reverse endless scrolling, fixed by upgrading to React 18 #914

Closed wjkmartin closed 4 months ago

wjkmartin commented 1 year ago

Describe the bug Flickering of elements on scroll, seemingly related to element size measurement. Debugger shows Layout Shift warning. Setting the measurement via the itemSize prop to return a constant does fix the issue, but obviously breaks other things. Upgrading to React 18 solves the issue, which we did as our solution.

Just reporting as a courtesy for anyone else having a similar issue. Thank you @petyosi for your work.

Reproduction https://codesandbox.io/s/currying-meadow-fjr3pb?file=/package.json

To Reproduce Steps to reproduce the behavior:

  1. Open the sandbox
  2. Scroll up
  3. See flickering
  4. Swap out the index files to the React 18 version and change the package versions of react to the latest React 18 versions.
  5. See it smooth.

Desktop (please complete the following information):

petyosi commented 1 year ago

Thanks for sharing that @wjkmartin - it's interesting as I've spent a lot of time eliminating flickering in React 18 :).

The effect in your example is certainly visible, especially due to the different background of the items. Another way to mitigate the flickering would be increasing the viewport, so that the items have more time to render before the user scrolls up to them:

<Virtuoso 
...
increaseViewportBy={{ top: 800, bottom: 300 }}
/>

Hope this helps, I will mark the issue with workaround provided and leave it open.

st-manhle commented 4 months ago

@petyosi Work Arround solution not work for my issue

Context

Issues

Do you have any solution for this?

petyosi commented 4 months ago

@st-manhle If you're building a chat interface, use the MessageList version. Notice that you still need to render images and videos with their known height, otherwise the list will bounce around. s

st-manhle commented 4 months ago

@petyosi Do we have any solution with Virtuoso component? - I can't refactor a source code because it's related to many stakeholders.

petyosi commented 4 months ago

@st-manhle no, I don't. Good luck finding another solution.