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() — for anything in a component's render path.
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 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 are:useOnyx()— for anything in a component's render path.Onyx.connectWithoutView()— for non-render logic that genuinely can't useuseOnyx.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 oneOnyxUtils.get(key)call (as of writing, line 46).Why
connectWithoutView(notuseOnyx) hereThis 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-livedconnectWithoutViewread: connect, read the first callback value, thenOnyx.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
import OnyxUtils from 'react-native-onyx/dist/OnyxUtils'.OnyxUtils.get(key).then((storedDerivedValue) => { ... })with a short-livedOnyx.connectWithoutViewread that resolves the stored value, then continues into the existing setup logic.dependencyValueswiring,connectWithoutViewdependency subscriptions, flush/coalesce logic) unchanged.Acceptance criteria
OnyxUtils/react-native-onyx/dist/OnyxUtilsremain in this file.Onyx.connectWithoutView(short-lived) via the publicOnyximport.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 Owner
Current Issue Owner: @mallenexpensify