This episode is for members only

Sign up to access "One Million Checkboxes with Laravel" right now.

Get started
Already a member? Sign in to continue
Playing
12. A quick reactivity fix

Transcript

00:00
So everything is working nicely now, both in terms of real time. And then when we refresh each of these pages,
00:06
we get that initial state back from Redis and hydrate it. Let's quickly fix up a reactivity issue here, where when we scroll down and click on an item, we're bumped right to the top of the page.
00:19
This is a pretty simple fix. Now, remember when we had our render key over here on our overall scroller? What's happening is when this render key changes, the scroller by default is going to be at the very top.
00:32
So it's just going to scroll back to the top. What we can do, and again, not ideal, because this whole solution isn't the most ideal, is we can apply this to either the input
00:42
or the div within here instead to react to changes. That's pretty much all we need to do. So let's give both of these pages a refresh, come down and check this and you can see it works.
00:52
Let's go all the way down to the one million item on both of these. And let's just check one of these. We have different browser sizes here, so some of these are going to get cut off.
01:02
Let's go over and maybe let's check one of these over here. And there we go. Yeah, so everything is nicely working. And despite this being so far down in the list,
01:12
everything is nicely reacting. So really, really simple fix. Let's go over to the next episode and look at making this responsive, because at the moment it's just cutting off here.

Episode summary

In this episode, we quickly sort out a minor but annoying reactivity issue in our app. Previously, whenever you scrolled way down the list and clicked on an item, the page would jump you right back to the top—which is pretty frustrating!

We look into why this happens: it turns out that our scroll container resets to the top whenever its render key changes. The fix is straightforward—by being a bit more careful about where we apply the render key, either to a child div or an input, the scroll position will stay put when it should. It's not the most elegant solution, but it gets the job done.

To make sure the fix works, we test it out by scrolling to deep items in our massive list and playing with different browser sizes. Everything works smoothly now! In the next episode, we'll tackle making the UI more responsive, so things won't get cut off on smaller screens.

Episode discussion

No comments, yet. Be the first!