react / react/react

[Compiler Bug]: Using useMemo with an sync function should not be reported, or should be able to be configured

Open
#34,931 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: React Compiler Status: Unconfirmed Type: Bug
Dominant language
JavaScript
Stars
251k
Forks
51.4k
Avg merge
2d 4h
Merged PRs (30d)
53

Description

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/#N4Igzg9grgTgxgUxALhAgHgBwjALgAgBMEAzAQygBsCSoA7OXASwjvwFkBPAQU0wAoAlPmAAdNvjiswBTDAgBbJmAT4AvPigr2CBRH5kwnBviHqAfCPwwEuWGwBMAbnwBfADT4A2gF1B4-ElpAgA3MkooVQ0tBH45RWUEQScA61t7fAAeQiYQ8wAJBEpKCHwAdRxKQkyAehy8lLpXcRB3ECk6EiYAcxQQJgVsPHxcTkxVYHwABQjupjoAeUxmaTd8EnkFfAByACMyXaKAWkxZ+aObMkYjqUGmSgQYOuVcbcbxfjEJGprbzHuyCs6OwIMRkPhRCBwpRIeJXPgwIDlF0EGBpmdFssWHQwMlWuAABYQADuAEk6LhHnRwmAUORKCpXEA

Repro steps

I got the issue when running the react hooks plugin that seems to use the babel plugin under the hood now.

The issue is here:
https://github.com/facebook/react/blame/ea0c17b0952e2b866a1f0dd4b5ac28c7df9d8518/compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateUseMemo.ts#L110-L123

It seems to be new with latest version of the eslint plugin (v7), but not sure why without a proper changelog.

IMO an async function is just a function returning a promise, and there's no reason a promise isn't a valid value to be memoized.

How often does this bug happen?

Every time

What version of React are you using?

19.2

What version of React Compiler are you using?

none

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the warning using the linked React Playground example, then inspect compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateUseMemo.ts at lines 110-123. Determine whether async functions should be accepted by useMemo or whether this behavior needs configuration, and verify that the chosen behavior is covered by the relevant compiler or plugin tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript, react
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.