Skip to content

[Due for payment 2026-09-10] Remove OnyxUtils.get() from OnyxDerived init (use connectWithoutView) #98607

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:

  1. useOnyx() — for anything in a component's render path.
  2. Onyx.connectWithoutView() — for non-render logic that genuinely can't use useOnyx.

Reaching into react-native-onyx/dist/* bypasses the public API and couples us to Onyx internals.

This issue covers src/libs/actions/OnyxDerived/index.ts, which contains one OnyxUtils.get(key) call (as of writing, line 46).

Why connectWithoutView (not useOnyx) here

This is module-level init() logic, not a component — useOnyx() is not applicable. The call performs a one-time hydration read of the stored derived value from disk before wiring up the dependency subscriptions. The sanctioned replacement is a short-lived connectWithoutView read: connect, read the first callback value, then Onyx.disconnect(connection).

Because the connection is short-lived (disconnected after the first callback), it will not recursively re-fire when this same code later writes back to the derived key.

Reference implementation of the short-lived pattern already in the codebase: src/libs/migrations/ConvertGpsPointsTo2DArray.ts.

Proposed change

  • Remove the import OnyxUtils from 'react-native-onyx/dist/OnyxUtils'.
  • Replace OnyxUtils.get(key).then((storedDerivedValue) => { ... }) with a short-lived Onyx.connectWithoutView read that resolves the stored value, then continues into the existing setup logic.
  • Keep all downstream behavior (the dependencyValues wiring, connectWithoutView dependency subscriptions, flush/coalesce logic) unchanged.

Acceptance criteria

  • No references to OnyxUtils / react-native-onyx/dist/OnyxUtils remain in this file.
  • The initial derived-value hydration uses Onyx.connectWithoutView (short-lived) via the public Onyx import.
  • Derived values still restore from disk on init and recompute correctly when dependencies change.

Notes

This is one of several issues removing OnyxUtils.get() across the app. A separate issue will add an ESLint rule to prevent it from being reintroduced.

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