-
Notifications
You must be signed in to change notification settings - Fork 46.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] repro of false positive for ValidatePreserveManualMemo
ghstack-source-id: 235c5bae0828b79db758871006e4c091923ca5fd Pull Request resolved: #30431
- Loading branch information
1 parent
f987f1a
commit c08b516
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
.../preserve-memo-validation/error.false-positive-useMemo-with-refs.flow.expect.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @flow @validatePreserveExistingMemoizationGuarantees | ||
import { identity } from "shared-runtime"; | ||
|
||
component Component( | ||
disableLocalRef, | ||
ref, | ||
) { | ||
const localRef = useFooRef(); | ||
const mergedRef = useMemo(() => { | ||
return disableLocalRef ? ref : identity(ref, localRef); | ||
}, [disableLocalRef, ref, localRef]); | ||
return <div ref={mergedRef} />; | ||
} | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
7 | ) { | ||
8 | const localRef = useFooRef(); | ||
> 9 | const mergedRef = useMemo(() => { | ||
| ^^^^^^^ | ||
> 10 | return disableLocalRef ? ref : identity(ref, localRef); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
> 11 | }, [disableLocalRef, ref, localRef]); | ||
| ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This value may be mutated later, which could cause the value to change unexpectedly (9:11) | ||
12 | return <div ref={mergedRef} />; | ||
13 | } | ||
14 | | ||
``` | ||
13 changes: 13 additions & 0 deletions
13
...fixtures/compiler/preserve-memo-validation/error.false-positive-useMemo-with-refs.flow.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @flow @validatePreserveExistingMemoizationGuarantees | ||
import { identity } from "shared-runtime"; | ||
|
||
component Component( | ||
disableLocalRef, | ||
ref, | ||
) { | ||
const localRef = useFooRef(); | ||
const mergedRef = useMemo(() => { | ||
return disableLocalRef ? ref : identity(ref, localRef); | ||
}, [disableLocalRef, ref, localRef]); | ||
return <div ref={mergedRef} />; | ||
} |