Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ function* generateInstructionTypes(
shapeId: BuiltInArrayId,
});
} else {
break;
continue;
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

## Input

```javascript
function Component(props) {
// Intentionally don't bind state, this repros a bug where we didn't
// infer the type of destructured properties after a hole in the array
let [, setState] = useState();
setState(1);
return props.foo;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: ['TodoAdd'],
isComponent: 'TodoAdd',
};

```


## Error

```
Found 1 error:

Error: Calling setState during render may trigger an infinite loop

Calling setState during render will trigger another render, and can lead to infinite loops. (https://react.dev/reference/react/useState).

error.invalid-setState-in-render-unbound-state.ts:5:2
3 | // infer the type of destructured properties after a hole in the array
4 | let [, setState] = useState();
> 5 | setState(1);
| ^^^^^^^^ Found setState() in render
6 | return props.foo;
7 | }
8 |
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Component(props) {
// Intentionally don't bind state, this repros a bug where we didn't
// infer the type of destructured properties after a hole in the array
let [, setState] = useState();
setState(1);
return props.foo;
}

export const FIXTURE_ENTRYPOINT = {
fn: Component,
params: ['TodoAdd'],
isComponent: 'TodoAdd',
};

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

## Input

```javascript
// @validatePreserveExistingMemoizationGuarantees
import {useCallback, useTransition} from 'react';

function useFoo() {
const [, /* isPending intentionally not captured */ start] = useTransition();

return useCallback(() => {
start();
}, []);
}

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

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
import { useCallback, useTransition } from "react";

function useFoo() {
const $ = _c(1);
const [, start] = useTransition();
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => {
start();
};
$[0] = t0;
} else {
t0 = $[0];
}
return t0;
}

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

```

### Eval output
(kind: ok) "[[ function params=0 ]]"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @validatePreserveExistingMemoizationGuarantees
import {useCallback, useTransition} from 'react';

function useFoo() {
const [, /* isPending intentionally not captured */ start] = useTransition();

return useCallback(() => {
start();
}, []);
}

export const FIXTURE_ENTRYPOINT = {
fn: useFoo,
params: [],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

## Input

```javascript
// @validatePreserveExistingMemoizationGuarantees
import {useCallback, useTransition} from 'react';

function useFoo() {
const [, /* state value intentionally not captured */ setState] = useState();

return useCallback(() => {
setState(x => x + 1);
}, []);
}

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

```

## Code

```javascript
import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
import { useCallback, useTransition } from "react";

function useFoo() {
const $ = _c(1);
const [, setState] = useState();
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = () => {
setState(_temp);
};
$[0] = t0;
} else {
t0 = $[0];
}
return t0;
}
function _temp(x) {
return x + 1;
}

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

```

### Eval output
(kind: exception) useState is not defined
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @validatePreserveExistingMemoizationGuarantees
import {useCallback, useTransition} from 'react';

function useFoo() {
const [, /* state value intentionally not captured */ setState] = useState();

return useCallback(() => {
setState(x => x + 1);
}, []);
}

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