Skip to content

[Compiler Bug]: react-hooks/set-state-in-effect false positive on async function #34905

@printfn

Description

@printfn

What kind of issue is this?

  • React Compiler core (the JS output is incorrect, or your app works incorrectly after optimization)
  • babel-plugin-react-compiler (build issue installing or using the Babel plugin)
  • eslint-plugin-react-compiler (build issue installing or using the eslint plugin)
  • react-compiler-healthcheck (build issue installing or using the healthcheck script)

Link to repro

https://playground.react.dev/#N4Igzg9grgTgxgUxALhAgHgBwjALgAgDMoA7OXASwhPwGEIBbbEhE3ACgEp9gAdG-HGpgCAbRgIAhgBMAngBp8YBLgBKUuQF18AXnxRlAZVyTcCdoUkAbZZwDc-fIOEFCu-ctrWrAI0lwAa3ZJMFkyfC5dAD4eRyd8SQB3SQpXFTgAC3YAcgA6fOz7OKdlNQ1ZdlwYKAQigQBfRVFNOriDBABRQkIEcnZInRi+ASdCLgcGpsIWibiJXFgaAB5pCgA3KOAJGVl8AH58bPUd7PxkQ4AZCBkKEgBzbPqlgHpVjYn6-hB5ECESQgodxQIAoTBwBFwskwCB4+AAClYoHdbgB5TCUYT4epEGCMQ5+HwIKwAWkwiORJGJ23IxKETAoVgQMFeFBE2VmJHYwycz2edMwDNMVBIAFkINIEOdeCBvNL+NiwEKwACEGB4eTUejhWB7N9wBkIIkAJJsJkkaxgFCWGwIepAA

Repro steps

export function Component() {
  const [ready, setReady] = useState(false);
  const f = useCallback(async () => {
    await fetch('...');
    setReady(true);
  }, []);

  useEffect(() => {
    f();
  }, [f]);

  return <div>{ready ? 'Ready' : 'Loading'}</div>;
}

The setState call is after an await, so it should not trigger the lint.

How often does this bug happen?

Every time

What version of React are you using?

19.2.0

What version of React Compiler are you using?

1.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bugType: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions