-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[CP Staging] fix: Downgrade Onyx to v3.0.45 #85767
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import {useIsFocused} from '@react-navigation/native'; | ||
| import {useFocusEffect} from '@react-navigation/native'; | ||
| import {hasSeenTourSelector} from '@selectors/Onboarding'; | ||
| import {FlashList} from '@shopify/flash-list'; | ||
| import type {FlashListRef, ListRenderItemInfo} from '@shopify/flash-list'; | ||
|
|
@@ -552,40 +552,31 @@ function MoneyRequestReportPreviewContent({ | |
| carouselTransactionsRef.current = carouselTransactions; | ||
| }, [carouselTransactions]); | ||
|
|
||
| const isFocused = useIsFocused(); | ||
| const isFocusedRef = useRef(isFocused); | ||
| useFocusEffect( | ||
| useCallback(() => { | ||
| const index = carouselTransactions.findIndex((transaction) => newTransactionIDs?.has(transaction.transactionID)); | ||
|
|
||
| useEffect(() => { | ||
| isFocusedRef.current = isFocused; | ||
| }, [isFocused]); | ||
|
|
||
| useEffect(() => { | ||
| const index = carouselTransactions.findIndex((transaction) => newTransactionIDs?.has(transaction.transactionID)); | ||
|
|
||
| if (index < 0) { | ||
| return; | ||
| } | ||
| const newTransaction = carouselTransactions.at(index); | ||
| setTimeout(() => { | ||
| if (!isFocusedRef.current) { | ||
| return; | ||
| } | ||
| // If the new transaction is not available at the index it was on before the delay, avoid the scrolling | ||
| // because we are scrolling to either a wrong or unavailable transaction (which can cause crash). | ||
| if (newTransaction?.transactionID !== carouselTransactionsRef.current.at(index)?.transactionID) { | ||
| if (index < 0) { | ||
| return; | ||
| } | ||
| const newTransaction = carouselTransactions.at(index); | ||
| setTimeout(() => { | ||
| // If the new transaction is not available at the index it was on before the delay, avoid the scrolling | ||
| // because we are scrolling to either a wrong or unavailable transaction (which can cause crash). | ||
| if (newTransaction?.transactionID !== carouselTransactionsRef.current.at(index)?.transactionID) { | ||
| return; | ||
|
Comment on lines
+563
to
+567
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| carouselRef.current?.scrollToIndex({ | ||
| index, | ||
| viewOffset: -2 * styles.gap2.gap, | ||
| animated: true, | ||
| }); | ||
| }, CONST.ANIMATED_TRANSITION); | ||
| carouselRef.current?.scrollToIndex({ | ||
| index, | ||
| viewOffset: -2 * styles.gap2.gap, | ||
| animated: true, | ||
| }); | ||
| }, CONST.ANIMATED_TRANSITION); | ||
|
|
||
| // We only want to scroll to a new transaction when the set of new transaction IDs changes. | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [newTransactionIDs]); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [newTransactionIDs]), | ||
| ); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ CONSISTENCY-5 (docs)The Add an explanatory comment before the disable: // We only want to scroll to a new transaction when the set of new transaction IDs changes.
// eslint-disable-next-line react-hooks/exhaustive-depsPlease rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency. |
||
| const onViewableItemsChanged = useRef(({viewableItems}: {viewableItems: ViewToken[]; changed: ViewToken[]}) => { | ||
| const newIndex = viewableItems.at(0)?.index; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import {useIsFocused} from '@react-navigation/native'; | ||
| import type {ListRenderItem} from '@shopify/flash-list'; | ||
| import React, {useCallback, useMemo, useRef, useState} from 'react'; | ||
| import type {LayoutChangeEvent} from 'react-native'; | ||
|
|
@@ -121,8 +122,9 @@ function MoneyRequestReportPreview({ | |
| selector: hasOnceLoadedReportActionsSelector, | ||
| }); | ||
| const newTransactions = useNewTransactions(hasOnceLoadedReportActions, transactions); | ||
| const isFocused = useIsFocused(); | ||
| // We only want to highlight the new expenses if the screen is focused. | ||
| const newTransactionIDs = new Set(newTransactions.map((transaction) => transaction.transactionID)); | ||
| const newTransactionIDs = isFocused ? new Set(newTransactions.map((transaction) => transaction.transactionID)) : undefined; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
|
|
||
| const transactionPreviewContainerStyles = [styles.h100, reportPreviewStyles.transactionPreviewCarouselStyle]; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import type {ComponentType} from 'react'; | ||
| import React, {useEffect} from 'react'; | ||
| import React from 'react'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; | ||
|
|
@@ -91,12 +91,9 @@ export default function <TProps extends WithPolicyProps>(WrappedComponent: Compo | |
| /* eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing */ | ||
| const isLoadingPolicy = !hasLoadedApp || (!!policyID && isLoadingOnyxValue(policyResults, policyDraftResults)); | ||
|
|
||
| useEffect(() => { | ||
| if (!policyID) { | ||
| return; | ||
| } | ||
| if (policyID && policyID.length > 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ PERF-8 (docs)
Restore the useEffect(() => {
if (!policyID) {
return;
}
updateLastAccessedWorkspace(policyID);
}, [policyID]);Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency. |
||
| updateLastAccessedWorkspace(policyID); | ||
| }, [policyID]); | ||
| } | ||
|
|
||
| return ( | ||
| <WrappedComponent | ||
|
|
||
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.
❌ PERF-12 (docs)
The
setTimeoutinside theuseFocusEffectcallback has no cleanup mechanism. If the screen loses focus or the component unmounts beforeCONST.ANIMATED_TRANSITIONelapses, the timer callback will still fire, potentially callingscrollToIndexon an unmounted or stale ref. The previous implementation guarded against this withisFocusedRef.current, but that guard has been removed.Return a cleanup function from the
useFocusEffectcallback to clear the timer:Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.