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] Add todo fixtures for local reassignment in an async callback #30109

Merged
merged 1 commit into from
Jun 26, 2024
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,58 @@

## Input

```javascript
function Component() {
let value = null;
const reassign = async () => {
await foo().then((result) => {
// Reassigning a local variable in an async function is *always* mutating
// after render, so this should error regardless of where this ends up
// getting called
value = result;
});
};

const onClick = async () => {
await reassign();
};
return <div onClick={onClick}>Click</div>;
}

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime";
function Component() {
const $ = _c(2);
let value;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
value = null;
$[0] = value;
} else {
value = $[0];
}
let t0;
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
const reassign = async () => {
await foo().then((result) => {
value = result;
});
};

const onClick = async () => {
await reassign();
};

t0 = <div onClick={onClick}>Click</div>;
$[1] = t0;
} else {
t0 = $[1];
}
return t0;
}

```

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function Component() {
let value = null;
const reassign = async () => {
await foo().then((result) => {
// Reassigning a local variable in an async function is *always* mutating
// after render, so this should error regardless of where this ends up
// getting called
value = result;
});
};

const onClick = async () => {
await reassign();
};
return <div onClick={onClick}>Click</div>;
}
1 change: 1 addition & 0 deletions compiler/packages/snap/src/SproutTodoFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ const skipFilter = new Set([
"todo.invalid-reassign-local-variable-in-jsx-callback",
"todo.invalid-reassign-local-variable-in-hook-argument",
"todo.invalid-reassign-local-variable-in-effect",
"todo.invalid-reassign-local-variable-in-async-callback",

// bugs
"bug-invalid-hoisting-functionexpr",
Expand Down