Virtual Scroller #1207
Replies: 4 comments 2 replies
-
Interesting thought (largely Show Originals-specific): do we want to hide the cells completely? (This does not appear to break j/k scrolling, though we would have to be careful while there's an active A/B). Consider:
Assuming putting display:none on the cell itself causes it to no longer trigger the intersection observer used for visibility, that seems better for the second bullet point, so long as it fulfills the first bullet point. (Oh, also, obviously we need to ensure that hidden posts do indeed have height zero; if we hide a cell and it doesn't update its height, that's bad.) |
Beta Was this translation helpful? Give feedback.
-
Problem (that I should have seen coming) and also solution: cells often get their classlists updated (presumably for Simple solution: set a data attribute instead. Whee. (That makes me think, like, oh, if we used |
Beta Was this translation helpful? Give feedback.
-
An unfortunate small performance regression: Some of the experimental virtual scroller code makes use of Recall that our pageModifications engine, as per #407 (and its predecessor #275):
There is a subtle condition here: This means, though, that in the case where the DOM mutations we're trying to react to are called using rAF, and are thus in an rAF callback, we have no way* of scheduling pageModifications after all Redpop mutations but before the DOM gets painted, rendered, etc like we used to. If we use rAF, our modifications will occur one frame later, so the user will see one frame of unmodified content before the modified view (causing a double reflow, etc, as we used to always have before 454b268 and #416 and stuff). If we don't use rAF, we basically have to just handle the mutations "now,"* which would mean running all of the pageModifications callbacks multiple times. Having a choice between a few milliseconds of wasteful javascript and a frame of UI flicker isn't the worst thing in the world—it's really only noticeable in certain circumstances, like when using Scroll to Bottom—but it is too bad to lose the "best of both worlds" option for such a subtle reason. *I have a trick involving repeatedly queueing a new microtask; it doesn't really help here. |
Beta Was this translation helpful? Give feedback.
-
We could get a small (and I mean small) performance improvement by not re-processing posts when the virtual scroller remounts them on scroll in scripts that only make changes to the This would presumably involve something like excludeClass... but we already have something called that, and it does something different, so an obvious way to do this really cleanly doesn't stand out to me. But in general, this should have essentially no impact and thus I don't think it would even be noticeable. Scenarios where one would consider this basically just involve parsing (This brings up that we could also cache |
Beta Was this translation helpful? Give feedback.
-
Yeah, this is just an excuse to use the tech office category again.
Thoughts so far (yay, reading minified react comes in handy for a real use case for once):
cell
containers when they go off of the screen and are re-added when the cells come back on the screen. (I think Tumblr's algorithm for this is probably too aggressive at the moment—I would run it more like a scheduled task during downtime than as a declarative effect on scroll—but I digress).It seems reasonable that, in theory, XKit's current processing might be able to avoid these scrollbar shenanigans. Specifically: if you scroll up, a post renders in with its full height, the virtual scroll container rerenders (moving everything down), XKit processes the post and hides it, the cell height becomes 0, the resize observer fires, the virtual scroll container rerenders (moving everything back up)... and then the javascript event loop ends and the browser actually renders the page for the first time, then nothing actually changed re: scroll position.
I am not actually 100% clear on whether this is working or not, at the moment. I thought it wasn't, but it actually might be (some things, like Youtube and Spotify embeds, definitely cause visible scrollbar jank at the moment even without XKit—I might just have been observing that).
Either way, it's probably ideal to avoid this code being fired multiple times at all. Placing XKit hidden classes on the
cell
elements themselves would make the first-time render of a hidden post have the correct height, presumably, which seems better.Beta Was this translation helpful? Give feedback.
All reactions