Staying Safe in a Concurrent World

Rate this content
Bookmark

With React 18 the long awaited concurrent features are now available to the public. While they technically do not introduce new restrictions about how we build our components, there are many patterns that previously worked but might now introduce subtle bugs in your apps. Let's re-learn the rules of React so that we can stay safe in this new concurrent world.

Andreas Roth
Andreas Roth
22 min
24 Oct, 2022

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This talk explores the implications of the new concurrent features in React 18 and how they impact developers. It discusses the core premise of React and the importance of pure function components. The talk also addresses misconceptions about React's rendering process and the prevention of tearing in applications. Additionally, it highlights the reconciliation and commit phases in React and the challenges of dependency management in state management libraries.

1. Introduction to React 18 Concurrent Features

Short description:

This talk explores the implications of the new concurrent features in React 18 and how they impact developers. The speaker, Andreas, shares his experience as a development lead in a software agency and highlights the importance of staying safe in a concurrent world.

I hope you're having an awesome conference so far. Maybe you even listened to a couple of talks mentioning the new concurrent features that were released in React 18 a couple of months ago. In this talk, we are not going into details about how these features work and what they are doing, but we want to take a look at the implications and ramifications that those features have on us as developers so that we can stay safe in a concurrent world of React.

Before we are going to dive into that, let me first tell you a bit about myself. My name is Andreas and I'm from Dresden in Germany, where I'm a development lead in a small software agency. Our job is to go into other software development companies and help the teams accelerate their software projects. We do that by using technologies like TypeScript React. So, this is exactly the stuff that I'm doing every day.

In this work, what we realized over the last couple of months is that there's lots of fear, uncertainty and doubt because of the new React agent release, the new rules and what you have to do to be concurrent mode-safe in your applications. And this is why I proposed this talk, so that you can lean back and stay safe in a concurrent world.

2. Evolution of React's Rendering Techniques

Short description:

Abramov introduced async rendering in 2018 to make React adapt to the user's device and ensure fast and responsive interactions. Since then, the release date was pushed back, and the name changed to concurrent rendering or concurrent mode. With React 18, concurrent features were introduced, allowing developers to opt-in specific parts of their application. The rules of React have not changed, but we are now starting to utilize them more effectively.

When we jumped back a couple of years ago, to 2018, then Abramov introduced async rendering. So, React should adapt to the user's device, fast interactions should feel instant and slow-end interactions should feel responsive. And the main technique was by splitting up the rendering process, so that we can pause, resume, do different updates, so that our application will stay fast and responsive, no matter the device or the network conditions.

Since then, lots have changed. So, for example, the release date has pushed back a bit, has been pushed back a bit, and the name changed from async rendering to concurrent rendering or concurrent mode. And then with React 18, the team made the awesome decision to not introduce a concurrent mode that switches all of your application in this new concurrent world, but they introduced concurrent features, so that you can opt in in tiny parts of your application into the concurrent features, so that your whole application must not be concurrent mode ready, but only parts of your application.

They even released a blog post back then, where they made certain changes to the React API to prepare this change for the future. So they removed component will mount, component will receive props and component will update, or replaced them with unsafe variants. This is so you as developers know that these methods are not really safe to use with concurrent features, but they can still live in your codebase as long as you don't use the concurrent features. You could say, the rules of React have changed since then. But it is not true. The rules of React have not changed since back then. This is the most important point of my presentation. The rules of React have not changed. We are only now starting to really make use of the same rules that have been present way back then.

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 Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
React 18! Concurrent features! You might’ve already tried the new APIs like useTransition, or you might’ve just heard of them. But do you know how React 18 achieves the performance wins it brings with itself? In this talk, let’s peek under the hood of React 18’s performance features: - How React 18 lowers the time your page stays frozen (aka TBT) - What exactly happens in the main thread when you run useTransition() - What’s the catch with the improvements (there’s no free cake!), and why Vue.js and Preact straight refused to ship anything similar
Understanding React’s Fiber Architecture
React Advanced Conference 2022React Advanced Conference 2022
29 min
Understanding React’s Fiber Architecture
Top Content
We've heard a lot about React's Fiber Architecture, but it feels like few of us understand it in depth (or have the time to). In this talk, Tejas will go over his best attempt at understanding Fiber (reviewed by other experts), and present it in an 'explain-like-I'm-five years old' way.
Inside Fiber: the in-depth overview you wanted a TLDR for
React Summit 2022React Summit 2022
27 min
Inside Fiber: the in-depth overview you wanted a TLDR for
I want to provide an in-depth overview of the important concepts behind reconciliation. We'll then explore how React uses the algorithm and go through a few magic words we hear a lot, like coroutines, continuations, fibers, generators, algebraic effects and see how they all relate to React.js.
Server Components: The Epic Tale of Rendering UX
React Summit 2023React Summit 2023
26 min
Server Components: The Epic Tale of Rendering UX
Server components, introduced in React v18 end these shortcomings, enabling rendering React components fully on the server, into an intermediate abstraction format without needing to add to the JavaScript bundle. This talk aims to cover the following points:1. A fun story of how we needed CSR and how SSR started to take its place2. What are server components and what benefits did they bring like 0 javascript bundle size3. Demo of a simple app using client-side rendering, SSR, and server components and analyzing the performance gains and understanding when to use what4. My take on how rendering UI will change with this approach
Cracking the Concurrent Mode
React Advanced Conference 2021React Advanced Conference 2021
30 min
Cracking the Concurrent Mode
With concurrent mode coming in React 18, let's talk about the complexities behind providing declarative APIs for concurrent rendering. While implementing concurrent mode APIs from scratch for Brahmos.js, I came across lot of use cases and variability which made it one of the most interesting problem to solve, and appreciate more the React's effort on advocating Concurrent UI. In this talk we will see what concurrent mode means for a web app, what are the internal complexities and how I solved it for Brahmos.js.
A Practical Guide for Migrating to Server Components
React Advanced Conference 2023React Advanced Conference 2023
28 min
A Practical Guide for Migrating to Server Components
Server Components are the hot new thing, but so far much of the discourse around them has been abstract. Let's change that. This talk will focus on the practical side of things, providing a roadmap to navigate the migration journey. Starting from an app using the older Next.js pages router and React Query, we’ll break this journey down into a set of actionable, incremental steps, stopping only when we have something shippable that’s clearly superior to what we began with. We’ll also discuss next steps and strategies for gradually embracing more aspects of this transformative paradigm.

Workshops on related topic

Concurrent Rendering Adventures in React 18
React Advanced Conference 2021React Advanced Conference 2021
132 min
Concurrent Rendering Adventures in React 18
Top Content
Featured WorkshopFree
Maurice de Beijer
Maurice de Beijer
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.
Getting Started with Suspense and Concurrent Rendering in React
React Summit 2020React Summit 2020
125 min
Getting Started with Suspense and Concurrent Rendering in React
Featured Workshop
Maurice de Beijer
Maurice de Beijer
React keeps on evolving and making hard things easier for the average developer.
One case, where React was not particularly hard but very repetitive, is working with AJAX request. There is always the trinity of loading, success and possible error states that had to be handled each time. But no more as the `<Suspense />` component makes life much easier.
Another case is performance of larger and complex applications. Usually React is fast enough but with a large application rendering components can conflict with user interactions. Concurrent rendering will, mostly automatically, take care of this.
You will learn all about using <Suspense />, showing loading indicators and handling errors. You will see how easy it is to get started with concurrent rendering. You will make suspense even more capable combining it with concurrent rendering, the `useTransition()` hook and the <SuspenseList /> component.