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.

This talk has been presented at React Advanced Conference 2023, check out the latest edition of this React Conference.

Watch video on a separate page

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
Kent C. Dodds discusses the concept of problem elimination rather than just problem-solving. He introduces the idea of a problem tree and the importance of avoiding creating solutions prematurely. Kent uses examples like Tesla's electric engine and Remix framework to illustrate the benefits of problem elimination. He emphasizes the value of trade-offs and taking the easier path, as well as the need to constantly re-evaluate and change approaches to eliminate problems.
Modern Web Debugging
JSNation 2023JSNation 2023
29 min
Modern Web Debugging
Top Content
This Talk discusses modern web debugging and the latest updates in Chrome DevTools. It highlights new features that help pinpoint issues quicker, improved file visibility and source mapping, and ignoring and configuring files. The Breakpoints panel in DevTools has been redesigned for easier access and management. The Talk also covers the challenges of debugging with source maps and the efforts to standardize the source map format. Lastly, it provides tips for improving productivity with DevTools and emphasizes the importance of reporting bugs and using source maps for debugging production code.
The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Today's Talk discusses the future of performance tooling, focusing on user-centric, actionable, and contextual approaches. The introduction highlights Adi Osmani's expertise in performance tools and his passion for DevTools features. The Talk explores the integration of user flows into DevTools and Lighthouse, enabling performance measurement and optimization. It also showcases the import/export feature for user flows and the collaboration potential with Lighthouse. The Talk further delves into the use of flows with other tools like web page test and Cypress, offering cross-browser testing capabilities. The actionable aspect emphasizes the importance of metrics like Interaction to Next Paint and Total Blocking Time, as well as the improvements in Lighthouse and performance debugging tools. Lastly, the Talk emphasizes the iterative nature of performance improvement and the user-centric, actionable, and contextual future of performance tooling.
Jotai Atoms Are Just Functions
React Day Berlin 2022React Day Berlin 2022
22 min
Jotai Atoms Are Just Functions
Top Content
State management in React is a highly discussed topic with many libraries and solutions. Jotai is a new library based on atoms, which represent pieces of state. Atoms in Jotai are used to define state without holding values and can be used for global, semi-global, or local states. Jotai atoms are reusable definitions that are independent from React and can be used without React in an experimental library called Jotajsx.
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
Watch video: Debugging JS
Debugging JavaScript is a crucial skill that is often overlooked in the industry. It is important to understand the problem, reproduce the issue, and identify the root cause. Having a variety of debugging tools and techniques, such as console methods and graphical debuggers, is beneficial. Replay is a time-traveling debugger for JavaScript that allows users to record and inspect bugs. It works with Redux, plain React, and even minified code with the help of source maps.
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
Remix Flat Routes is a new convention that aims to make it easier to see and organize the routes in your app. It allows for the co-location of support files with routes, decreases refactor and redesign friction, and helps apps migrate to Remix. Flat Folders convention supports co-location and allows importing assets as relative imports. To migrate existing apps to Flat Routes, use the Remix Flat Routes package's migration tool.

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.
Mastering advanced concepts in TypeScript
React Summit US 2023React Summit US 2023
132 min
Mastering advanced concepts in TypeScript
Top Content
Featured WorkshopFree
Jiri Lojda
Jiri Lojda
TypeScript is not just types and interfaces. Join this workshop to master more advanced features of TypeScript that will make your code bullet-proof. We will cover conditional types and infer notation, template strings and how to map over union types and object/array properties. Each topic will be demonstrated on a sample application that was written with basic types or no types at all and we will together improve the code so you get more familiar with each feature and can bring this new knowledge directly into your projects.
You will learn:- - What are conditional types and infer notation- What are template strings- How to map over union types and object/array properties.
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