Skip to content

[Due for payment 2026-08-05] Remove sourceValue from Onyx #94348

Closed

Description

@mountiny

Coming from here

Background

A collection callback receives an optional third argument, sourceValue (mirrored as a field on useOnyx's result metadata): the specific member(s) the triggering write touched, so a consumer can process just the delta instead of scanning the whole collection. Like per-member delivery, it predates the reference-stable frozen collection objects now kept in OnyxCache, in which members that didn't change keep the same reference across writes.

Problem

When a consumer reads sourceValue to learn which collection members a write changed, if several updates arrive close enough that React batches the resulting re-renders into one, then the hook keeps only the last write's sourceValue — it overwrites a single ref per update and the render reads only its final value — so a consumer using it to invalidate a derived cache silently misses every batched-away member and leaves that cache stale. The ref is also never cleared after a render, so an unrelated re-render still reports the previous write's keys, making the consumer recompute when nothing changed.

(Both were first reported in #newdot-performance — which also notes a third manifestation: a cache-invalidation if/else over multiple collections' sourceValues only invalidates one collection's keys when updates batch. Both reproduce against current main: the failing-test proofs in PR #679 still pass — its description of the batching internals predates a refactor, but the per-render, last-write-wins design that causes them remains.)

Solution

Remove the sourceValue parameter from the collection callback signature and from useOnyx's result metadata. A consumer that needs the delta computes it with usePrevious (or a stored previous reference) plus a structural diff against the new collection object — O(members), O(1) per member.

On E/App, add a small pure helper getCollectionDelta (new-vs-previous collection-object diff) and a new useCollectionDelta hook, and migrate the existing sourceValue consumers onto them.

Deriving the change this way is immune to both failure modes above. A render always sees the collection in its final, fully-merged state, so a previous-vs-current diff captures every member that changed across a batch — nothing is lost. And because unchanged members keep their reference, an unrelated re-render yields an identical object and an empty diff — no stale keys, no wasted work.

Although the proposal is not performance-focused, we measured and we didn't find any performance regressions with the new approach. In fact, SidebarOrderedReportsContextProvider (a heavy user of sourceValues) showed improvements of 5-10% in total execution.

Onyx PR: Expensify/react-native-onyx#801
E/App PR: #93438

Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    ReviewingHas a PR in review
    InternalRequires API changes or must be handled by Expensify staff
    on Jun 23, 2026
  2. fabioh8010 commented on Jun 30, 2026

    @fabioh8010
    Contributor
  3. Julesssss commented on Jun 30, 2026

    @Julesssss
    Contributor

    Onyx PR merged and released in 3.0.90. Blocked by queue currently as we're on 3.0.86.

  4. melvin-bot commented on Jul 7, 2026

    @melvin-bot

    @truph01 Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  5. fabioh8010 commented on Jul 8, 2026

    @fabioh8010
    Contributor

    We are still waiting for the bump queue.

  6. melvin-bot commented on Jul 9, 2026

    @melvin-bot

    @truph01 Eep! 4 days overdue now. Issues have feelings too...

  7. melvin-bot commented on Jul 13, 2026

    @melvin-bot

    @truph01 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!

  8. 15 remaining items

  9. melvin-bot commented on Jul 30, 2026

    @melvin-bot

    Triggered auto assignment to @mallenexpensify (Awaiting Payment)

  10. melvin-bot commented on Aug 4, 2026

    @melvin-bot

    Payment Summary

    Upwork Job

    • Contributor: @fabioh8010 does not require payment (Contractor)
    • Reviewer: @truph01 owed $250 via NewDot

    BugZero Checklist (@mallenexpensify)

    • I have verified the correct assignees and roles are listed above and updated the necessary manual offers
    • I have verified that there are no duplicate or incorrect contracts on Upwork for this job (https://www.upwork.com/ab/applicants//hired)
    • I have verified the PR was not reverted
    • I have applied any discounts due to bugs/regressions introduced by this PR
    • I have paid out the Upwork contracts or cancelled the ones that are incorrect
    • I have verified the payment summary above is correct
  11. melvin-bot commented on Aug 4, 2026

    @melvin-bot

    @mallenexpensify Huh... This is 4 days overdue. Who can take care of this?

  12. mallenexpensify commented on Aug 7, 2026

    @mallenexpensify
    Contributor

    Payment Summary

    Contributor+: @truph01 due $250 via NewDot

  13. garrettmknight commented on Oct 12, 2026

    @garrettmknight
    Contributor

    $250 approved for @truph01

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 productionDailyKSv2InternalRequires API changes or must be handled by Expensify staffTask

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions