Skip to content

Compiler: NonReactive annotation#35715

Closed
srubin wants to merge 3 commits intofacebook:mainfrom
descriptinc:steve/stable-handler
Closed

Compiler: NonReactive annotation#35715
srubin wants to merge 3 commits intofacebook:mainfrom
descriptinc:steve/stable-handler

Conversation

@srubin
Copy link
Contributor

@srubin srubin commented Feb 6, 2026

Summary

How did you test this change?

Prompt: Looking at @compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/stable-handler/stable-handler-prop-basic.expect.md -- I see
   two potential problems. It looks to me like the onClick that is being passed to <button> will be re-created whenever `value` changes. It also looks
  like `t1` is only capturing the value of `onSubmit` when `value` changes. What we want instead is for `onClick` to never update, and to always
  capture the latest values of `value` and `onSubmit`.
@meta-cla meta-cla bot added the CLA Signed label Feb 6, 2026
@srubin srubin closed this Feb 6, 2026
@josephsavona
Copy link
Member

This isn’t something we plan to support, at least not in the way it’s used in the fixtures. This NonReactive annotation appears intended to let you drop reactivity, like many frameworks notion of “untracked”, which our experience suggests is a footgun.

@srubin
Copy link
Contributor Author

srubin commented Feb 7, 2026

Thanks for the response, and understood! Creating this PR was an accident; It's not something I intended to submit upstream -- it's just something I am experimenting with. Our codebase heavily uses a custom hook based on the useEvent idea, so I'm exploring how React Compiler can simplify some of our use case.

@josephsavona
Copy link
Member

@srubin
Copy link
Contributor Author

srubin commented Feb 7, 2026

I'm aware of that, but my understanding is that it won't work for our use cases. It is only intended to be used within useEffects and doesn't guarantee a stable function reference. So, it won't help with avoiding re-renders of child components, e.g., those caused by passing event handler props to child components or other functions to be used within event handlers of child components.

Do not [...] pass them to other components or Hooks

and

Effect Event functions do not have a stable identity. Their identity intentionally changes on every render.

I'm not familiar with the history of what changed between that original RFC and shipping of the more limited approach in React 19.2. Our codebase has seen a lot of great performance improvements from our implementation of useEvent.

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.

2 participants