[compiler] Add experimental structured hooks lowering prototype#36305
Open
luckysolanki902 wants to merge 3 commits intofacebook:mainfrom
Open
[compiler] Add experimental structured hooks lowering prototype#36305luckysolanki902 wants to merge 3 commits intofacebook:mainfrom
luckysolanki902 wants to merge 3 commits intofacebook:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
enableEmitStructuredHookscompiler flag and'use structured hooks'directive pathuseState()/useMemo()calls intoexperimental_useStructuredHooks(...)@targetpragmas actually control runtime-module selectionWhy
This explores a different runtime representation for hook identity.
Today, the Rules of Hooks are enforced by a cursor-based hook model where state is identified by call order. This experiment asks whether a compiler can carve out a narrow opt-in subset where hook identity is instead assigned explicitly with stable keys.
The branch stays intentionally small:
enableEmitStructuredHooks'use structured hooks'useState()and inlineuseMemo()with literal dependency arraysThat keeps the claim tight: this does not pretend arbitrary conditional hooks are solved. It demonstrates a concrete lowering seam where branch-local hook state can survive disappear/reappear cycles while still collapsing to one real top-level hook call.
Validation
yarn workspace react-compiler-runtime testyarn workspace babel-plugin-react-compiler run jest parseConfigPragma-test.ts structuredHooksTransform-test.tsyarn workspace babel-plugin-react-compiler lintyarn workspace babel-plugin-react-compiler test