-
Notifications
You must be signed in to change notification settings - Fork 47.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler] Fixture to demonstrate issue with returning object contain…
…ing ref Summary: We currently can return a ref from a hook but not an object containing a ref. ghstack-source-id: 8b1de4991eb2731b7f758e685ba62d9f07d584b2 Pull Request resolved: #30820
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...r/src/__tests__/fixtures/compiler/error.return-ref-callback-structure.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,45 @@ | ||
|
||
## Input | ||
|
||
```javascript | ||
// @flow @validateRefAccessDuringRender @validatePreserveExistingMemoizationGuarantees | ||
|
||
import {useRef} from 'react'; | ||
|
||
component Foo(cond: boolean, cond2: boolean) { | ||
const ref = useRef(); | ||
|
||
const s = () => { | ||
return ref.current; | ||
}; | ||
|
||
if (cond) return [s]; | ||
else if (cond2) return {s}; | ||
else return {s: [s]}; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{cond: false, cond2: false}], | ||
}; | ||
|
||
``` | ||
|
||
|
||
## Error | ||
|
||
``` | ||
10 | }; | ||
11 | | ||
> 12 | if (cond) return [s]; | ||
| ^ InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (12:12) | ||
InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (13:13) | ||
InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef) (14:14) | ||
13 | else if (cond2) return {s}; | ||
14 | else return {s: [s]}; | ||
15 | } | ||
``` | ||
20 changes: 20 additions & 0 deletions
20
...gin-react-compiler/src/__tests__/fixtures/compiler/error.return-ref-callback-structure.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,20 @@ | ||
// @flow @validateRefAccessDuringRender @validatePreserveExistingMemoizationGuarantees | ||
|
||
import {useRef} from 'react'; | ||
|
||
component Foo(cond: boolean, cond2: boolean) { | ||
const ref = useRef(); | ||
|
||
const s = () => { | ||
return ref.current; | ||
}; | ||
|
||
if (cond) return [s]; | ||
else if (cond2) return {s}; | ||
else return {s: [s]}; | ||
} | ||
|
||
export const FIXTURE_ENTRYPOINT = { | ||
fn: Foo, | ||
params: [{cond: false, cond2: false}], | ||
}; |