-
Notifications
You must be signed in to change notification settings - Fork 50.2k
[compiler] Fixes to enableTreatRefLikeIdentifiersAsRefs #34000
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
|
|
||
| ## Input | ||
|
|
||
| ```javascript | ||
| // @flow @enableTreatRefLikeIdentifiersAsRefs @validateRefAccessDuringRender | ||
| import {makeObject_Primitives} from 'shared-runtime'; | ||
|
|
||
| component Example() { | ||
| const fooRef = makeObject_Primitives(); | ||
| fooRef.current = true; | ||
|
|
||
| return <Stringify foo={fooRef} />; | ||
| } | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| ## Error | ||
|
|
||
| ``` | ||
| Found 1 error: | ||
|
|
||
| Error: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) | ||
|
|
||
| 4 | component Example() { | ||
| 5 | const fooRef = makeObject_Primitives(); | ||
| > 6 | fooRef.current = true; | ||
| | ^^^^^^^^^^^^^^ Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) | ||
| 7 | | ||
| 8 | return <Stringify foo={fooRef} />; | ||
| 9 | } | ||
| ``` | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // @flow @enableTreatRefLikeIdentifiersAsRefs @validateRefAccessDuringRender | ||
| import {makeObject_Primitives} from 'shared-runtime'; | ||
|
|
||
| component Example() { | ||
| const fooRef = makeObject_Primitives(); | ||
| fooRef.current = true; | ||
|
|
||
| return <Stringify foo={fooRef} />; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ function Foo() { | |
|
|
||
| const onClick = useCallback(() => { | ||
| ref.current?.click(); | ||
| }, []); | ||
| }, [ref]); | ||
|
Member
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. out of curiosity what was this for?
Member
Author
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. same as below, the ref could change over time |
||
|
|
||
| return <button onClick={onClick} />; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ function Foo() { | |
|
|
||
| const onClick = useCallback(() => { | ||
| customRef.current?.click(); | ||
| }, []); | ||
| }, [customRef]); | ||
|
|
||
| return <button onClick={onClick} />; | ||
| } | ||
|
|
@@ -47,24 +47,26 @@ function useCustomRef() { | |
| function _temp() {} | ||
|
|
||
| function Foo() { | ||
| const $ = _c(2); | ||
| const $ = _c(4); | ||
| const customRef = useCustomRef(); | ||
| let t0; | ||
| if ($[0] === Symbol.for("react.memo_cache_sentinel")) { | ||
| if ($[0] !== customRef) { | ||
|
Member
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. I get that this is functionally equivalent since the box identity never changes, but shouldn't refs be ignored as dependencies for memo blocks?
Member
Author
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 don't know that |
||
| t0 = () => { | ||
| customRef.current?.click(); | ||
| }; | ||
| $[0] = t0; | ||
| $[0] = customRef; | ||
| $[1] = t0; | ||
| } else { | ||
| t0 = $[0]; | ||
| t0 = $[1]; | ||
| } | ||
| const onClick = t0; | ||
| let t1; | ||
| if ($[1] === Symbol.for("react.memo_cache_sentinel")) { | ||
| if ($[2] !== onClick) { | ||
| t1 = <button onClick={onClick} />; | ||
| $[1] = t1; | ||
| $[2] = onClick; | ||
| $[3] = t1; | ||
| } else { | ||
| t1 = $[1]; | ||
| t1 = $[3]; | ||
| } | ||
| return t1; | ||
| } | ||
|
|
||
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.
Without this i got errors trying to resolve properties, because we have a shape id defined for reanimated but no shape definition. I'm not sure how we didn't run into that error before but it seems like it easily could have occurred.
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.
Note that the error was an invariant which i don't think we report in eslint, so the compiler may have just been silently failing for folks using reanimated