Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DevTools Bug]: React DevTools Profiler freezes after recording multiple events #31977

Closed
MariniGraphicDesigner opened this issue Jan 4, 2025 · 5 comments · Fixed by #32066
Closed
Labels
Component: Developer Tools Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug

Comments

@MariniGraphicDesigner
Copy link

Website or app

localhost

Repro steps

I'm experiencing an issue with React DevTools while debugging a project locally. Here are the steps to reproduce the issue:

  1. Open React DevTools and navigate to the Profiler tab.
  2. Start a recording by clicking on "Start Profiling," then stop it by clicking on "Stop Profiling."
  3. View the recording results without any issues.
  4. Attempt to start a new recording by clicking on "Start Profiling" again.
  5. After a few moments, the Profiler becomes extremely slow or completely unresponsive.
  6. At this point, I am unable to make additional recordings or refresh the Profiler data.

I hope these details help in identifying and resolving the issue. Let me know if you need further information or clarification.

How often does this bug happen?

Every time

DevTools package (automated)

No response

DevTools version (automated)

No response

Error message (automated)

No response

Error call stack (automated)

No response

Error component stack (automated)

No response

GitHub query string (automated)

No response

@MariniGraphicDesigner MariniGraphicDesigner added Component: Developer Tools Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug labels Jan 4, 2025
@adi-ydv-1
Copy link

@MariniGraphicDesigner try to clear your local cache.

@kevcam4891
Copy link

I'm encountering this issue as well. Recording even for a few seconds in profiler, then stopping, paints the flame graph successfully, but then all future clicks to the UI do not do anything. Closing dev tools then reopening, the react dev tools are no longer available in the tab bar.

Hemant77777777 added a commit to Hemant77777777/react-meta-fcebook that referenced this issue Jan 12, 2025
@GaneshS288
Copy link

GaneshS288 commented Jan 12, 2025

I started using react just today and encountered this while going over the devtools. I am attaching a video of the behaviour. It seems to freeze whenever i have previous profiling data present and I try to press start profiling.

20250112-1028-59.9864090.mp4

If you clear the profiling data before pressing start profiling button or press the reload and start profiling it works

@MariniGraphicDesigner
Copy link
Author

Sto riscontrando anche questo problema. La registrazione anche per alcuni secondi nel profiler, quindi l'arresto, dipinge correttamente il grafico della fiamma, ma tutti i clic futuri sull'interfaccia utente non fanno nulla. Chiudendo gli strumenti di sviluppo e poi riaprendo, gli strumenti di sviluppo delle reazioni non sono più disponibili nella barra delle schede.

I also have the exact same problem. After the Profiler tab freezes, even closing and reopening causes the React DevTools to disappear. I can also confirm that the video by @GaneshS288 shows the same behavior that happens to me and that I tried to describe in my post.

@V3RON
Copy link
Contributor

V3RON commented Jan 14, 2025

I believe I have pinpointed the exact reason why this is happening.

Profiling works fine the first time, but subsequently, the Dev Tools enter an infinite loop of state updates. It begins with a call to the startProfiling function. Next, SnapshotSelector invokes selectCommitIndex(0) because profiling data from a previous session is available, which triggers another re-render. Then, ProfilerContextProvider calls selectCommitIndex(null) because no commit is selected, causing yet another re-render. This loop continues indefinitely.

However, when you pause execution using a debugger in the startProfiling function and first call clear to remove the existing profiling data, everything functions correctly.

hoxyq pushed a commit that referenced this issue Jan 14, 2025
…#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](https://github.com/facebook/react/blob/b3a95caf61bc716fb618997e6e9f3a0c8c9c8374/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)`](https://github.com/facebook/react/blob/b3a95caf61bc716fb618997e6e9f3a0c8c9c8374/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](https://github.com/facebook/react/blob/b3a95caf61bc716fb618997e6e9f3a0c8c9c8374/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Developer Tools Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants