React Compiler doesn't memoize class instances or their dependents without explicit useMemo #80
Unanswered
thisStorageIsMine
asked this question in
General Questions
Replies: 1 comment
-
|
Hi there! Taking a look at your issue regarding When working with the React Compiler (React Forget), this type of behavior usually stems from how the compiler analyzes hook dependencies and component boundaries. Make sure that:
Hope this helps clarify the expected boundaries! Let me know if you have a minimal repro I can test against. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
React Compiler doesn't memoize:
new Class())This means that a single un-memoized class instance "poisons" the entire dependency chain —
even expressions that could theoretically be safely memoized are skipped.
Reproduction
Playground link (with useMemo):
https://playground.react.dev/#N4Igzg9grgTgxgUxALhAgHgBwjALgAjggDswCBZATwAkIIBrfAXnwAoBKZgPn2AB1i+IYRJl8kALYIAwgBsAhmDABJUrnnFEzfFDAJyCCRFYdu+YggDu+OYrAcANPgDaAXXYDhIteIm4AFtqSMgpKqmQaiAB0AGZ0rOgegsIwCLiwgmB+-gIAvgDcIA4gRMQxAJYA5igg5RLYePi4lJgIvPgACrJQleXEAPKYuOWi+Ln4MTAQEvgA5ABG8vMIsgC0mN29xKup8nC4q0T15bIIMAD0ACblZLP5AgKs-Mnn50eYJ-LDJOQQlwjIfB8EDyWSyYF5cRfG4VBBgTqbPqDb6kdiFYpgfwQSyqXBnYigsAoGKEhC5IA
With
useMemo, the compiler memoizes bothsomeClassInstanceandsmthvariables. OnceuseMemois removed, all memoization is gone.Questions
Beta Was this translation helpful? Give feedback.
All reactions