Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
```


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} />;
}