diff --git a/packages/desktop-client/e2e/accounts.mobile.test.js b/packages/desktop-client/e2e/accounts.mobile.test.js index d6a740bb550..a1487c333db 100644 --- a/packages/desktop-client/e2e/accounts.mobile.test.js +++ b/packages/desktop-client/e2e/accounts.mobile.test.js @@ -55,9 +55,9 @@ test.describe('Mobile Accounts', () => { await expect(page).toMatchThemeScreenshots(); await accountPage.clearSearch(); + await expect(accountPage.transactions).not.toHaveCount(0); await accountPage.searchByText('Kroger'); - await expect(accountPage.transactionList).toBeVisible(); await expect(accountPage.transactions).not.toHaveCount(0); await expect(page).toMatchThemeScreenshots(); }); diff --git a/packages/loot-core/src/client/data-hooks/transactions.ts b/packages/loot-core/src/client/data-hooks/transactions.ts index 55d692b6a9c..ce2ea7ec38d 100644 --- a/packages/loot-core/src/client/data-hooks/transactions.ts +++ b/packages/loot-core/src/client/data-hooks/transactions.ts @@ -15,6 +15,8 @@ import { useSchedules, } from './schedules'; +const defaultQuery = q('transactions').select('*'); + type UseTransactionsProps = { queryBuilder: (query: Query) => Query; options?: { @@ -37,9 +39,8 @@ export function useTransactions({ queryBuilder, options = { pageCount: 50, includePreviewTransactions: false }, }: UseTransactionsProps): UseTransactionsResult { - const initialQuery = q('transactions').select('*'); const [query, setQuery] = useState( - queryBuilder?.(initialQuery) ?? initialQuery, + queryBuilder?.(defaultQuery) ?? defaultQuery, ); const [isLoading, setIsLoading] = useState(false); const [transactions, setTransactions] = useState< @@ -86,8 +87,8 @@ export function useTransactions({ const updateQuery = useCallback( (queryBuilder: (currentQuery: Query) => Query) => - setQuery(queryBuilder?.(query) ?? query), - [query], + setQuery(currentQuery => queryBuilder?.(currentQuery) ?? currentQuery), + [], ); return { @@ -168,7 +169,8 @@ function usePreviewTransactions({ setPreviewTransactions(ungroupTransactions(withDefaults)); } }); - } else { + } else if (!isUnmounted) { + // Nothing to preview setIsLoading(false); }