Skip to content

[Due for payment 2026-09-22] Add ESLint rule to disallow OnyxUtils.get() / react-native-onyx/dist/OnyxUtils runtime imports #98610

Description

@tgolen

Problem

OnyxUtils.get() — imported from the internal deep path react-native-onyx/dist/OnyxUtils — is not a sanctioned way to read Onyx data. The only two supported read APIs are useOnyx() (render path) and Onyx.connectWithoutView() (non-render logic). Reaching into react-native-onyx/dist/* bypasses the public API and couples us to Onyx internals.

Once the existing runtime usages are removed (see the linked issues below), we should add an ESLint rule so it can't be reintroduced in /App.

Scope of the ban

The rule should disallow the runtime import/use of react-native-onyx/dist/OnyxUtils.

Important: there is a legitimate type-only usage that must keep working — src/types/onyx/Request.ts does import type OnyxUtils from 'react-native-onyx/dist/OnyxUtils' and references OnyxUtils.METHOD as a type. The rule must therefore allow type imports.

Suggested implementation

The project uses flat config (eslint.config.mjs) and has a local-rules plugin (eslint-plugin-local-rules). The simplest approach is a no-restricted-imports entry with allowTypeImports: true:

'no-restricted-imports': ['error', {
    paths: [{
        name: 'react-native-onyx/dist/OnyxUtils',
        message: 'OnyxUtils is not a sanctioned way to read Onyx data. Use useOnyx() in render paths, or a short-lived Onyx.connectWithoutView() for non-render logic.',
        allowTypeImports: true,
    }],
}],

Notes for the implementer:

  • If no-restricted-imports is already configured, merge this path into the existing entry rather than overriding it.
  • If a member-level ban is preferred (e.g. allow other OnyxUtils members but ban .get), a custom rule in eslint-plugin-local-rules using no-restricted-syntax-style selectors is an alternative — but the import-path ban above is sufficient given .get is the only runtime member used today.

Dependency / ordering

This rule should land after the four removal issues, otherwise it will immediately error on existing code. The four call sites to remove first:

(Alternatively, if we want the rule in sooner, it could be added with an eslint-seatbelt baseline and the baseline entries removed as each file is fixed.)

Acceptance criteria

  • Importing/using react-native-onyx/dist/OnyxUtils at runtime fails lint with a helpful message pointing to useOnyx / connectWithoutView.
  • import type of OnyxUtils still passes (so src/types/onyx/Request.ts is unaffected).
  • npm run lint passes on main once the four removal issues are merged.
Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

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

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2ExternalAdded to denote the issue can be worked on by a contributorImprovementItem broken or needs improvement.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions