React Compiler doesn't memoize class instances or their dependents without explicit useMemo #80
Unanswered
thisStorageIsMine
asked this question in
General Questions
Replies: 0 comments
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