Repository navigation
Description
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 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 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-livedOnyx.connectWithoutViewread that resolves the stored value, then continues into the existing setup logic. - Keep all downstream behavior (the
dependencyValueswiring,connectWithoutViewdependency subscriptions, flush/coalesce logic) unchanged.
Acceptance criteria
- No references to
OnyxUtils/react-native-onyx/dist/OnyxUtilsremain in this file. - The initial derived-value hydration uses
Onyx.connectWithoutView(short-lived) via the publicOnyximport. - 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
- Upwork Job URL: https://www.upwork.com/jobs/~022087946412464986788
- Upwork Job ID: 2087946412464986788
- Last Price Increase: 2026-08-13
Activity
melvin-bot commentedon Aug 13, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @Ollyws (
External)melvin-bot commentedon Aug 13, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022087946412464986788
skrohan5016-coder commentedon Aug 13, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
src/libs/actions/OnyxDerived/index.tsperforms a one-time startup read withOnyxUtils.get(key), imported from the internal deep pathreact-native-onyx/dist/OnyxUtils. Runtime code should use the public Onyx API instead, while preserving the current initialization behavior: restore the persisted derived value first, then establish the long-lived dependency subscriptions.What is the root cause of that problem?
OnyxDerived.init()needs a one-shot, non-React read for every derived key. Since this code runs at module startup outside the React lifecycle,useOnyx()is not applicable, and the existing implementation reached intoOnyxUtils.get()as a promise-based shortcut.The important detail is the ordering around that read. The current
.then(...)continuation contains all dependency wiring, so no dependency can complete the initial set and recompute until the persisted derived value has been assigned toderivedValue. Moving those subscriptions outside the hydration callback would introduce a startup race: the first recompute could run withcontext.currentValuestillundefinedand overwrite a valid disk-cached derived value.The replacement must also disconnect after the first callback. Leaving the derived-key connection active would make later writes to that same derived key re-enter the initialization block and install another set of dependency listeners.
What changes do you think we should make in order to solve the problem?
react-native-onyx/dist/OnyxUtilsfromsrc/libs/actions/OnyxDerived/index.ts.OnyxUtils.get(key).then(...)with a short-livedOnyx.connectWithoutView({key, callback})read.Onyx.disconnect(connection)before continuing with initialization.derivedValuerestoration, dependency arrays, long-lived dependency subscriptions, coalescing, clear handling, and self-healing logic—inside that one-shot callback. This preserves the existing hydrate-before-subscribe ordering.src/libs/migrations/ConvertGpsPointsTo2DArray.ts. The default connection reuse behavior is sufficient: disconnecting this returned connection removes this callback without tearing down other consumers of the same key.Conceptually:
What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?
Add focused coverage to the existing OnyxDerived tests for these invariants:
context.currentValue, proving hydration still occurs before dependency-driven recomputation.Onyx.clear()handling, and failed-compute recovery are unchanged.What alternative solutions did you explore? (Optional)
useOnyx(): not usable because this is non-React startup logic.connectWithoutView()subscription: rejected because writes to the derived key could re-run initialization and duplicate listeners.connectWithoutView().tgolen commentedon Aug 17, 2026
@Ollyws Are you OK with that proposal?
nkdengineer commentedon Aug 19, 2026
Proposal
What is the root cause of that problem?
src/libs/actions/OnyxDerived/index.tsrestores the stored derived value withOnyxUtils.get(key), imported from the internal deep pathreact-native-onyx/dist/OnyxUtils. That is not a sanctioned Onyx read API and couples the derived-value engine to Onyx internals.This code is not in a React render path, so
useOnyx()is not applicable. The read happens during module-levelinit()before the dependency subscriptions are established, purely to hydrate the last stored derived value from disk and seedderivedValuebefore recomputes begin. That makes this a non-render, one-shot read, which is exactly the caseOnyx.connectWithoutView()is meant to cover.The subtle requirement is preserving the current bootstrap ordering: restore
storedDerivedValue, then continue into the existing dependency wiring, coalescing, and flush logic unchanged. A short-livedconnectWithoutViewfits that pattern because it can read the first callback value, then immediately disconnect before the latersetDerivedValue()writes occur.What changes do you think we should make in order to solve the problem?
Replace the internal
OnyxUtils.get()hydration read with the same short-livedOnyx.connectWithoutView()pattern already used byConvertGpsPointsTo2DArray.ts.Concretely:
import OnyxUtils from 'react-native-onyx/dist/OnyxUtils'.OnyxUtils.get(key).then((storedDerivedValue) => { ... })with a small promise wrapper aroundOnyx.connectWithoutView:keystoredDerivedValueOnyx.disconnect(connection)init()unchanged: restoringderivedValue, establishing dependency subscriptions, deferring writes until all connections initialize, and preserving the current clear/reset and microtask coalescing behavior.This keeps the behavior the same while moving the initial hydration read onto the public Onyx API.
What alternative solutions did you explore? (Optional)
useOnyx()instead: rejected because this is module-level initialization logic, not a component or hook render path.Ollyws commentedon Aug 19, 2026
@MelvinBot create a draft PR from the proposal outlined in #98607 (comment)
MelvinBot commentedon Aug 19, 2026
🤖 Draft PR created: #99004
I implemented the proposal from this issue — replacing the internal
OnyxUtils.get(key)hydration read insrc/libs/actions/OnyxDerived/index.tswith a short-livedOnyx.connectWithoutViewread (disconnected after the first callback), following theConvertGpsPointsTo2DArray.tspattern.Acceptance criteria:
OnyxUtils/react-native-onyx/dist/OnyxUtilsremain in the file (import removed).Onyx.connectWithoutView(short-lived) via the publicOnyximport.Checks run locally (all pass):
typecheck(tsgo),lint, and the OnyxDerived unit suites —OnyxDerivedTest,OnyxDerivedSelfHealTest,CardFeedErrorsDerivedValueTest(69 tests).Please mark the PR as "Ready for review" when it is ready.
view run
12 remaining items
melvin-bot commentedon Sep 8, 2026
@Ollyws Huh... This is 4 days overdue. Who can take care of this?
melvin-bot commentedon Sep 9, 2026
Triggered auto assignment to @mallenexpensify (
Awaiting Payment)melvin-bot commentedon Sep 9, 2026
Payment Summary
Resolving PRs:
Remove OnyxUtils.get() from OnyxDerived init (use connectWithoutView) #99004
Reviewer: @Ollyws owed $250 via NewDot
BugZero Checklist (@mallenexpensify)
Ollyws commentedon Sep 14, 2026
Not sure the checklist is required here as it was code cleanup but we can possibly add these tests:
melvin-bot commentedon Sep 14, 2026
@mallenexpensify Huh... This is 4 days overdue. Who can take care of this?
mallenexpensify commentedon Sep 14, 2026
Claude posting on behalf of Matt:
$125 to @Ollyws (Contributor+), 50%. One file, 17 changed lines, described by the reviewer himself as code cleanup.
How the amount is reached
Two things I did not treat as reductions. The platform sections are all marked N/A, and there is no formal Contributor+ Checklist on this issue. Neither is a fault here: the change is a code-only cleanup with no UI, and a missing checklist is an absence rather than evidence the work was skipped.
To pay the rules amount:
To pay full:
@Ollyws, flagging this since it proposes less than the standard price.
Claude posting on behalf of Matt.
PAYRUBRICTEST v2mallenexpensify commentedon Sep 15, 2026
Payment Summary
Contributor+: @Ollyws due $125 via NewDot
flaviadefaria commentedon Sep 22, 2026
Approved: @Ollyws due $125 via NewDot