Repository navigation
Remove sourceValue from Onyx #93438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mountiny
merged 19 commits into
Expensify:main
from
callstack-internal:feature/onyx-store-pr-2
Jul 24, 2026
Merged
Remove sourceValue from Onyx #93438
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
69cc9f2
Use newest Onyx changes from Onyx store-based PR 2
fabioh8010 eb942cb
Merge remote-tracking branch 'origin/main' into feature/onyx-store-pr-2
fabioh8010 7beffbd
Replace removed Onyx sourceValue with a structural-sharing delta
fabioh8010 34c8b8a
Merge branch 'feature/onyx-store-poc-baseline' into feature/onyx-stor…
fabioh8010 b6fce1a
Merge branch 'main' into feature/onyx-store-pr-2
fabioh8010 64a15f8
Merge branch 'feature/onyx-store-poc-baseline' into feature/onyx-stor…
fabioh8010 35e1cc2
Merge branch 'feature/onyx-store-poc-baseline' into feature/onyx-stor…
fabioh8010 51bbeb7
Merge branch 'feature/onyx-store-poc-baseline' into feature/onyx-stor…
fabioh8010 076914f
Rebuild VISIBLE_REPORT_ACTIONS per report so deletions take effect
fabioh8010 bb9143e
Add tests for useCollectionDelta/getCollectionDelta
fabioh8010 39922ea
Cleanup
fabioh8010 05fe128
Cleanup
fabioh8010 f02c0e7
Merge branch 'main' into feature/onyx-store-pr-2
fabioh8010 aef6a90
Restore comment
fabioh8010 96788cb
Format files
fabioh8010 4ccad87
Add test for visibility recompute on a session change
fabioh8010 8c62d6e
Remove useMemo
fabioh8010 bb13756
Merge remote-tracking branch 'origin/main' into feature/onyx-store-pr-2
fabioh8010 ed1e14e
Merge remote-tracking branch 'origin/main' into feature/onyx-store-pr-2
fabioh8010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import getCollectionDelta from '@libs/getCollectionDelta'; | ||
|
|
||
| import type {OnyxCollection} from 'react-native-onyx'; | ||
|
|
||
| import usePrevious from './usePrevious'; | ||
|
|
||
| /** | ||
| * Given the latest collection value from `useOnyx`, returns the subset of members that changed since | ||
| * the previous render (added, changed, or removed), or `undefined` when nothing changed. Because Onyx | ||
| * structurally shares unchanged members, the underlying diff is a cheap reference-equality scan. | ||
| */ | ||
| function useCollectionDelta<TValue>(value: OnyxCollection<TValue>): OnyxCollection<TValue> | undefined { | ||
| const previous = usePrevious(value); | ||
| return getCollectionDelta(value, previous); | ||
| } | ||
|
|
||
| export default useCollectionDelta; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import {renderHook} from '@testing-library/react-native'; | ||
|
|
||
| import useCollectionDelta from '@hooks/useCollectionDelta'; | ||
|
|
||
| import type {OnyxCollection} from 'react-native-onyx'; | ||
|
|
||
| type Item = {v: number}; | ||
|
|
||
| function renderUseCollectionDelta(initialProps: OnyxCollection<Item>) { | ||
| return renderHook((value: OnyxCollection<Item>) => useCollectionDelta(value), {initialProps}); | ||
| } | ||
|
|
||
| describe('useCollectionDelta', () => { | ||
| it('should return undefined on the first render (nothing to diff against)', () => { | ||
| const {result} = renderUseCollectionDelta({a: {v: 1}}); | ||
| expect(result.current).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should return the members added since the previous render', () => { | ||
| const a: Item = {v: 1}; | ||
| const b: Item = {v: 2}; | ||
| const {result, rerender} = renderUseCollectionDelta({a}); | ||
|
|
||
| rerender({a, b}); | ||
| expect(result.current).toStrictEqual({b}); | ||
| }); | ||
|
|
||
| it('should return a changed member with its current value', () => { | ||
| const a: Item = {v: 1}; | ||
| const aNext: Item = {v: 2}; | ||
| const {result, rerender} = renderUseCollectionDelta({a}); | ||
|
|
||
| rerender({a: aNext}); | ||
| expect(result.current).toStrictEqual({a: aNext}); | ||
| }); | ||
|
|
||
| it('should return a removed member as undefined', () => { | ||
| const a: Item = {v: 1}; | ||
| const b: Item = {v: 2}; | ||
| const {result, rerender} = renderUseCollectionDelta({a, b}); | ||
|
|
||
| rerender({a}); | ||
| expect(result.current).toStrictEqual({b: undefined}); | ||
| }); | ||
|
|
||
| it('should return undefined when the value reference is unchanged between renders', () => { | ||
| const collection: OnyxCollection<Item> = {a: {v: 1}}; | ||
| const {result, rerender} = renderUseCollectionDelta(collection); | ||
|
|
||
| rerender(collection); | ||
| expect(result.current).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should return undefined when members keep their references across renders (structural sharing)', () => { | ||
| const a: Item = {v: 1}; | ||
| const {result, rerender} = renderUseCollectionDelta({a}); | ||
|
|
||
| // New container object, same member reference. | ||
| rerender({a}); | ||
| expect(result.current).toBeUndefined(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old
useMappedPolicies(policyMapper)only trackedtype,name,avatarURL, andemployeeList.Could we use a selector here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mapper actually never "tracked" only these properties: this consumer destructured
[, {sourceValue: policiesUpdates}], discarding the mapped value, anduseMappedPoliciesmaps after theuseOnyx(COLLECTION.POLICY)subscription (no selector), sosourceValuewas the raw changed policy members — and the code only uses their keys by doingObject.keys(policiesUpdates). So onmainan LHN recompute already fired on any policy change (keyed by policyID), anduseCollectionDelta(allPolicies)preserves that exact behavior (only the changed keys are consumed), so there's no regression — it's actually probably cheaper since it drops the unused inline map.