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] feat: show changed hooks names in the Profiler tab #31398

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

piotrski
Copy link

@piotrski piotrski commented Nov 1, 2024

Summary

This PR adds support for displaying the names of changed hooks directly in the Profiler tab, making it easier to identify specific updates.

A HookChangeSummary component has been introduced to show these hook names, with a displayMode prop that toggles between “compact” for tooltips and “detailed” for more in-depth views. This keeps tooltip summaries concise while allowing for a full breakdown where needed.

This functionality also respects the “Always parse hook names from source” setting from the Component inspector, as it uses the same caching mechanism already in place for the Components tab. Additionally, even without hook names parsed, the Profiler will now display hook types (like State, Callback, etc.) based on data from inspectedElement.

To enable this across the DevTools, InspectedElementContext has been moved higher in the component tree, allowing it to be shared between the Profiler and Components tabs. This update allows hook name data to be reused across tabs without duplication.

Additionally, a getAlreadyLoadedHookNames helper function was added to efficiently access cached hook names, reducing the need for repeated fetching when displaying changes.

These changes improve the ability to track specific hook updates within the Profiler tab, making it clearer to see what’s changed.

Before

Previously, the Profiler tab displayed only the IDs of changed hooks, as shown below:
Screenshot 2024-11-01 at 12 02 21_cropped

After (without hook names parsed)

When hook names aren’t parsed, custom hooks and hook types are displayed based on the inspectedElement data:
Screenshot 2024-11-01 at 12 03 09_cropped

After (with hook names parsed)

Once hook names are fully parsed, the Profiler tab provides a complete breakdown of specific hooks that have changed:
Screenshot 2024-11-01 at 12 03 14_cropped

This should resolve #21856 🎉

…cache

The InspectedElementContext was previously only available in the Components tab.
This change moves the context provider to a higher level in the component
hierarchy, making the InspectedElementContext available in both the Components
and Profiler tabs.
- Introduced `HookChangeSummary` component to show names of changed hooks, improving clarity and making it easier to identify specific hook updates in the Profiler tab.
- Added `getAlreadyLoadedHookNames` helper for efficient retrieval of hook names.

Resolves facebook#21856
…ry in tooltips

- Added `displayMode` prop to `HookChangeSummary` for `detailed` and `compact` views.
- Updated `WhatChanged` and `HoveredFiberInfo` to use `compact` mode in tooltips, preserving the previous concise summary display.

This change maintains the original hook change summary style in tooltips while allowing a detailed view where needed.
Copy link

vercel bot commented Nov 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 1, 2024 1:32pm

@hoxyq
Copy link
Contributor

hoxyq commented Nov 13, 2024

Hey, thanks for upstreaming this, really appreciate any contributions to React DevTools.

I am currently on leave and will be back first week of December. This change will probably require some manual testing on my side, so I think its better to iterate on this once I am fully available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DevTools] Show which hooks (names) changed in the Profiler
4 participants