Skip to content
New issue

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

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

Already on GitHub? # to your account

Bug: Devtools does not correctly identify context change for functional component #22737

Closed
KamranAsif opened this issue Nov 10, 2021 · 2 comments
Assignees
Labels
Component: Developer Tools Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@KamranAsif
Copy link

KamranAsif commented Nov 10, 2021

React version: 17.0.2
Devtools version: 4.21.0.1 (FB build)

Steps To Reproduce

  1. Open sandbox (source)
  2. Start profiling with 'Record why each component rendered while profiling' enabled.
  3. Click the page a few times to force renders.
  4. Stop profiling and view 'Why did this render?' panel

Link to code example:

https://codesandbox.io/s/react-playground-forked-lke58

The current behavior

The profiler says the component rendered because the parent component rendered. This is incorrect, as the parent component is a MemoComponent that did in fact not render.

image

The expected behavior

The component actually rendered because its context was changed. When digging into the devtools code, we are checking the memoizedValue value on the context, which doesn't seem to exist.

while (prevContext && nextContext) {
  if (!is(prevContext.memoizedValue, nextContext.memoizedValue)) {
    return true;
  }

  prevContext = prevContext.next;
  nextContext = nextContext.next;
}

image

I couldn't find the actual value on the context property; or in the memoizedState.

@KamranAsif KamranAsif added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Nov 10, 2021
@bvaughn bvaughn self-assigned this Nov 10, 2021
@KamranAsif
Copy link
Author

Fixed codesandbox link

@bvaughn
Copy link
Contributor

bvaughn commented Nov 11, 2021

PR #22746 fixes this issue for newer versions of React (e.g. 18 alpha) but older versions will remain broken because there's not a good way to read the most recent context value for a Fiber after render has completed. This is because React maintains a stack of context values during render, but by the time DevTools is called– render has finished and the stack is empty.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Component: Developer Tools Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

2 participants