This issue is related to Chromium Issue ID 1380100 and has been fixed in version 109.0.5414.25 of Chrome.
Once the issue occurs any action which causes a re-painting of the component will fix it temporarily but it will reoccur if you scroll back down and up.
I tested the following approach as a temporary fix successfully.
Add a p element with ID 'scroller' on the page (this could easily be hidden by making the color the same as the background color for example). Updating this p element will trigger the re-painting of the flex container.
<p id="output">scrollTop: 0</p>
Then add an event targeting the scroll event to the flex container (you will notice that I added ID scroller1 to the flex container div.)
const output = document.querySelector("#output")
const scroller = document.querySelector("#scroller1")
scroller.addEventListener("scroll", (event) => {
output.textContent = `scrollTop: ${scroller.scrollTop}`
})
Finally seeing that this is a Chrome bug you can apply this only if executed by Chrome as follows.
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(is_chrome)
{
...`enter code here`
}
So a simplified example index.html file with the fix in looks like this.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
html, body {
padding: 0;
margin: 0;
font-family: sans-serif;
background: #525252;
}
body {
display: flex;
align-items: center;
justify-content: space-evenly;
height: 100vh;
}
.item {
background: #ececec;
padding: 20px;
display: grid;
place-items: center;
border-radius: 8px;
}
.list {
display: flex;
flex-direction: column-reverse;
width: 600px;
height: 600px;
overflow-y: scroll;
gap: 16px;
background: #2B2B2B;
padding: 16px;
}
#output {
color: cyan;
}
</style>
</head>
<body>
<div class="list" id="scroller1"></div>
<div id="output">scrollTop: 0</div>
<script>
// fix - comment out to see issue
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1
if(is_chrome)
{
const output = document.querySelector("#output")
const scroller = document.querySelector("#scroller1")
scroller.addEventListener("scroll", (event) => {
output.textContent = `scrollTop: ${scroller.scrollTop}`
})
}
// end of fix
const list = document.querySelector('.list')
for (let i = 0; i <= 400; i++) {
let item = document.createElement('div')
item.setAttribute('class', 'item')
item.textContent= 'Item '+ i
list.appendChild(item)
}
</script>
</body>
</html>
If you are using a framework which controls element updates then you might have to use a method other than a simple p element update to trigger a repainting of the component but the Event Handler approach should stay the same.