But I have one question, Gerald, because we saw that the, in this case, the playlist query is a little bit slower and so we have two updates on the initial load, but what if the playlist, the request to fetch the data for our playlist route is faster than the other fetches that we're doing to populate the data in our UI?
That's a great question. So to answer that, we're going to go back to this, our playlist route here. And for those that, with a keen eye, you've probably noticed these add synthetics around it. These directives just help us artificially slow down parts of our query so that we can demonstrate some of these things. So in this case here, let's, let's remove this synthetic timeout for the playlist because we want this to execute a little bit faster. So let's go back here and see what kind of user experience we get with this change.
Okay, and now we're back to one update on initial load. If we click to another playlist, let's, let's confirm that we still have the expected behavior of our inner row components still suspending and being encapsulated by that inner suspense boundary. So it's really nice that now if our row component, our playlist data fetching is fast in the best case scenario, we're going to have one update to the screen on initial load. But if it's a little slower and React essentially can't wait for it, then the worst case scenario is going to give us two updates to the screen. And for our app here, that's definitely the right trade off in terms of the number of suspense boundaries and their placement. But let's remove all the other synthetic timeouts in our app here to get it feeling a little bit faster. Awesome. Yeah, because obviously, it'd be terrible user experience if we ship this to our customers. Great for a talk, bad for an actual application. So we're going to go back in here to each one of these and we're going to just delete each of those synthetics directives. And here we're going to see, as we reload this, probably something a little more like we expect in terms of load performance here. But as I load this, if you see that playlist loading in, we can see it's still taking a little bit too long for my liking here. And that's because I've taken some time to kind of figure out, like, there's a slow field in here somewhere that's just causing my query to take a long time to finish here. So this wouldn't be a GraphQL talk if we explored some GraphQL concepts to figure out how we can help ourselves here to update this experience. So we've got a new directive that is almost ready in the spec, the GraphQL spec, that we can integrate with that allows us to mark part of our query as some fields that can be loaded in later when they are ready. So we're going to go back to the playlist route here. And no surprise to the keen eye, we've got our tracks field here that has a synthetics timeout as well. But if this were a production application, we would assume that you've done some sleuthing to determine that, hey, it's these tracks that are really taking a long time. So what I'd really like in my user experience is to be able to show some of those playlist details first, and then as the tracks are ready and load in, be able to show those when they are ready. So again, we've got a new directive that we can use that works on fragments, I'm going to include that in here by adding an inline fragment with defer, I'm just going to wrap my tracks there with it. And let's go and see what that does with my application here. Okay, so we've added one additional layer of loading UI here. So in the best case, we're back to two loading states. But to illustrate the worst case, let's see what happens if the playlist details takes a little longer.
Comments