Skip to content
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] Fixture to show ref-in-render enforcement issue with useCallback #30714

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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,41 @@

## Input

```javascript
// @flow @validateRefAccessDuringRender @validatePreserveExistingMemoizationGuarantees

component Foo() {
const ref = useRef();

const s = useCallback(() => {
return ref.current;
});

return <a r={s} />;
}

export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [],
};

```


## Error

```
4 | const ref = useRef();
5 |
> 6 | const s = useCallback(() => {
| ^^^^^^^
> 7 | return ref.current;
| ^^^^^^^^^^^^^^^^^^^^^^^
> 8 | });
| ^^^^ InvalidReact: Ref values (the `current` property) may not be accessed during render. (https://react.dev/reference/react/useRef). Cannot access ref value at read $27:TObject<BuiltInFunction> (6:8)
9 |
10 | return <a r={s} />;
11 | }
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @flow @validateRefAccessDuringRender @validatePreserveExistingMemoizationGuarantees

component Foo() {
const ref = useRef();

const s = useCallback(() => {
return ref.current;
});

return <a r={s} />;
}

export const FIXTURE_ENTRYPOINT = {
fn: Foo,
params: [],
};