-
Notifications
You must be signed in to change notification settings - Fork 45.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compiler: fix accidental propagation of function effects from StartMemoize/FinishMemoize #29154
Conversation
…moize/FinishMemoize By default, React Compiler will skip compilation if it cannot preserve existing memoization. Ie, if the code has an existing `useMemo()` or `useCallback()` and the compiler cannot determine that it is safe to keep that memoization — or do even better — then we'll leave the code alone. The actual compilation doesn't use any hints from existing memo calls, this is purely to check and avoid regressing any specific memoization that developers may have already applied. However, we were accidentally reporting some false-positive _validation_ errors due to the StartMemoize and FinishMemoize instructions that we emit to track where the memoization was in the source code. This is now fixed. Fixes #29131 Fixes #29132 [ghstack-poisoned]
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
…moize/FinishMemoize By default, React Compiler will skip compilation if it cannot preserve existing memoization. Ie, if the code has an existing `useMemo()` or `useCallback()` and the compiler cannot determine that it is safe to keep that memoization — or do even better — then we'll leave the code alone. The actual compilation doesn't use any hints from existing memo calls, this is purely to check and avoid regressing any specific memoization that developers may have already applied. However, we were accidentally reporting some false-positive _validation_ errors due to the StartMemoize and FinishMemoize instructions that we emit to track where the memoization was in the source code. This is now fixed. Fixes #29131 Fixes #29132 ghstack-source-id: 9f6b8dbc5074ccc96e6073cf11c4920b5375faf6 Pull Request resolved: #29154
Comparing: 1d6eebf...8210d3b Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tricky! If I understand it right, the issue is that we see a StartMemo instruction containing dependency values as triggering the effects of those dependencies to fire, similarly to if we'd passed them as args or propagated them somewhere else, is that right? But StartMemoize is a "virtual" instruction that doesn't correspond to any emitted code, so it shouldn't fire any such effects.
If we end up adding any further virtual instructions, will need to be careful not to repeat this issue!
…moize/FinishMemoize By default, React Compiler will skip compilation if it cannot preserve existing memoization. Ie, if the code has an existing `useMemo()` or `useCallback()` and the compiler cannot determine that it is safe to keep that memoization — or do even better — then we'll leave the code alone. The actual compilation doesn't use any hints from existing memo calls, this is purely to check and avoid regressing any specific memoization that developers may have already applied. However, we were accidentally reporting some false-positive _validation_ errors due to the StartMemoize and FinishMemoize instructions that we emit to track where the memoization was in the source code. This is now fixed. Fixes #29131 Fixes #29132 ghstack-source-id: 9f6b8dbc5074ccc96e6073cf11c4920b5375faf6 Pull Request resolved: #29154
Stack from ghstack (oldest at bottom):
By default, React Compiler will skip compilation if it cannot preserve existing memoization. Ie, if the code has an existing
useMemo()
oruseCallback()
and the compiler cannot determine that it is safe to keep that memoization — or do even better — then we'll leave the code alone. The actual compilation doesn't use any hints from existing memo calls, this is purely to check and avoid regressing any specific memoization that developers may have already applied.However, we were accidentally reporting some false-positive validation errors due to the StartMemoize and FinishMemoize instructions that we emit to track where the memoization was in the source code. This is now fixed.
Fixes #29131
Fixes #29132