Road to a Better UX with Suspense and Concurrent UI

Rate this content

Put up your thinking caps with Suspense and Concurrent mode! In this talk, I would discuss how to improve the existing user experience with the magic of React’s Suspense and Concurrent mode for non-blocked rendering. The talk would highlight the best practices and guidelines for the same.

9 min
14 May, 2021

AI Generated Video Summary

This talk explores how React Suspense and Concurrent mode can enhance the user experience by controlling loading areas, prefetching data, and reducing loading time. It demonstrates how UseTransition can remove unnecessary loaders by skipping the loading state if data arrives within a specified time. The speaker advises using these experimental features in personal projects rather than enterprise applications. The talk concludes with an invitation to join the journey at Postman and thanks to the organizers, sponsors, speakers, and audience for making the conference a success.

1. Introduction to React Suspense and Concurrent Mode

Short description:

In this talk, we'll discuss how to take UX to the next level with React Suspense and Concurrent mode. We'll cover controlling the loading area, prefetching data, and reducing loading time. We'll also explore how concurrent mode can remove unnecessary loaders. A demo of a Twitter dashboard will be used to showcase these concepts.

Hey everyone! So today, I'm actually going to be discussing how we can take UX to the next level with React Suspense and Concurrent mode. So before starting, for the ones who don't know me, hey, I'm Nikhil, I'm a software engineer at Postman. I actually handle stuff around design systems, Postman on the web, and Postman as a platform. You can actually find me on Twitter, on Github. I actually love to talk about design systems, and performance in general, so come say hi, it's actually going to be a great chat.

So before diving in, let's cover what are going to be the key takeaways of this lightning So in this talk, we are actually going to discuss how we can actually have more control over the loading area, which means how we can actually control where exactly do we want to show a loading shape. Is it going to be the whole page, or can we actually control loading on the UI that's going to be asynchronous with the API called Suspense? Secondly, we are going to see how we can start prefetching our data or our screens in background while we are right now in some other screen with the magic of concurrent mode. And thirdly, we'll actually see how we can actually reduce that janky spinner Nudra experience with actually the users for our faster connections actually face with a loading indicator which just comes and goes in a flash for them using a hook called use transition. Okay, so with that being said, let's actually deep dive and thread this road to a great UX together.

So I'll actually switch to a small demo of a Twitter dashboard that I actually have here, right? So this dashboard actually shows me a profile section where it shows my name, my designation, it has a small about me section, which actually displays a small description around me and the work that I've done. And there's a tweet section which actually just shows what is that then treat that I put it. Just don't try to go check the Twitter. It's just something that I couldn't write. So and there's an extra button, which I click and then I just see another tweet. Okay, so far, so good. Now, let me actually just go and switch to concurrent mode on version of this app. And they just see how we can actually improve the UX right now. So let me just refresh and I go to this about me section. And if you see I have this nice big loader on my whole tab. And because of like, even if I have just small content inside my tab, which is my description, which was like asynchronous, but I'm actually loading my whole tab, and I'm actually showing a screen up for this whole section, which is actually not a great user experience. Right? I could actually rendered my static content as regardless of the fact that my description is running or not right. So moving on to how it is right now coded, let's actually see how we are actually written this up in our code. So we have a suspense block inside this block, I have some static content as a small div. So what if I could actually take this particular div out and render this inside, outside the suspense block, right? And this is actually how suspense actually gives you a fine grain control by defining a small sort of a boundary, and it lets you control over what exactly do you want to show your loading upon. So let's say this, I refresh this app, I go to my about me section, and now my static content is already there for my users to interact with while my description was loading. Okay, so, so far so good and it's simple. Now, let's actually try to uncover and see how concurrent mode can actually help us in removing some of those more loaders, right? So on the left side, we actually have a synchronous synchronous mode of that app. And we actually, right now, fetch stuff while we are going to a screen, right? So in the left, and I click on this about me section, I see a nice loader, and then I start loading that stuff right. And, but since concurrent mode is something which switches tasks or into priority, I can actually start fetching my description and my tweets, actually, when I am right now on the profile page, and I can actually start rendering things in parallel, while I'm on this profile. So what do you think that what would happen if I just go to about me section and I just click on this, would I see a loader? Let's actually find out.

2. Removing Loaders with UseTransition

Short description:

So I click on a tweet section, and it starts fetching data in the background. The loader that appears when clicking the next tweet button is unnecessary for faster connection users. We can remove the loader using UseTransition and a timeout. This allows React to skip the loading state if the data arrives within a specified time. By using the start transition function, we can handle the loading state and use the spending billion value provided by UseTransition. This allows us to skip the loading state in synchronous concurrent mode and display the tweet instantly.

So I click on this, no loader, no spinner, it just appears that it was actually right now there, right? I click on this tweet section, but on this left-hand side, I click on this and it now starts to fetch stuff while I'm now on the stream, right?

Okay, so two spinners have now been mitigated. Okay, now let's start to actually uncover another use case. So what happens when I click on this next tweet button? I actually see a loader and it just comes and goes, right? I just see it in a flash. And this is something that our faster connection users face, right? And the purpose of this loader is not defeated because the small milliseconds of time would be something that you would actually skip that loading state, right? And you would actually just let your stream be as it is rather than just showing the loader.

Now, let's actually try to remove this loader itself and use a code called UseTransition. So I have this component right here, which is TweetList and let me just comment out this line, which is called UseTransition. And what it actually asks me to give it is a timeout in milliseconds. Now what this actually means is React will actually skip my loading state if my data actually comes within these two seconds of time. So if I check this onclick logic of my button, right, this is actually the logic where I actually set my state and enable loading state with suspense. Now what if I could actually just take all of this I copy and use start transition which actually has a function and I copy and paste all of that stuff inside. Okay. And the start function actually takes care of all the stuff that if the data actually arrives within these two seconds of time just to the loading state. Now let's actually use this spending billion value which use transition gives us. So let's disable this button to actually see this. I save it. Now let's actually see how things happen in synchronous concurrent mode. Right. So I click on this tweet section. Now I'm seeing a loading sheet for the first time. Click on this button. It's synchronous mode and I'm right now seeing a loader which is not really good. So let's actually see what happens when I switch to concurrent mode. So with that huge transition hook, I can actually skip that loading state now. Right. So I click on this next week. I don't see a loader. Just stay on it as it is. And then the tweet appears in a flash. Let's actually see one more time. I click on this no loader and the tweet appears just like a flash.

3. Conclusion and Acknowledgements

Short description:

And it seemed that it just all happened in an instant. We have made good progress in terms of UX. However, suspense and concurrent mode are still experimental, so it's advisable to use them in personal projects rather than enterprise applications. On a side note, we are building great things at Postman and invite you to join our journey. Thank you to the organizers, sponsors, speakers, and audience for making this conference a success.

And it seemed that it just all happened in an instant. Right. Okay. So far so good. And I think we have actually made some good improvement and progress in terms of a good UX. Right. So far so good. You guys are awesome.

Now you all might be tempted to think that, hey, this is a super cool API and let me just use suspense and concurrent mode and tell my managers and technical leads and, hey, let's use this API. It's awesome. And this is something that actually Facebook and React itself might not be in favor of right now because suspense or data fetching and concurrent mode are something that right now are experimental. And the Facebook team is right now still looking for more feedback since the API is still expected to evolve and can be error prone right now since it's experimental. So you might actually want to fiddle with these APIs in your personal side projects, but thinking of something that is enterprise is not something that you would actually want to do, right? Since things can be error prone.

On a side note, we are building great things at Postman. So if you actually like to be a part of our journey, please come say hi and visit us at our career's website. We'd like to connect and discuss things forward. So with this, I'd actually like to end my talk. A big thanks to all the organizers and the sponsors for who are actually working so hard to making this conference a great success and all the speakers and at the last but not the least, your audience. You guys, you guys are great at having actually great time discussing my thoughts with all of you.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

React Advanced Conference 2022React Advanced Conference 2022
25 min
A Guide to React Rendering Behavior
React is a library for "rendering" UI from components, but many users find themselves confused about how React rendering actually works. What do terms like "rendering", "reconciliation", "Fibers", and "committing" actually mean? When do renders happen? How does Context affect rendering, and how do libraries like Redux cause updates? In this talk, we'll clear up the confusion and provide a solid foundation for understanding when, why, and how React renders. We'll look at: - What "rendering" actually is - How React queues renders and the standard rendering behavior - How keys and component types are used in rendering - Techniques for optimizing render performance - How context usage affects rendering behavior| - How external libraries tie into React rendering
React Summit Remote Edition 2021React Summit Remote Edition 2021
33 min
Building Better Websites with Remix
Remix is a new web framework from the creators of React Router that helps you build better, faster websites through a solid understanding of web fundamentals. Remix takes care of the heavy lifting like server rendering, code splitting, prefetching, and navigation and leaves you with the fun part: building something awesome!
React Advanced Conference 2022React Advanced Conference 2022
30 min
Using useEffect Effectively
Can useEffect affect your codebase negatively? From fetching data to fighting with imperative APIs, side effects are one of the biggest sources of frustration in web app development. And let’s be honest, putting everything in useEffect hooks doesn’t help much. In this talk, we'll demystify the useEffect hook and get a better understanding of when (and when not) to use it, as well as discover how declarative effects can make effect management more maintainable in even the most complex React apps.
React Summit 2022React Summit 2022
20 min
Routing in React 18 and Beyond
Concurrent React and Server Components are changing the way we think about routing, rendering, and fetching in web applications. Next.js recently shared part of its vision to help developers adopt these new React features and take advantage of the benefits they unlock.In this talk, we’ll explore the past, present and future of routing in front-end applications and discuss how new features in React and Next.js can help us architect more performant and feature-rich applications.
React Advanced Conference 2021React Advanced Conference 2021
27 min
(Easier) Interactive Data Visualization in React
If you’re building a dashboard, analytics platform, or any web app where you need to give your users insight into their data, you need beautiful, custom, interactive data visualizations in your React app. But building visualizations hand with a low-level library like D3 can be a huge headache, involving lots of wheel-reinventing. In this talk, we’ll see how data viz development can get so much easier thanks to tools like Plot, a high-level dataviz library for quick & easy charting, and Observable, a reactive dataviz prototyping environment, both from the creator of D3. Through live coding examples we’ll explore how React refs let us delegate DOM manipulation for our data visualizations, and how Observable’s embedding functionality lets us easily repurpose community-built visualizations for our own data & use cases. By the end of this talk we’ll know how to get a beautiful, customized, interactive data visualization into our apps with a fraction of the time & effort!

Workshops on related topic

React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Featured WorkshopFree
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
React Advanced Conference 2021React Advanced Conference 2021
132 min
Concurrent Rendering Adventures in React 18
Featured WorkshopFree
With the release of React 18 we finally get the long awaited concurrent rendering. But how is that going to affect your application? What are the benefits of concurrent rendering in React? What do you need to do to switch to concurrent rendering when you upgrade to React 18? And what if you don’t want or can’t use concurrent rendering yet?

There are some behavior changes you need to be aware of! In this workshop we will cover all of those subjects and more.

Join me with your laptop in this interactive workshop. You will see how easy it is to switch to concurrent rendering in your React application. You will learn all about concurrent rendering, SuspenseList, the startTransition API and more.
React Summit Remote Edition 2021React Summit Remote Edition 2021
177 min
React Hooks Tips Only the Pros Know
Featured Workshop
The addition of the hooks API to React was quite a major change. Before hooks most components had to be class based. Now, with hooks, these are often much simpler functional components. Hooks can be really simple to use. Almost deceptively simple. Because there are still plenty of ways you can mess up with hooks. And it often turns out there are many ways where you can improve your components a better understanding of how each React hook can be used.You will learn all about the pros and cons of the various hooks. You will learn when to use useState() versus useReducer(). We will look at using useContext() efficiently. You will see when to use useLayoutEffect() and when useEffect() is better.
React Advanced Conference 2021React Advanced Conference 2021
174 min
React, TypeScript, and TDD
Featured WorkshopFree
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
React Advanced Conference 2021React Advanced Conference 2021
145 min
Web3 Workshop - Building Your First Dapp
Featured WorkshopFree
In this workshop, you'll learn how to build your first full stack dapp on the Ethereum blockchain, reading and writing data to the network, and connecting a front end application to the contract you've deployed. By the end of the workshop, you'll understand how to set up a full stack development environment, run a local node, and interact with any smart contract using React, HardHat, and Ethers.js.
React Summit 2023React Summit 2023
151 min
Designing Effective Tests With React Testing Library
Featured Workshop
React Testing Library is a great framework for React component tests because there are a lot of questions it answers for you, so you don’t need to worry about those questions. But that doesn’t mean testing is easy. There are still a lot of questions you have to figure out for yourself: How many component tests should you write vs end-to-end tests or lower-level unit tests? How can you test a certain line of code that is tricky to test? And what in the world are you supposed to do about that persistent act() warning?
In this three-hour workshop we’ll introduce React Testing Library along with a mental model for how to think about designing your component tests. This mental model will help you see how to test each bit of logic, whether or not to mock dependencies, and will help improve the design of your components. You’ll walk away with the tools, techniques, and principles you need to implement low-cost, high-value component tests.
Table of contents- The different kinds of React application tests, and where component tests fit in- A mental model for thinking about the inputs and outputs of the components you test- Options for selecting DOM elements to verify and interact with them- The value of mocks and why they shouldn’t be avoided- The challenges with asynchrony in RTL tests and how to handle them
Prerequisites- Familiarity with building applications with React- Basic experience writing automated tests with Jest or another unit testing framework- You do not need any experience with React Testing Library- Machine setup: Node LTS, Yarn