I came across an unexpected issue when adding new items to a state array in React, which consequently results in more items being added to the DOM. In Safari and Firefox, this results in the new DOM items being added below the fold, and I must scroll down to see the new items. In Chrome, the screen remains scrolled to the bottom of the page, and the items are added above. This means I need to scroll up to see the new items. This is obviously not the expected behaviour for lazy loading or a "load more" button to view more blog posts in a list.
See here: https://codesandbox.io/s/new-leaf-0fnv5?file=/src/App.js
A few other observations below:
- I tried it on another Mac with Chrome, and it behaved more like Safari and Firefox but scrolled slightly up so that the last item is seen before clicking "Add more" was below the fold.
- Given the variance between the two browsers, there must be a way to achieve a more stable, expected behaviour.
- I've created similar "Load more" lists previously and never encountered this before. I've also never seen this behaviour on other live sites, so there clearly is something I'm doing differently that triggers Chrome to sometimes behave this way, I just don't know what.
- I noticed one or two similar questions on SO, but none of them addressed the question of why this happens sometimes, but not all the time, in Chrome.
Any suggestions on what could be influencing Chrome to behave in this unexpected way?