A declarative, efficient, and flexible JavaScript library for building user interfaces. reactjs.org
Go to file
Szymon Chmal 453f505256
[DevTools] Prevent crash when starting consecutive profiling sessions (#32066)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

This pull request resolves an issue where consecutive profiling sessions
would cause Dev Tools to freeze due to an infinite loop of state
updates. The problem occurs when the startProfiling function triggers a
call to [`selectCommitIndex(0)` in
SnapshotSelector](b3a95caf61/packages/react-devtools-shared/src/devtools/views/Profiler/SnapshotSelector.js (L77-L85))
as previous profiling data is available, which causes a re-render. Then,
[ProfilerContextProvider calls
`selectCommitIndex(null)`](b3a95caf61/packages/react-devtools-shared/src/devtools/views/Profiler/ProfilerContext.js (L231-L241))
to clear the view while profiling is in progress, leading to another
re-render and creating an infinite loop. This behavior was prevented by
clearing the existing profiling data before starting a new session.

Closes #31977
Closes #31679

## How did you test this change?

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->

I ran the Dev Tools locally following [the contributing
guideline](b3a95caf61/packages/react-devtools/CONTRIBUTING.md).
I observed the freeze at the start of the second profiling session.
Then, I modified the code to clear the store when starting a new session
and ran the Dev Tools again. This time, no freeze was observed.

Before:

https://github.com/user-attachments/assets/9d790f84-f6d0-4951-8202-e599cf8d225b

After:

https://github.com/user-attachments/assets/af097019-0b8f-49dd-8afc-0f6cd72af787
2025-01-14 20:23:42 +00:00
.codesandbox Codesandbox: upgrade to Node.js 18 (#26330) 2023-03-06 15:38:03 -05:00
.github [ci] Make gh workflow names consistent (#32010) 2025-01-07 12:09:10 -05:00
compiler fix(eslint-plugin-react-compiler): support v9 context api (#32045) 2025-01-13 13:49:31 -05:00
fixtures View Transition Class Names based on event kind (#32050) 2025-01-13 09:45:53 -05:00
packages [DevTools] Prevent crash when starting consecutive profiling sessions (#32066) 2025-01-14 20:23:42 +00:00
scripts Add <ViewTransition> Component (#31975) 2025-01-08 12:11:18 -05:00
.editorconfig Remove trim_trailing_whitespace from editorconfig (#31413) 2024-11-04 15:30:02 -05:00
.eslintignore Fix ESLint and Prettier configs for React Compiler (#29073) 2024-05-15 14:02:57 -07:00
.eslintrc.js View Transition Refs (#32038) 2025-01-10 11:51:37 -05:00
.git-blame-ignore-revs Add run prettier commit to .git-blame-ignore-revs 2024-07-18 17:42:45 -04:00
.gitattributes .gitattributes to ensure LF line endings when we should 2014-01-17 16:25:53 -08:00
.gitignore feat[devtools]: add package for fusebox integration (#28553) 2024-04-12 15:29:35 +01:00
.mailmap updates mailmap entries (#19824) 2020-09-12 13:05:52 -04:00
.nvmrc [ci] Standardize node version and timezones 2024-07-12 12:53:05 -04:00
.prettierignore [prettier] Ignore compiler/target (#31168) 2024-10-10 10:53:27 -04:00
.prettierrc.js [BE] switch to hermes parser for prettier (#30421) 2024-07-22 19:16:13 -04:00
.watchmanconfig .watchmanconfig must be valid json (#16118) 2019-07-11 19:01:02 -07:00
babel.config.js Upgrade tests to use react/jsx-runtime (#28252) 2024-02-05 23:07:41 -05:00
CHANGELOG-canary.md Add useActionState to CHANGELOG-canary.md (#28632) 2024-03-26 13:15:08 -04:00
CHANGELOG.md Fix headings in React 19 CHANGELOG (#31683) 2024-12-06 16:55:53 +01:00
CODE_OF_CONDUCT.md revert last grammatical edit (#25067) 2022-08-10 20:14:31 +01:00
CONTRIBUTING.md Fix: Updated link in CONTRIBUTING (#25381) 2022-10-03 10:29:57 -04:00
dangerfile.js [ci] Cleanup more references to circleci 2024-07-29 19:18:03 -04:00
LICENSE [Codemod] Update copyright header to Meta (#25315) 2022-10-18 11:19:24 -04:00
netlify.toml [UMD] Remove umd builds (#28735) 2024-04-17 11:15:27 -07:00
package.json Bump rollup from 3.20.0 to 3.29.5 (#31072) 2024-09-26 09:56:33 -04:00
react.code-workspace created a vscode workspace file for the repo (#29830) 2024-06-13 16:23:42 +01:00
ReactVersions.js Fix canary version strings (#31721) 2024-12-12 14:11:24 -05:00
README.md [ez] Remove circleci badge from readme 2024-07-29 13:26:14 -04:00
SECURITY.md Create SECURITY.md (#15784) 2020-01-09 14:07:41 -08:00
yarn.lock react-hooks/rules-of-hooks: detect issues in class properties (#31823) 2025-01-06 12:12:09 +01:00

React · GitHub license npm version (Runtime) Build and Test (Compiler) TypeScript PRs Welcome

React is a JavaScript library for building user interfaces.

  • Declarative: React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes. Declarative views make your code more predictable, simpler to understand, and easier to debug.
  • Component-Based: Build encapsulated components that manage their own state, then compose them to make complex UIs. Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep the state out of the DOM.
  • Learn Once, Write Anywhere: We don't make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code. React can also render on the server using Node and power mobile apps using React Native.

Learn how to use React in your project.

Installation

React has been designed for gradual adoption from the start, and you can use as little or as much React as you need:

Documentation

You can find the React documentation on the website.

Check out the Getting Started page for a quick overview.

The documentation is divided into several sections:

You can improve it by sending pull requests to this repository.

Examples

We have several examples on the website. Here is the first one to get you started:

import { createRoot } from 'react-dom/client';

function HelloMessage({ name }) {
  return <div>Hello {name}</div>;
}

const root = createRoot(document.getElementById('container'));
root.render(<HelloMessage name="Taylor" />);

This example will render "Hello Taylor" into a container on the page.

You'll notice that we used an HTML-like syntax; we call it JSX. JSX is not required to use React, but it makes code more readable, and writing it feels like writing HTML.

Contributing

The main purpose of this repository is to continue evolving React core, making it faster and easier to use. Development of React happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving React.

Code of Conduct

Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Contributing Guide

Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React.

Good First Issues

To help you get your feet wet and get you familiar with our contribution process, we have a list of good first issues that contain bugs that have a relatively limited scope. This is a great place to get started.

License

React is MIT licensed.