Skip to content

Commit 8b9992a

Browse files
mountinyOSBotify
authored andcommitted
Merge pull request #85767 from margelo/@chrispader/dowgrade-onyx-to-v3.0.45
[CP Staging] fix: Downgrade Onyx to v3.0.45 (cherry picked from commit 5277b58) (cherry-picked to staging by mountiny)
1 parent 8877e41 commit 8b9992a

11 files changed

Lines changed: 56 additions & 86 deletions

File tree

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
"react-native-localize": "^3.5.4",
182182
"react-native-nitro-modules": "0.29.4",
183183
"react-native-nitro-sqlite": "9.2.0",
184-
"react-native-onyx": "3.0.46",
184+
"react-native-onyx": "3.0.45",
185185
"react-native-pager-view": "8.0.0",
186186
"react-native-pdf": "7.0.2",
187187
"react-native-permissions": "^5.4.0",

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useIsFocused} from '@react-navigation/native';
1+
import {useFocusEffect} from '@react-navigation/native';
22
import {hasSeenTourSelector} from '@selectors/Onboarding';
33
import {FlashList} from '@shopify/flash-list';
44
import type {FlashListRef, ListRenderItemInfo} from '@shopify/flash-list';
@@ -552,40 +552,31 @@ function MoneyRequestReportPreviewContent({
552552
carouselTransactionsRef.current = carouselTransactions;
553553
}, [carouselTransactions]);
554554

555-
const isFocused = useIsFocused();
556-
const isFocusedRef = useRef(isFocused);
555+
useFocusEffect(
556+
useCallback(() => {
557+
const index = carouselTransactions.findIndex((transaction) => newTransactionIDs?.has(transaction.transactionID));
557558

558-
useEffect(() => {
559-
isFocusedRef.current = isFocused;
560-
}, [isFocused]);
561-
562-
useEffect(() => {
563-
const index = carouselTransactions.findIndex((transaction) => newTransactionIDs?.has(transaction.transactionID));
564-
565-
if (index < 0) {
566-
return;
567-
}
568-
const newTransaction = carouselTransactions.at(index);
569-
setTimeout(() => {
570-
if (!isFocusedRef.current) {
571-
return;
572-
}
573-
// If the new transaction is not available at the index it was on before the delay, avoid the scrolling
574-
// because we are scrolling to either a wrong or unavailable transaction (which can cause crash).
575-
if (newTransaction?.transactionID !== carouselTransactionsRef.current.at(index)?.transactionID) {
559+
if (index < 0) {
576560
return;
577561
}
562+
const newTransaction = carouselTransactions.at(index);
563+
setTimeout(() => {
564+
// If the new transaction is not available at the index it was on before the delay, avoid the scrolling
565+
// because we are scrolling to either a wrong or unavailable transaction (which can cause crash).
566+
if (newTransaction?.transactionID !== carouselTransactionsRef.current.at(index)?.transactionID) {
567+
return;
568+
}
578569

579-
carouselRef.current?.scrollToIndex({
580-
index,
581-
viewOffset: -2 * styles.gap2.gap,
582-
animated: true,
583-
});
584-
}, CONST.ANIMATED_TRANSITION);
570+
carouselRef.current?.scrollToIndex({
571+
index,
572+
viewOffset: -2 * styles.gap2.gap,
573+
animated: true,
574+
});
575+
}, CONST.ANIMATED_TRANSITION);
585576

586-
// We only want to scroll to a new transaction when the set of new transaction IDs changes.
587-
// eslint-disable-next-line react-hooks/exhaustive-deps
588-
}, [newTransactionIDs]);
577+
// eslint-disable-next-line react-hooks/exhaustive-deps
578+
}, [newTransactionIDs]),
579+
);
589580

590581
const onViewableItemsChanged = useRef(({viewableItems}: {viewableItems: ViewToken[]; changed: ViewToken[]}) => {
591582
const newIndex = viewableItems.at(0)?.index;

src/components/ReportActionItem/MoneyRequestReportPreview/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {useIsFocused} from '@react-navigation/native';
12
import type {ListRenderItem} from '@shopify/flash-list';
23
import React, {useCallback, useMemo, useRef, useState} from 'react';
34
import type {LayoutChangeEvent} from 'react-native';
@@ -121,8 +122,9 @@ function MoneyRequestReportPreview({
121122
selector: hasOnceLoadedReportActionsSelector,
122123
});
123124
const newTransactions = useNewTransactions(hasOnceLoadedReportActions, transactions);
125+
const isFocused = useIsFocused();
124126
// We only want to highlight the new expenses if the screen is focused.
125-
const newTransactionIDs = new Set(newTransactions.map((transaction) => transaction.transactionID));
127+
const newTransactionIDs = isFocused ? new Set(newTransactions.map((transaction) => transaction.transactionID)) : undefined;
126128

127129
const transactionPreviewContainerStyles = [styles.h100, reportPreviewStyles.transactionPreviewCarouselStyle];
128130

src/pages/workspace/withPolicy.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {ComponentType} from 'react';
2-
import React, {useEffect} from 'react';
2+
import React from 'react';
33
import type {OnyxEntry} from 'react-native-onyx';
44
import useOnyx from '@hooks/useOnyx';
55
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
@@ -91,12 +91,9 @@ export default function <TProps extends WithPolicyProps>(WrappedComponent: Compo
9191
/* eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing */
9292
const isLoadingPolicy = !hasLoadedApp || (!!policyID && isLoadingOnyxValue(policyResults, policyDraftResults));
9393

94-
useEffect(() => {
95-
if (!policyID) {
96-
return;
97-
}
94+
if (policyID && policyID.length > 0) {
9895
updateLastAccessedWorkspace(policyID);
99-
}, [policyID]);
96+
}
10097

10198
return (
10299
<WrappedComponent

tests/actions/ReportTest.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,8 +1520,6 @@ describe('actions/Report', () => {
15201520
currentUserAccountID: TEST_USER_ACCOUNT_ID,
15211521
});
15221522

1523-
await waitForBatchedUpdates();
1524-
15251523
// Need the reportActionID to delete the comments
15261524
const newComment = PersistedRequests.getAll().at(1);
15271525
const reportActionID = newComment?.data?.reportActionID as string | undefined;
@@ -2041,9 +2039,6 @@ describe('actions/Report', () => {
20412039
const newComment = PersistedRequests.getAll().at(0);
20422040
const reportActionID = newComment?.data?.reportActionID as string | undefined;
20432041
const reportAction = TestHelper.buildTestReportComment(created, TEST_USER_ACCOUNT_ID, reportActionID);
2044-
2045-
await waitForBatchedUpdates();
2046-
20472042
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: true});
20482043

20492044
// wait for Onyx.connect execute the callback and start processing the queue
@@ -2237,7 +2232,6 @@ describe('actions/Report', () => {
22372232
expect(requests?.at(0)?.data?.reportComment).toBe('value3');
22382233

22392234
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});
2240-
await waitForBatchedUpdates();
22412235

22422236
TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.UPDATE_COMMENT, 1);
22432237
});
@@ -2336,8 +2330,6 @@ describe('actions/Report', () => {
23362330
expect(requests?.at(0)?.data?.reportComment).toBe('value3');
23372331

23382332
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});
2339-
await waitForBatchedUpdates();
2340-
23412333
TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.UPDATE_COMMENT, 1);
23422334
});
23432335

tests/actions/SessionTest.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ describe('Session', () => {
189189

190190
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});
191191

192-
await waitForBatchedUpdates();
193-
194192
expect(getAllPersistedRequests().length).toBe(0);
195193
});
196194

@@ -228,8 +226,6 @@ describe('Session', () => {
228226

229227
await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false});
230228

231-
await waitForBatchedUpdates();
232-
233229
expect(getAllPersistedRequests().length).toBe(0);
234230
});
235231

tests/unit/APITest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ describe('APITests', () => {
436436
});
437437

438438
Onyx.set(ONYXKEYS.NETWORK, {isOffline: true});
439-
expect(NetworkStore.isOffline()).toBe(true);
439+
expect(NetworkStore.isOffline()).toBe(false);
440440
expect(NetworkStore.isAuthenticating()).toBe(false);
441441
return waitForBatchedUpdates();
442442
})
@@ -551,7 +551,7 @@ describe('APITests', () => {
551551
API.write('MockCommandThree' as WriteCommand, {});
552552

553553
// THEN the retryable requests should immediately be added to the persisted requests
554-
expect(PersistedRequests.getLength()).toBe(2);
554+
expect(PersistedRequests.getAll().length).toBe(2);
555555

556556
// WHEN we wait for the queue to run and finish processing
557557
return waitForBatchedUpdates();

tests/unit/OptionsListUtilsTest.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,7 +3526,7 @@ describe('OptionsListUtils', () => {
35263526
expect(canCreate).toBe(false);
35273527
});
35283528

3529-
it('createOptionList() localization', async () => {
3529+
it('createOptionList() localization', () => {
35303530
renderLocaleContextProvider();
35313531
// Given a set of reports and personal details
35323532
// When we call createOptionList and extract the reports
@@ -3535,15 +3535,18 @@ describe('OptionsListUtils', () => {
35353535
// Then the returned reports should match the expected values
35363536
expect(reports.at(10)?.subtitle).toBe(`Submits to Mister Fantastic`);
35373537

3538-
await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES);
3539-
3540-
await waitForBatchedUpdates();
3541-
3542-
// When we call createOptionList again
3543-
const newReports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS).reports;
3544-
// Then the returned reports should change to Spanish
3545-
// cspell:disable-next-line
3546-
expect(newReports.at(10)?.subtitle).toBe('Se envía a Mister Fantastic');
3538+
return (
3539+
waitForBatchedUpdates()
3540+
// When we set the preferred locale to Spanish
3541+
.then(() => Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.ES))
3542+
.then(() => {
3543+
// When we call createOptionList again
3544+
const newReports = createOptionList(PERSONAL_DETAILS, CURRENT_USER_ACCOUNT_ID, EMPTY_PRIVATE_IS_ARCHIVED_MAP, REPORTS).reports;
3545+
// Then the returned reports should change to Spanish
3546+
// cspell:disable-next-line
3547+
expect(newReports.at(10)?.subtitle).toBe('Se envía a Mister Fantastic');
3548+
})
3549+
);
35473550
});
35483551
});
35493552

@@ -3617,8 +3620,6 @@ describe('OptionsListUtils', () => {
36173620
'1': getFakeAdvancedReportAction(CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT),
36183621
},
36193622
});
3620-
await waitForBatchedUpdates();
3621-
36223623
// When we call createOptionList with report 10 marked as archived
36233624
const archivedMap: PrivateIsArchivedMap = {
36243625
[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}10`]: reportNameValuePairs.private_isArchived,

tests/unit/ReportSecondaryActionUtilsTest.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,14 @@ describe('getSecondaryAction', () => {
5252
beforeAll(() => {
5353
Onyx.init({
5454
keys: ONYXKEYS,
55-
initialKeyStates: {
56-
[ONYXKEYS.SESSION]: SESSION,
57-
[ONYXKEYS.PERSONAL_DETAILS_LIST]: {[EMPLOYEE_ACCOUNT_ID]: PERSONAL_DETAILS, [APPROVER_ACCOUNT_ID]: {accountID: APPROVER_ACCOUNT_ID, login: APPROVER_EMAIL}},
58-
},
5955
});
6056
});
6157

6258
beforeEach(async () => {
6359
jest.clearAllMocks();
6460
Onyx.clear();
61+
await Onyx.merge(ONYXKEYS.SESSION, SESSION);
62+
await Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {[EMPLOYEE_ACCOUNT_ID]: PERSONAL_DETAILS, [APPROVER_ACCOUNT_ID]: {accountID: APPROVER_ACCOUNT_ID, login: APPROVER_EMAIL}});
6563
});
6664

6765
it('should always return default options', () => {

0 commit comments

Comments
 (0)