Repository navigation
Conversation
… descriptions When "Record why each component rendered while profiling" is enabled, getChangeDescription() called inspectHooks() for every function-like Fiber, including MemoComponent. A MemoComponent Fiber (the outer Fiber of memo(forwardRef(...)) or memo(Component, areEqual)) doesn't own hooks, so react-debug-tools threw "Unknown Fiber. Needs to be a function component to inspect hooks." and the commit failed to be recorded. Only inspect hooks for FunctionComponent, SimpleMemoComponent and ForwardRef, matching the usesHooks check in inspectElementRaw(). Fixes react#37733
|
Hi @alpakts! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
The build for this commit did not complete, so there is no size report. See the workflow run for details. Generated by sizebot against e0519ee |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
Fixes #37733.
When "Record why each component rendered while profiling" is enabled,
getChangeDescription()callsinspectHooks()for every function-like Fiber, includingMemoComponent. AMemoComponentFiber (the outer Fiber ofmemo(forwardRef(...))ormemo(Component, areEqual)) doesn't own hooks, soreact-debug-toolsthrows:and the commit fails to be recorded by the Profiler.
This looks like a regression from #35123, which moved changed-hook detection to
inspectHooks().The fix only inspects hooks for
FunctionComponent,SimpleMemoComponentandForwardRef, matching theusesHookscheck ininspectElementRaw(). For other tagshooksisnull. The inner Fiber that actually owns the hooks still gets its own change description, so no information is lost.How did you test this change?
Added two tests to
packages/react-devtools-shared/src/__tests__/profilerChangeDescriptions-test.js:memo(forwardRef(...))re-rendering with changed props (the shape from the issue)memo(Component, areEqual)re-rendering with changed propsWithout the fix, both fail with the same error and stack as the issue (
recordProfilingDurations→getChangeDescription→inspectHooks). With the fix:Also ran:
yarn test --build --project devtools) with and without this change: the set of failing tests is identical (pre-existing failures in my local Windows setup, e.g. legacy-mode tests), so no new failures.yarn prettierandyarn linc: clean.yarn flow dom-browser(the renderer config that coversreact-devtools-shared): no errors.