Skip to content

Conversation

@everettbu
Copy link

@everettbu everettbu commented Dec 13, 2025

Mirror of facebook/react#35318
Original author: ArnaudBarre


Summary

Fixes vitejs/vite-plugin-react#1006

I'm not sure a lot of users do nest hooks at the second level, but the added complexity to the Babel plugin fells low enough to add support to it.

Before this change, the signature for the test would have been _s(App, "useNestedThing{foo}", true) which would force reset on HMR.

@greptile-apps
Copy link

greptile-apps bot commented Dec 13, 2025

Greptile Overview

Greptile Summary

Extended Fast Refresh to support hook calls on nested member expressions like module.property.useHook(). Previously, this pattern would generate an incorrect signature causing unnecessary component resets on HMR.

Key changes:

  • Extended createArgumentsForSignature to check two levels deep in member expressions
  • Added conditional to extract binding name from callee.object.object when it's an Identifier
  • Test case validates the signature correctly tracks FancyHook.property.useNestedThing() as "useNestedThing{foo}" with proper binding tracking

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is minimal, well-tested, and follows existing patterns. The logic correctly handles nested member expressions without breaking existing functionality. Test coverage is comprehensive with snapshot validation.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
packages/react-refresh/src/ReactFreshBabelPlugin.js 5/5 Added support for nested member expression hook calls (module.property.useHook()) by checking two levels deep in the AST
packages/react-refresh/src/tests/ReactFreshBabelPlugin-test.js 5/5 Added test case for nested hook calls using FancyHook.property.useNestedThing() pattern
packages/react-refresh/src/tests/snapshots/ReactFreshBabelPlugin-test.js.snap 5/5 Snapshot correctly shows the transformed output with proper signature tracking for nested hook call

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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.

hooks inside deeply nested objects always cause state reset

3 participants