Skip to content

Disallow manual memoization #104514

Closed
Closed

Description

@roryabraham

Slack: https://expensify.slack.com/archives/C01GTK53T8Q/p1792522792041069

Proposal: Disallow manual memoization in components that compile with React Compiler.

Background

React Compiler has been in place years now, and it memoizes React components and hooks, injecting React.memo, useMemo, and useCallback automatically at compile time. The memoization performed by React Compiler is generally more robust than manual memoization:

  • Mistakes in dependency arrays are not possible
  • It's often more granular than memoization we'd be likely to write by hand

We have existing CI checks that enforce that:

  • All new components compile with React Compiler
  • Any existing components cannot regress (i.e: if they compile on main, then a PR can't break them)

We've also completed several broad migrations where we refactor batches of components to:

  • Remove Rules of React violations such that they compile with React Compiler
  • Remove all manual memoization

So far, none of these migrations have caused any regressions.

Problem

When we write React code and use the React Compiler, if we include manual memoization, then the code becomes more complex for no gain, and in fact less-efficient memoization or mistakes in dependency arrays become possible.

Solution

Disallow the use of React.memo, useMemo, and useCallback in any components that compile with React Compiler. Specifically, we can enforce this with a custom lint rule: we already have the React Compiler plugged into our lint pipeline, such that different rules can apply for components that compile vs components that don't.

Once the rules are in place, we can also remove https://github.com/Expensify/App/blob/8ee46d39e1383fc7520a77c14782349e5b8a5fc5/.claude/skills/app-coding-standards/rules/clean-react-0-compiler.md, because it will be redundant against the deterministic check.

Note: There is one exception that should be allowed: useFocusEffect produces a warning if the callback isn't explicitly wrapped with useCallback, so we'll allow useCallback in that case.

Activity

  1. self-assigned this
    on Oct 20, 2026
  2. roryabraham commented on Oct 21, 2026

    @roryabraham
    ContributorAuthor
  3. roryabraham commented on Oct 23, 2026

    @roryabraham
    ContributorAuthor

    @truph01 is going to help with C+ review and manual testing, on top of the full regression run being performed by Applause

  4. truph01 commented on Oct 27, 2026

    @truph01
    Contributor

    @roryabraham Actually, the PR was merged without requiring a C+ review.

  5. roryabraham commented on Oct 27, 2026

    @roryabraham
    ContributorAuthor

    Going to leave this open at least until the PR deploys to prod

  6. melvin-bot commented on Oct 27, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  7. melvin-bot commented on Oct 28, 2026

    @melvin-bot

    ⚠️ Looks like this issue was linked to a Deploy Blocker here

    If you are the assigned CME please investigate whether the linked PR caused a regression and leave a comment with the results.

    If a regression has occurred and you are the assigned CM follow the instructions here.

    If this regression could have been avoided please consider also proposing a recommendation to the PR checklist so that we can avoid it in the future.

  8. melvin-bot commented on Oct 29, 2026

    @melvin-bot

    @roryabraham

    The solution for this issue has been 🚀 deployed to production 🚀 in version 9.5.24-8 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

  9. roryabraham commented on Oct 29, 2026

    @roryabraham
    ContributorAuthor

    done, no payments due

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions