S
SolidJS•2mo ago
florian

`scroll` event emitted until end reached when scrolling lazy-rendered table

I'm currently working on an app which displays a lot of data in a table that often has thousands of rows. To reduce the time spent while rendering the table I wanted to make it lazy-rendered so it just renders the rows in view and adds padding before and after the elements to correct the scroll position. The solution I came up with does just that but for some reason it keeps emitting scroll events when starting to scroll down until the end is reached, even when just increasing scrollTop by a few pixel and no manual scrolling at all. This doesn't happen when scrolling up for some reason? I created a minimal example that has the same behaviour like in my app here: https://playground.solidjs.com/anonymous/239274a9-b2f9-4c66-bb52-f9d69d40845f I know there are more performance improvements available but this would make the example just more complicated.
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
28 Replies
bigmistqke
bigmistqke•2mo ago
hi florian, did u figure it out?
florian
florianOP•2mo ago
nope, not yet and tbh I don't understand at all why it's behaving like that it's super weird
bigmistqke
bigmistqke•2mo ago
ye i agree it's very weird it has slightly different behavior with wheel instead of scroll but still very strange it feels a bit like the browser tries to correct the scroll after changing the heights of the content, and that sort of gets in conflict with how you are calculating the scroll-position
bigmistqke
bigmistqke•2mo ago
https://playground.solidjs.com/anonymous/fad74136-8440-4678-866d-ed99755ad3c1 even with the inner-container having a fixed width it still has the same behavior
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
florian
florianOP•2mo ago
yeah I think the browser emits non-user scroll events but I don't see why at all and I also wasn't able to find any other reason why a scroll event gets emitted other than by either the user scrolling or modifying scrollTop/Left
bigmistqke
bigmistqke•2mo ago
strange behavior i like the approach tho
florian
florianOP•2mo ago
the lazy-rendering itself?
bigmistqke
bigmistqke•2mo ago
keeping the list in view with the top and bottom-padding
florian
florianOP•2mo ago
yeah I actually used it before in my project like almost the same process but for some reason it didn't happen there one sec, maybe I can share the code of it
bigmistqke
bigmistqke•2mo ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
bigmistqke
bigmistqke•2mo ago
it doesn't happen with absolutely positioned rows so it's really something to do with how these static/relative positoned rows interact with the scrollTop
florian
florianOP•2mo ago
interesting
florian
florianOP•2mo ago
a friend of mine also just looked at it and came up with this: https://playground.solidjs.com/anonymous/31e97be8-c692-4915-8c59-7a59136066fc
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
florian
florianOP•2mo ago
which just sets scrollTop to the scrollTop at the beginning of the function?
bigmistqke
bigmistqke•2mo ago
a nice cheeky fixing that browser correction
florian
florianOP•2mo ago
yeah it looks like dragging the scrollbar thumb results in the old behaviour tho not really sure why tho
bigmistqke
bigmistqke•2mo ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
bigmistqke
bigmistqke•2mo ago
Solid Primitives
A library of high-quality primitives that extend SolidJS reactivity
bigmistqke
bigmistqke•2mo ago
looks quite a minimal abstraction
bigmistqke
bigmistqke•2mo ago
this is that approach, but then applied with your abstraction: https://playground.solidjs.com/anonymous/ca289da7-20af-453c-8722-4411a7b9f361
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
bigmistqke
bigmistqke•2mo ago
so instead of padding you have 1 scroll-container 👉 1 relative container for the height 👉 1 absolute positioned container with top 👉 the selection of relative positioned divs
florian
florianOP•2mo ago
interesting looks like everything's working with this one
bigmistqke
bigmistqke•2mo ago
yup! pretty neat 🙂
florian
florianOP•2mo ago
I think I will actually just use this one Thank you very much for taking a look at it
bigmistqke
bigmistqke•2mo ago
ur very welcome!
florian
florianOP•2mo ago
I was sitting at this problem for over a week now and tried so many different rendering techniques in the hope that improving the speed of the whole rerendering etc. would solve this 😭 I was about to just use plain js for it all
bigmistqke
bigmistqke•2mo ago
ye those sneaky ass browser stuff is horrific really weird weird bug this one probably somewhere deeply hidden in the spec there is a line that describes this behavior
florian
florianOP•2mo ago
yeah well, lesson learned lol

Did you find this page helpful?