-
Notifications
You must be signed in to change notification settings - Fork 47.7k
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] Exclude refs and ref values from having mutable ranges #30713
Changes from 2 commits
dd7fbe4
bc1655d
886f215
ca429de
23625a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
## Input | ||
|
||
```javascript | ||
// @enablePreserveExistingMemoizationGuarantees | ||
// @enablePreserveExistingMemoizationGuarantees @validateRefAccessDuringRender | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're going to need to enable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah i see you did this later in the stack, sweet |
||
import {useCallback, useRef} from 'react'; | ||
|
||
function Component(props) { | ||
|
@@ -42,7 +42,9 @@ export const FIXTURE_ENTRYPOINT = { | |
> 10 | ref.current.inner = event.target.value; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
> 11 | }); | ||
| ^^^^ CannotPreserveMemoization: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This value was memoized in source but not in compilation output. (7:11) | ||
| ^^^^ InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef). Cannot access ref value at freeze $44:TObject<BuiltInFunction> (7:11) | ||
|
||
InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (14:14) | ||
12 | | ||
13 | // The ref is modified later, extending its range and preventing memoization of onChange | ||
14 | ref.current.inner = null; | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @validatePreserveExistingMemoizationGuarantees:true | ||
|
||
import {useRef, useMemo} from 'react'; | ||
import {makeArray} from 'shared-runtime'; | ||
|
||
function useFoo() { | ||
const r = useRef(); | ||
return useMemo(() => makeArray(r), []); | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
## Code | ||
|
||
```javascript | ||
import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees:true | ||
|
||
import { useRef, useMemo } from "react"; | ||
import { makeArray } from "shared-runtime"; | ||
|
||
function useFoo() { | ||
const $ = _c(1); | ||
const r = useRef(); | ||
let t0; | ||
let t1; | ||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
t1 = makeArray(r); | ||
$[0] = t1; | ||
} else { | ||
t1 = $[0]; | ||
} | ||
t0 = t1; | ||
return t0; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: useFoo, | ||
params: [], | ||
}; | ||
|
||
``` | ||
|
||
### Eval output | ||
(kind: ok) [{}] |
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.
maybe add a helper for this combination?