Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
07b6339
fix: remembered snapshot and skeleton state for Home Recently added s…
BartekObudzinski Aug 19, 2026
25a38dd
Merge remote-tracking branch 'upstream/main' into fix/recently-added-…
BartekObudzinski Aug 19, 2026
e1641a9
fix: correct inaccurate comment about SearchUIUtils bundle cost
BartekObudzinski Aug 19, 2026
b840ad1
fix: satisfy spellcheck and drop unused type export
BartekObudzinski Aug 19, 2026
9b91f4a
fix: keep Search snapshot results when a request fails
BartekObudzinski Aug 19, 2026
3975881
fix: drop unused import and type assertion flagged by eslint
BartekObudzinski Aug 19, 2026
bbc7ee3
fix: retry a failed Search on reconnect, drop the row cap and the dea…
BartekObudzinski Aug 20, 2026
1302cfd
Merge remote-tracking branch 'upstream/main' into fix/recently-added-…
BartekObudzinski Aug 20, 2026
8f6c3e8
fix: drop isOffline from Search call sites added upstream
BartekObudzinski Aug 20, 2026
421d397
Merge remote-tracking branch 'upstream/main' into fix/recently-added-…
BartekObudzinski Aug 20, 2026
932e469
fix: measure the skeleton without padding and drop stale isOffline deps
BartekObudzinski Aug 21, 2026
ce7f027
docs: trim comments down to the non-obvious reasons
BartekObudzinski Aug 21, 2026
1af2d1e
fix: match the skeleton block to the real row height and separators
BartekObudzinski Aug 21, 2026
cef3290
Merge remote-tracking branch 'upstream/main' into fix/recently-added-…
BartekObudzinski Aug 21, 2026
e47dbbb
fix: keep the empty state spacing as it is on staging
BartekObudzinski Aug 21, 2026
fb47ae9
fix: add JSDoc to shouldShowSkeleton, replace em dash in comment
BartekObudzinski Aug 24, 2026
0aa931b
fix: add blank lines before inline comments per review suggestions
BartekObudzinski Aug 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
shouldCalculateTotals,
offset: 0,
queryJSON: currentSearchQueryJSON,
isOffline,
isLoading: !!currentSearchResults?.search?.isLoading,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ function PayPrimaryAction({reportID, chatReportID}: PayPrimaryActionProps) {
shouldCalculateTotals,
offset: 0,
queryJSON: currentSearchQueryJSON,
isOffline,
isLoading: !!currentSearchResults?.search?.isLoading,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ function SubmitPrimaryActionContent({reportID}: SubmitPrimaryActionProps) {
shouldCalculateTotals,
offset: 0,
queryJSON: currentSearchQueryJSON,
isOffline,
isLoading: !!currentSearchResults?.search?.isLoading,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ function GroupChildrenContent({
offset: 0,
shouldCalculateTotals: false,
isLoading: !!transactionsSnapshot?.search?.isLoading,
isOffline,
});
};

Expand All @@ -76,7 +75,6 @@ function GroupChildrenContent({
offset: (transactionsSnapshot?.search?.offset ?? 0) + pageSize,
shouldCalculateTotals: false,
isLoading: !!transactionsSnapshot?.search?.isLoading,
isOffline,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ function TransactionGroupListItemImpl({
offset: 0,
shouldCalculateTotals: false,
isLoading: !!transactionsSnapshot?.search?.isLoading,
isOffline,
});
};

Expand All @@ -181,7 +180,6 @@ function TransactionGroupListItemImpl({
offset: (transactionsSnapshot?.search?.offset ?? 0) + pageSize,
shouldCalculateTotals: false,
isLoading: !!transactionsSnapshot?.search?.isLoading,
isOffline,
});
};

Expand Down Expand Up @@ -222,9 +220,8 @@ function TransactionGroupListItemImpl({
offset: 0,
shouldCalculateTotals: false,
isLoading: !!transactionsSnapshot?.search?.isLoading,
isOffline,
});
}, [newTransactionID, isExpanded, groupItem.transactionsQueryJSON, isOffline, transactionsSnapshot?.search?.isLoading]);
}, [newTransactionID, isExpanded, groupItem.transactionsQueryJSON, transactionsSnapshot?.search?.isLoading]);

const wasScreenFocusedRef = useRef(isScreenFocused);
useEffect(() => {
Expand All @@ -246,9 +243,8 @@ function TransactionGroupListItemImpl({
offset: 0,
shouldCalculateTotals: false,
isLoading: !!transactionsSnapshot?.search?.isLoading,
isOffline,
});
}, [isScreenFocused, isExpanded, isExpenseReportType, groupItem.transactionsQueryJSON, isOffline, transactionsSnapshot?.search?.isLoading]);
}, [isScreenFocused, isExpanded, isExpenseReportType, groupItem.transactionsQueryJSON, transactionsSnapshot?.search?.isLoading]);

const handleToggle = () => {
setIsExpanded((prev) => {
Expand Down
10 changes: 5 additions & 5 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,10 @@ function Search({
const focusedRoute = findFocusedRoute(navigationRef.getRootState());
const isMigratedModalDisplayed = focusedRoute?.name === NAVIGATORS.MIGRATED_USER_MODAL_NAVIGATOR || focusedRoute?.name === SCREENS.MIGRATED_USER_WELCOME_MODAL.DYNAMIC_ROOT;

const comingBackOnlineWithNoResults = prevIsOffline && !isOffline && isEmptyObject(searchResults?.data);
// A failed search keeps its previous results, so only the error tells us a retry is still needed.
const comingBackOnlineWithNoResultsOrError = prevIsOffline && !isOffline && (isEmptyObject(searchResults?.data) || hasErrors);
const comingBackOnlineWithMissingAllMatchingTotals = prevIsOffline && !isOffline && isExpenseAllMatchingSelection && isAllMatchingItemsCountMissing;
const shouldRefreshOnReconnect = comingBackOnlineWithNoResults || comingBackOnlineWithMissingAllMatchingTotals;
const shouldRefreshOnReconnect = comingBackOnlineWithNoResultsOrError || comingBackOnlineWithMissingAllMatchingTotals;
if (!shouldRefreshOnReconnect && ((!isFocused && !isMigratedModalDisplayed) || isOffline)) {
return;
}
Expand Down Expand Up @@ -1027,9 +1028,8 @@ function Search({
{...(!isInvalidQuery && {
buttonTranslationKey: 'common.tryAgain',
onButtonPress: () => {
// A failed load-more clears the whole snapshot (data: null), so retrying with the
// paginated offset would refetch only the later page into an empty snapshot and drop
// the initial results. Reset pagination to the first page before retrying.
// A response replaces the snapshot's results rather than appending to them, so retrying at
// the paginated offset would leave only that later page behind. Retry from the first page.
setOffset(0);
handleSearch({
queryJSON,
Expand Down
1 change: 0 additions & 1 deletion src/libs/SearchRefreshUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function refreshSearchAfterReportAction({currentSearchQueryJSON, currentSearchKe
shouldCalculateTotals,
offset: 0,
queryJSON: currentSearchQueryJSON,
isOffline,
isLoading,
});
}
Expand Down
13 changes: 5 additions & 8 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,6 @@ function getOnyxLoadingData(
hash: number,
queryJSON?: Readonly<SearchQueryJSON>,
offset?: number,
isOffline?: boolean,
isSearchAPI = false,
shouldCalculateTotals?: boolean,
): OnyxData<typeof ONYXKEYS.COLLECTION.SNAPSHOT> {
Expand All @@ -761,7 +760,7 @@ function getOnyxLoadingData(
// `search.state` tracks the lifecycle of a real search request (identified by its queryJSON): it starts as
// `loading` optimistically and is resolved to `loaded` by finallyData. handlePreventSearchAPI
// reuses this helper as a UI-only loading toggle with no query, so it must stay out of
// the state machine — otherwise it would strand `state: loading` with no terminal write to clear it.
// the state machine. Otherwise it would strand `state: loading` with no terminal write to clear it.
const isSearchRequest = isSearchAPI && !!queryJSON;
const type = queryJSON?.type;

Expand Down Expand Up @@ -812,12 +811,13 @@ function getOnyxLoadingData(
},
];

// Deliberately leaves `data` in place: `errors` already records the failure and the Search view early-returns on it.
// Deleting the results too cost every consumer its last known data, and the snapshot is the only copy that survives a reload.
const failureData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.SNAPSHOT>> = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`,
value: {
...(isOffline ? {} : {data: null}),
search: {
type,
...(isSearchAPI && {isLoading: false}),
Comment thread
mountiny marked this conversation as resolved.
Resolved
Expand Down Expand Up @@ -1083,7 +1083,7 @@ function handlePreventSearchAPI(hash: number | undefined) {
if (typeof hash === 'undefined') {
return {};
}
const {optimisticData, finallyData} = getOnyxLoadingData(hash, undefined, undefined, false, true);
const {optimisticData, finallyData} = getOnyxLoadingData(hash, undefined, undefined, true);
return {
enableSearchAPIPrevention: () => {
shouldPreventSearchAPI = true;
Expand Down Expand Up @@ -1128,7 +1128,6 @@ function search({
offset,
shouldCalculateTotals = false,
prevReportsLength,
isOffline = false,
isLoading,
shouldUpdateLastSearchParams = false,
skipWaitForWrites = false,
Expand All @@ -1139,7 +1138,6 @@ function search({
offset?: number;
shouldCalculateTotals?: boolean;
prevReportsLength?: number;
isOffline?: boolean;
isLoading: boolean;
shouldUpdateLastSearchParams?: boolean;
/**
Expand Down Expand Up @@ -1180,7 +1178,6 @@ function search({
offset,
shouldCalculateTotals: inFlightRequest.pendingShouldCalculateTotals,
prevReportsLength,
isOffline,
isLoading: false,
shouldUpdateLastSearchParams,
skipWaitForWrites,
Expand All @@ -1192,7 +1189,7 @@ function search({
const inFlightRequestState: InFlightSearchRequest = {shouldCalculateTotals, shouldSaveRecentSearch};
inFlightSearchRequests.set(dedupeKey, inFlightRequestState);

const {optimisticData, finallyData, failureData} = getOnyxLoadingData(queryJSON.hash, queryJSON, offset, isOffline, true, shouldCalculateTotals);
const {optimisticData, finallyData, failureData} = getOnyxLoadingData(queryJSON.hash, queryJSON, offset, true, shouldCalculateTotals);
const {backendQueryJSON, limit, exactMatchFilterKeys} = getBackendQueryJSON(queryJSON);
const query = {
...backendQueryJSON,
Expand Down
2 changes: 0 additions & 2 deletions src/pages/ReportSubmitToContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ function ReportSubmitToContent({
shouldCalculateTotals,
offset: 0,
queryJSON: currentSearchQueryJSON,
isOffline,
isLoading: !!currentSearchResults?.search?.isLoading,
});
}
Expand Down Expand Up @@ -322,7 +321,6 @@ function ReportSubmitToContent({
shouldCalculateTotals,
offset: 0,
queryJSON: currentSearchQueryJSON,
isOffline,
isLoading: !!currentSearchResults?.search?.isLoading,
});
}
Expand Down
1 change: 0 additions & 1 deletion src/pages/home/InsightsSection/useInsightData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function useInsightData(config: SearchTypeMenuItem | undefined) {
queryJSON,
searchKey,
offset: 0,
isOffline,
isLoading: false,
shouldUpdateLastSearchParams: false,
// The query is a static canned search, so it doesn't need anything OpenApp delivers. Don't sit behind it.
Expand Down
139 changes: 139 additions & 0 deletions src/pages/home/RecentlyAddedSection/RecentlyAddedPlaceholder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import SkeletonRect from '@components/SkeletonRect';
import ItemListSkeletonView from '@components/Skeletons/ItemListSkeletonView';

import useContainerWidth from '@hooks/useContainerWidth';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';

import variables from '@styles/variables';

import CONST from '@src/CONST';

import React from 'react';
import {View} from 'react-native';

import EmptyState from './EmptyState';

type RecentlyAddedPlaceholderProps = {
/** When true, renders the shimmer skeleton; when false, renders the empty state. */
shouldShowSkeleton: boolean;
};
Comment thread
mountiny marked this conversation as resolved.
Resolved

// Derived from the tokens RecentlyAddedRow uses rather than copied as literals, so the block keeps matching the rows
// when a token changes. A row is `pv3` around a receipt (pinned to its narrow size on both layouts) beside a merchant
// line and a muted label line separated by `gap1`, and every row but the last adds a 1px `borderBottom`.
// `pv3` on the row, top and bottom.
const ROW_VERTICAL_PADDING = 12 * 2;
const RECEIPT_WIDTH = variables.h36;
const RECEIPT_HEIGHT = variables.w40;
const MERCHANT_LINE_HEIGHT = variables.fontSizeNormalHeight;
const LABEL_LINE_HEIGHT = variables.lineHeightNormal;
const TEXT_LINE_GAP = 4;

// Every row but the last carries a 1px `borderBottom`, which the uniform loader height cannot express.
Comment thread
mountiny marked this conversation as resolved.
Resolved
const SEPARATORS_HEIGHT = CONST.HOME.SECTION_VISIBLE_LIMIT - 1;
const ITEM_HEIGHT = ROW_VERTICAL_PADDING + Math.max(RECEIPT_HEIGHT, MERCHANT_LINE_HEIGHT + TEXT_LINE_GAP + LABEL_LINE_HEIGHT);
const COLUMN_GAP = 12;
const BAR_HEIGHT = 12;
const AMOUNT_WIDTH = 56;
const TYPE_WIDTH = 40;
const DATE_WIDTH = 64;
const separatorsSpacerStyle = {height: SEPARATORS_HEIGHT};

// ItemListSkeletonView adds `mr5` to every row, so without this offset the right-aligned bars land past the svg and clip.
Comment thread
mountiny marked this conversation as resolved.
Resolved
const ROW_RIGHT_MARGIN = 20;

/** Varying the merchant width per row keeps the shimmer from reading as a rigid block. */
function getMerchantSkeletonWidth(itemIndex: number) {
switch (itemIndex % 3) {
case 0:
return 120;
case 1:
return 96;
default:
return 140;
}
}

/**
* Shimmer while a search may still land, empty state once the answer is settled. Measures its own container rather than
* the window, because it sits in a Home widget and not in the full-width Search pane.
*/
function RecentlyAddedPlaceholder({shouldShowSkeleton}: RecentlyAddedPlaceholderProps) {
const {onLayout, containerWidth} = useContainerWidth(ROW_RIGHT_MARGIN);
const styles = useThemeStyles();
const {shouldUseNarrowLayout} = useResponsiveLayout();

const renderSkeletonItem = (args: {itemIndex: number}) => {
const textX = RECEIPT_WIDTH + COLUMN_GAP;
const merchantWidth = getMerchantSkeletonWidth(args.itemIndex);

// Centred as a block against the taller receipt, as the row's flex column is.
Comment thread
mountiny marked this conversation as resolved.
Resolved
const textBlockHeight = MERCHANT_LINE_HEIGHT + TEXT_LINE_GAP + LABEL_LINE_HEIGHT;
const blockTop = (ITEM_HEIGHT - textBlockHeight) / 2;
const firstLineY = blockTop + (MERCHANT_LINE_HEIGHT - BAR_HEIGHT) / 2;
const secondLineY = blockTop + MERCHANT_LINE_HEIGHT + TEXT_LINE_GAP + (LABEL_LINE_HEIGHT - BAR_HEIGHT) / 2;

return (
<>
<SkeletonRect
transform={[{translateX: 0}, {translateY: (ITEM_HEIGHT - RECEIPT_HEIGHT) / 2}]}
width={RECEIPT_WIDTH}
height={RECEIPT_HEIGHT}
borderRadius={4}
/>
<SkeletonRect
transform={[{translateX: textX}, {translateY: firstLineY}]}
width={merchantWidth}
height={BAR_HEIGHT}
/>
<SkeletonRect
transform={[{translateX: textX}, {translateY: secondLineY}]}
width={DATE_WIDTH}
height={BAR_HEIGHT}
/>
{/* Right-aligned, so they can only be placed once measured; a guessed position would visibly jump. */}
{containerWidth > 0 && (
<>
<SkeletonRect
transform={[{translateX: containerWidth - AMOUNT_WIDTH}, {translateY: firstLineY}]}
width={AMOUNT_WIDTH}
height={BAR_HEIGHT}
/>
<SkeletonRect
transform={[{translateX: containerWidth - TYPE_WIDTH}, {translateY: secondLineY}]}
width={TYPE_WIDTH}
height={BAR_HEIGHT}
/>
</>
)}
</>
);
};

if (!shouldShowSkeleton) {
return <EmptyState />;
}

return (
<View
testID="recentlyAddedSkeleton"
style={shouldUseNarrowLayout ? styles.ph5 : styles.ph8}
>
{/* Measured without padding: the padded parent's width includes the inset, which pushes the right-aligned bars off the svg. */}
<View
style={styles.flex1}
onLayout={onLayout}
>
<ItemListSkeletonView
itemViewHeight={ITEM_HEIGHT}
fixedNumItems={CONST.HOME.SECTION_VISIBLE_LIMIT}
renderSkeletonItem={renderSkeletonItem}
/>
<View style={separatorsSpacerStyle} />
</View>
</View>
);
}

export default RecentlyAddedPlaceholder;
10 changes: 6 additions & 4 deletions src/pages/home/RecentlyAddedSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import React from 'react';

import type {RecentlyAddedExpense} from './useRecentlyAddedData';

import EmptyState from './EmptyState';
import RecentlyAddedPlaceholder from './RecentlyAddedPlaceholder';
import RecentlyAddedRow from './RecentlyAddedRow';
import {useRecentlyAddedData} from './useRecentlyAddedData';

function RecentlyAddedSection() {
const {transactions} = useRecentlyAddedData();
const {transactions, isAwaitingFirstResult} = useRecentlyAddedData();
const {translate} = useLocalize();
const styles = useThemeStyles();
const {shouldUseNarrowLayout} = useResponsiveLayout();
Expand Down Expand Up @@ -112,7 +112,9 @@ function RecentlyAddedSection() {
<WidgetContainer
title={translate('homePage.recentlyAddedSection.title')}
titleRightContent={overflowMenu}
containerStyles={hasExpenses ? listBottomPadding : undefined}
Comment thread
mountiny marked this conversation as resolved.
Resolved
// The skeleton stands in for the rows, so it needs their bottom padding to avoid a jump when they land.
// The empty state never had it, so it keeps its existing spacing.
containerStyles={hasExpenses || isAwaitingFirstResult ? listBottomPadding : undefined}
>
{hasExpenses ? (
transactions.map((expense, index) => (
Expand All @@ -126,7 +128,7 @@ function RecentlyAddedSection() {
/>
))
) : (
<EmptyState />
<RecentlyAddedPlaceholder shouldShowSkeleton={isAwaitingFirstResult} />
)}
</WidgetContainer>
);
Expand Down
Loading
Loading