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 Owner
Current Issue Owner: @mallenexpensify
Problem
OnyxUtils.get()— imported from the internal deep pathreact-native-onyx/dist/OnyxUtils— is not a sanctioned way to read Onyx data. The only two supported read APIs areuseOnyx()(render path) andOnyx.connectWithoutView()(non-render logic). Reaching intoreact-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.tsdoesimport type OnyxUtils from 'react-native-onyx/dist/OnyxUtils'and referencesOnyxUtils.METHODas 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 ano-restricted-importsentry withallowTypeImports: true:Notes for the implementer:
no-restricted-importsis already configured, merge this path into the existing entry rather than overriding it.OnyxUtilsmembers but ban.get), a custom rule ineslint-plugin-local-rulesusingno-restricted-syntax-style selectors is an alternative — but the import-path ban above is sufficient given.getis 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-seatbeltbaseline and the baseline entries removed as each file is fixed.)Acceptance criteria
react-native-onyx/dist/OnyxUtilsat runtime fails lint with a helpful message pointing touseOnyx/connectWithoutView.import typeofOnyxUtilsstill passes (sosrc/types/onyx/Request.tsis unaffected).npm run lintpasses onmainonce the four removal issues are merged.Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @mallenexpensify