Building Better React Debugging with Replay Analysis

Rate this content
Bookmark

React's component model and one-way data flow give us a great mental model for building our apps, but debugging React apps can still be confusing. React's internals are a black box, and it's often hard to understand why components rendered or what caused errors.


The Replay time-travel debugger makes it easier to debug React apps by letting you inspect what's happening at any point in time. But what if we could go beyond the usual debugger features, and build new debugging features that tell us more about what React is doing? Let's see how Replay's API makes that possible.

FAQ

Replay is a time-traveling debugger designed for JavaScript that allows developers to record their application usage and then debug with advanced time-travel capabilities. This tool is especially beneficial for React developers as it helps identify and fix timing-related issues efficiently.

The React DevTools extension injects JavaScript into a page, creating a global variable that allows React in the page to communicate with the browser extension. It captures the fiber tree of React components after each render to analyze component changes, aiding developers in debugging and performance tuning.

React DevTools allows inspection of the React component tree, profiling of component renders to identify performance bottlenecks, and viewing current props, state, and hooks of selected components. It also shows the 'owner tree' that details the hierarchy of components that led to a particular render.

Replay is free for individual users and open-source developers. There is a pricing model for companies, but it is designed to be flexible to accommodate different needs.

Yes, while Replay is optimized for React and heavily used within the React community, it is not framework-specific. It can be used with other JavaScript frameworks like Vue, Angular, or even jQuery.

Redux Toolkit 2.0 is the latest version of the toolkit that aims to simplify Redux development. Developers are encouraged to beta test this version and provide feedback on new features and API designs, which could influence the final adjustments before its official release.

Replay introduces a novel approach to debugging by allowing developers to record, replay, and scrutinize their application's behavior over time. This enables pinpointing exact moments of failures or bugs, which is more challenging with traditional debugging methods that do not have time-travel capabilities.

React DevTools provides a detailed view of the component tree, showing the relationships and hierarchies between components. It helps developers understand how data flows through the application, inspect component states and properties, and track performance issues.

Mark Erikson
Mark Erikson
31 min
20 Oct, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Today's Talk focused on building better React dev tools with replay time travel analysis. The React DevTools provide valuable insights into React apps, using a fiber data structure to represent component instances. Replay is a time-traveling debugger for React, with plans to make Chrome their primary recording browser. They extract React information from recordings using their time travel API and have built a UI for debugging and inspecting the content. The long-term goal is to have Replay work offline and in permanent record mode.

1. Introduction to Building Better React Dev Tools

Short description:

Today, I will talk about building better react dev tools with replay time travel analysis. Redux Toolkit 2.0 is in beta, and we appreciate your feedback. The React DevTools are a valuable tool for understanding your React app.

All right, good afternoon, thank you very much. My name is Mark Eriksson, and today I am very excited to talk to you about building better react dev tools with replay time travel analysis, the title changes, whatever. Thank you for being here. I'll be honest, this is probably not going to be the most actionable talk. There aren't a lot of things. It's like I can go home and like immediately change my code.

We will definitely be diving deep today. I will have the slides up on my blog later today, blog.i2software.com, and very happy to answer questions about this later. A couple quick things about myself. I am a senior frontend engineer at Replay, where we are building a time traveling debugger for JavaScript, and we will talk about that. I will answer questions anywhere there is a text box on the internet. I collect all kinds of interesting links. I write ridiculously long blog posts, and I am a Redux maintainer, but most people know me as the guy with the Simpsons avatar.

Out of curiosity, how many people... we will get to the React stuff in a second. One quick note. Redux Toolkit 2.0 is in beta. We would really appreciate people trying that out and giving us feedback. Let us know how the new feature works. Give us feedback if we should try to change some of the API designs before it goes final. Please, please try that out and let us know how it works. ETA soon. How many of you have the React DevTools extension installed in your browser? Okay, good. That's most of the hands. Very happy to see that. The React DevTools are a wonderful aid for understanding what is going on in your React app. It's one of the great advantages they have over earlier frameworks like Backbone. What are they? They let us inspect the component tree in the page. They show us the parent-child relationships, the order of the components, and if you select a component, then it will show you the current props, the hooks, the state, even something called the owner tree, which is the chain of components that rendered it. It is an extremely valuable tool for understanding your React app.

2. Understanding React Dev Tools

Short description:

The React dev tools have a profiler panel that shows the number of renders, the components rendered, and their rendering time. It uses a data structure called a fiber to represent component instances. React communicates with the browser extension through a global hook object, allowing it to send information about renders. The fiber tree has pointers to the previous version, enabling the extension to compare the current and previous trees during the commit phase.

The React dev tools also have a profiler panel. You can hit the record button, use the app for a minute, and it will show you a list or a count of all the times that the application rendered, and for each render, it will show you which components in the tree rendered, and how long each of them took. The flame graph gives you a relative sense of this component took twice as long as that one. Very valuable for understanding the overall performance of your app.

But how does this even work? Magic. Okay. Not actually magic, but a lot of very careful engineering. So we know function components and class components. But in a lot of ways, those are just kind of like little facades over the actual data. Internally, React has a data structure called a fiber. And each fiber represents one component instance in the tree. And so React stores the type of the component, literally the function or the class. It stores the current props. It has a linked list that points to parents and siblings and children, and a whole lot of other internal metadata. And so, this truly is the real tree of the components. Every time React finishes a render, it has this tree of fibers that represents the component instances.

So, when you install the browser extension, React, that gets loaded into every page and it injects some JavaScript. And this creates a global variable, double underscore React DevTools global hook, double underscore. And this is how React in the page is going to talk to the browser extension. So, this global hook object, which by the way, has nothing to do with hooks, like use whatever, it's just a naming collision. It stores references to every different copy of React that's in the page. It has some event emitter capabilities and it has some callbacks that React will run every time it has rendered. So, when you load React in the page, one of the first things it does, is it looks to see, does this global hook object exist? And if so, it knows that the browser extension is there and it will try to send the information later.

So, every time React finishes rendering at the end of the commit phase, it will then talk to the global hook and run this on commit fiber root method. And it passes over the top level fiber representing the root component for the whole tree. And now, at that point, the browser extension has some code that runs inside the page, and it can look at the tree of components and see what is there and what did the tree look like before that. So, how does it know what the component tree looks like? I mean, it's obvious. It's right there. We can all read this, right? So, the fiber tree actually has pointers to the previous version of the tree from the last commit as well. And so, during the commit phase, when it runs this callback, the extension code in the page can walk over the tree and diff it to compare here was the tree last time versus here is the this time.

QnA

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

Don't Solve Problems, Eliminate Them
React Advanced Conference 2021React Advanced Conference 2021
39 min
Don't Solve Problems, Eliminate Them
Top Content
Humans are natural problem solvers and we're good enough at it that we've survived over the centuries and become the dominant species of the planet. Because we're so good at it, we sometimes become problem seekers too–looking for problems we can solve. Those who most successfully accomplish their goals are the problem eliminators. Let's talk about the distinction between solving and eliminating problems with examples from inside and outside the coding world.
Modern Web Debugging
JSNation 2023JSNation 2023
29 min
Modern Web Debugging
Top Content
Few developers enjoy debugging, and debugging can be complex for modern web apps because of the multiple frameworks, languages, and libraries used. But, developer tools have come a long way in making the process easier. In this talk, Jecelyn will dig into the modern state of debugging, improvements in DevTools, and how you can use them to reliably debug your apps.
The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Our understanding of performance & user-experience has heavily evolved over the years. Web Developer Tooling needs to similarly evolve to make sure it is user-centric, actionable and contextual where modern experiences are concerned. In this talk, Addy will walk you through Chrome and others have been thinking about this problem and what updates they've been making to performance tools to lower the friction for building great experiences on the web.
Jotai Atoms Are Just Functions
React Day Berlin 2022React Day Berlin 2022
22 min
Jotai Atoms Are Just Functions
Top Content
Jotai is a state management library. We have been developing it primarily for React, but it's conceptually not tied to React. It this talk, we will see how Jotai atoms work and learn about the mental model we should have. Atoms are framework-agnostic abstraction to represent states, and they are basically just functions. Understanding the atom abstraction will help designing and implementing states in your applications with Jotai
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
As developers, we spend much of our time debugging apps - often code we didn't even write. Sadly, few developers have ever been taught how to approach debugging - it's something most of us learn through painful experience.  The good news is you _can_ learn how to debug effectively, and there's several key techniques and tools you can use for debugging JS and React apps.
Remix Flat Routes – An Evolution in Routing
Remix Conf Europe 2022Remix Conf Europe 2022
16 min
Remix Flat Routes – An Evolution in Routing
Top Content
This talk introduces the new Flat Routes convention that will most likely be the default in a future version of Remix. It simplifies the existing convention as well as gives you new capabilities.

Workshops on related topic

React Performance Debugging Masterclass
React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Top Content
Featured WorkshopFree
Ivan Akulov
Ivan Akulov
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, TypeScript, and TDD
React Advanced Conference 2021React Advanced Conference 2021
174 min
React, TypeScript, and TDD
Top Content
Featured WorkshopFree
Paul Everitt
Paul Everitt
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.
Web3 Workshop - Building Your First Dapp
React Advanced Conference 2021React Advanced Conference 2021
145 min
Web3 Workshop - Building Your First Dapp
Top Content
Featured WorkshopFree
Nader Dabit
Nader Dabit
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.
Remix Fundamentals
React Summit 2022React Summit 2022
136 min
Remix Fundamentals
Top Content
Featured WorkshopFree
Kent C. Dodds
Kent C. Dodds
Building modern web applications is riddled with complexity And that's only if you bother to deal with the problems
Tired of wiring up onSubmit to backend APIs and making sure your client-side cache stays up-to-date? Wouldn't it be cool to be able to use the global nature of CSS to your benefit, rather than find tools or conventions to avoid or work around it? And how would you like nested layouts with intelligent and performance optimized data management that just works™?
Remix solves some of these problems, and completely eliminates the rest. You don't even have to think about server cache management or global CSS namespace clashes. It's not that Remix has APIs to avoid these problems, they simply don't exist when you're using Remix. Oh, and you don't need that huge complex graphql client when you're using Remix. They've got you covered. Ready to build faster apps faster?
At the end of this workshop, you'll know how to:- Create Remix Routes- Style Remix applications- Load data in Remix loaders- Mutate data with forms and actions
Vue3: Modern Frontend App Development
Vue.js London Live 2021Vue.js London Live 2021
169 min
Vue3: Modern Frontend App Development
Top Content
Featured WorkshopFree
Mikhail Kuznetcov
Mikhail Kuznetcov
The Vue3 has been released in mid-2020. Besides many improvements and optimizations, the main feature of Vue3 brings is the Composition API – a new way to write and reuse reactive code. Let's learn more about how to use Composition API efficiently.

Besides core Vue3 features we'll explain examples of how to use popular libraries with Vue3.

Table of contents:
- Introduction to Vue3
- Composition API
- Core libraries
- Vue3 ecosystem

Prerequisites:
IDE of choice (Inellij or VSC) installed
Nodejs + NPM
Developing Dynamic Blogs with SvelteKit & Storyblok: A Hands-on Workshop
JSNation 2023JSNation 2023
174 min
Developing Dynamic Blogs with SvelteKit & Storyblok: A Hands-on Workshop
Top Content
Featured WorkshopFree
Alba Silvente Fuentes
Roberto Butti
2 authors
This SvelteKit workshop explores the integration of 3rd party services, such as Storyblok, in a SvelteKit project. Participants will learn how to create a SvelteKit project, leverage Svelte components, and connect to external APIs. The workshop covers important concepts including SSR, CSR, static site generation, and deploying the application using adapters. By the end of the workshop, attendees will have a solid understanding of building SvelteKit applications with API integrations and be prepared for deployment.