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]: Confusing "Why did this render?" with hooks #23114

Closed
Andarist opened this issue Jan 14, 2022 · 3 comments
Closed

[DevTools]: Confusing "Why did this render?" with hooks #23114

Andarist opened this issue Jan 14, 2022 · 3 comments
Labels
Component: Developer Tools Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug

Comments

@Andarist
Copy link
Contributor

Website or app

https://codesandbox.io/s/elegant-paper-5lhxd?file=/src/App.js

Repro steps

  1. visit https://5lhxd.csb.app/
  2. start recording profile
  3. click a button (to update the context value)
  4. check the report:

Screenshot 2022-01-15 at 00 14 52

Problem

The list of hooks that were changed is correct. However, this list is not really the reason why this component has been rendered. The only thing that changed and led to this rerender is the context value.

I think the list of changed hooks is useful but this should be listed separately. For the "Why did this render?" only context and state (and maybe useSyncExternalStore snapshots) should be listed. As only those actually cause rerenders.

On a separate note - it's a bummer that contexts are not counted within the changed hooks list and the only report we get is that "context has changed". If I use multiple contexts in a component this information is often not enough because I can't easily check which context has been updated.

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

@Andarist Andarist added Component: Developer Tools Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Type: Bug labels Jan 14, 2022
@eps1lon
Copy link
Collaborator

eps1lon commented Jan 15, 2022

If I use multiple contexts in a component this information is often not enough because I can't easily check which context has been updated.

This would be a nice separate feature request. Since we have display names for context we could leverage that to separate them.

I think the separation between context and hooks is technical because hook changes are only tracked for stateful hooks. For useContext the state lives in the actual Context not the hook.

@Andarist
Copy link
Contributor Author

This would be a nice separate feature request. Since we have display names for context we could leverage that to separate them.

Agreed. I was creating this issue late, before hitting the bed and I got lazy 😉 Gonna try to create an issue about this sometime later.

I think the separation between context and hooks is technical because hook changes are only tracked for stateful hooks. For useContext the state lives in the actual Context not the hook.

Yep, I understand the technical context here - but there is still room for improvement from the UX PoV.

@eps1lon
Copy link
Collaborator

eps1lon commented Apr 29, 2022

Fixed in #24189 which is live in 4.24.3

@eps1lon eps1lon closed this as completed Apr 29, 2022
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

No branches or pull requests

3 participants
@Andarist @eps1lon and others