mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Repro for false positive in validatePreserveMemoization on non-escaping value
This demonstrates a false positive in validatePreserveExistingManualMemoization. We prune memoization of non-escaping values, but the validation pass just sees that the value "should" have a scope and that scope doesn't exist, and thinks we failed to preserve memoization.
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @validatePreserveExistingMemoizationGuarantees @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
|
||||
function Component({ entity, children }) {
|
||||
// showMessage doesn't escape so we don't memoize it.
|
||||
// However, validatePreserveExistingMemoizationGuarantees only sees that the scope
|
||||
// doesn't exist, and thinks the memoization was missed instead of being intentionally dropped.
|
||||
const showMessage = useCallback(() => entity != null);
|
||||
|
||||
if (!showMessage) {
|
||||
return children;
|
||||
}
|
||||
|
||||
return <Message>{children}</Message>;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
```
|
||||
[ReactForget] InvalidReact: This value was manually memoized, but cannot be memoized under Forget because it may be mutated after it is memoized (6:6)
|
||||
```
|
||||
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// @validatePreserveExistingMemoizationGuarantees @enableAssumeHooksFollowRulesOfReact @enableTransitivelyFreezeFunctionExpressions
|
||||
function Component({ entity, children }) {
|
||||
// showMessage doesn't escape so we don't memoize it.
|
||||
// However, validatePreserveExistingMemoizationGuarantees only sees that the scope
|
||||
// doesn't exist, and thinks the memoization was missed instead of being intentionally dropped.
|
||||
const showMessage = useCallback(() => entity != null);
|
||||
|
||||
if (!showMessage) {
|
||||
return children;
|
||||
}
|
||||
|
||||
return <Message>{children}</Message>;
|
||||
}
|
||||
Reference in New Issue
Block a user