Skip to content

Add public Onyx.get - #831

Draft
LukasMod wants to merge 10 commits into
Expensify:mainfrom
callstack-internal:feat/onyx-get-async
Draft

Add public Onyx.get#831
LukasMod wants to merge 10 commits into
Expensify:mainfrom
callstack-internal:feat/onyx-get-async

Conversation

@LukasMod

@LukasMod LukasMod commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Details

Adds Onyx.get(key), a public one-shot asynchronous read on the Onyx object, so callers can read a key without opening a subscription.

What it does

  • Onyx.get<TKey>(key: TKey): Promise<OnyxValue<TKey>> (lib/Onyx.ts:632), registered on the Onyx object (lib/Onyx.ts:663) and therefore reachable through the default export of lib/index.ts.
  • The body runs inside OnyxUtils.afterInit, so a call made before Onyx.init() has finished resolves with the hydrated value instead of undefined.
  • Single key: delegates to OnyxUtils.get(key) and normalises null to undefined.
  • Collection key: returns the cached collection when the cache already holds it, otherwise assembles it from OnyxUtils.getAllKeys() plus OnyxUtils.multiGet() over the matching member keys, which also warms the cache for the next read.
  • Both a collection key and a collection member key are accepted. The internal OnyxUtils.get cannot return a whole collection, so that gap is what this function closes.

No new storage machinery is introduced; these are the same reads useOnyx already performs.

Semantics, documented in the JSDoc and in API.md

  • The result is the cached object itself, not a copy, and it is typed mutable to stay consistent with useOnyx(). Callers must treat it as read-only: a mutation is visible to every other reader of that key.
  • A write that is still queued when get() is called is not visible to it, so the write has to be awaited before reading.
  • A collection with no members resolves to {}. A collection read on a completely empty store resolves to undefined.
  • Use useOnyx() or Onyx.connectWithoutView() when the value has to stay current. get() is a point-in-time read.

Related Issues

GH_LINK

Linked E/App PR

Expensify/App#99667

Automated Tests

tests/unit/onyxTest.ts gains a describe('get') block with 14 cases covering:

  • single key present, and missing key resolving to undefined
  • resolving from cache without consulting storage, for both a single key and a whole collection
  • falling back to storage when the key is not in cache, and asserting the cache is warmed by that fallback
  • assembling a whole collection from its member keys
  • falling back to storage for a collection the cache holds nothing for
  • reading a collection member by its own key
  • not reading stale storage data for a RAM-only key
  • the four afterInit paths: waiting for initialization for a single key and for a collection, resolving undefined after init when the key has no value, and resolving a collection as undefined on a completely empty store

tests/perf-test/Onyx.perf-test.ts gains a describe('get') block with two benchmarks: 1k reads of a whole 10k-member collection of heavy objects, and 10k reads of individual collection members.

API.md is regenerated from the JSDoc.

Manual Tests

This is a library API addition with no UI surface, so it is exercised through the linked E/App PR rather than in isolation:

  1. Check out the linked E/App PR, which pins react-native-onyx to this PR's HEAD.
  2. Run the app and confirm the flows that were switched over to Onyx.get still load their data.
  3. Confirm there are no new console errors or warnings.
  4. Confirm no regression in the flows that still use useOnyx for the same keys.

Author Checklist

  • I linked the correct issue in the ### Related Issues section above
  • I linked the corresponding Expensify/App PR in the ### Linked E/App PR section above, and verified this change against it (E/App CI passed and manual testing completed)
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

@LukasMod

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ef3f683cb7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/Onyx.ts Outdated
Comment thread API.md Outdated
@LukasMod

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36f7695d07

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread API.md Outdated
@LukasMod

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 5638e884f1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@LukasMod

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: ce3efa96c2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@LukasMod
LukasMod force-pushed the feat/onyx-get-async branch from 0fa6e3b to d3e0b52 Compare September 3, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant