Skip to content

[DevTools] Don't inspect hooks of MemoComponent when recording change descriptions - #37798

Open
alpakts wants to merge 1 commit into
react:mainfrom
alpakts:fix/devtools-profiler-memo-hooks
Open

alpakts wants to merge 1 commit into
react:mainfrom
alpakts:fix/devtools-profiler-memo-hooks

Conversation

@alpakts

@alpakts alpakts commented Oct 8, 2026

Copy link
Copy Markdown

Summary

Fixes #37733.

When "Record why each component rendered while profiling" is enabled, getChangeDescription() calls 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 throws:

Unknown Fiber. Needs to be a function component to inspect hooks.

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, SimpleMemoComponent and ForwardRef, matching the usesHooks check in inspectElementRaw(). For other tags hooks is null. 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 props

Without the fix, both fail with the same error and stack as the issue (recordProfilingDurations → getChangeDescription → inspectHooks). With the fix:

yarn build-for-devtools
yarn test --build --project devtools --ci profilerChangeDescriptions
Tests: 3 passed, 3 total

Also ran:

  • The full DevTools suite (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 prettier and yarn linc: clean.
  • yarn flow dom-browser (the renderer config that covers react-devtools-shared): no errors.

… 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
@meta-cla

meta-cla Bot commented Oct 8, 2026

Copy link
Copy Markdown

Hi @alpakts!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

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

@meta-cla

meta-cla Bot commented Oct 8, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed label Oct 8, 2026
@meta-cla

meta-cla Bot commented Oct 8, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

This branch has not been deployed

No deployments
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 Bug]: Profiler crashes for a controlled memo(forwardRef(...)) component when recording render reasons

1 participant