A full-featured CRM built with React, shadcn/ui, and Supabase.
Keep global search results out of the offline query cache
François Zaninottode354833c497
diff --git a/src/components/atomic-crm/root/CRM.tsx b/src/components/atomic-crm/root/CRM.tsxindex 9dcf0f9f..7bc70e69 100644--- a/src/components/atomic-crm/root/CRM.tsx+++ b/src/components/atomic-crm/root/CRM.tsx@@ -298,7 +298,13 @@ const MobileAdmin = (return (<PersistQueryClientProviderclient={queryClient}- persistOptions={{ persister: asyncStoragePersister }}+ persistOptions={{+ persister: asyncStoragePersister,+ dehydrateOptions: {+ shouldDehydrateQuery: (query) =>+ query.state.status === "success" && query.meta?.persist !== false,+ },+ }}><AdminqueryClient={queryClient}diff --git a/src/components/atomic-crm/search/GlobalSearchDialog.test.tsx b/src/components/atomic-crm/search/GlobalSearchDialog.test.tsxindex df76285f..61bcacf7 100644--- a/src/components/atomic-crm/search/GlobalSearchDialog.test.tsx+++ b/src/components/atomic-crm/search/GlobalSearchDialog.test.tsx@@ -286,6 +286,26 @@ describe("GlobalSearchDialog", () => {expect(match.element().tagName).toBe("MARK");});+ it("keeps search results out of the query cache the mobile app saves for offline use", async () => {+ await page.viewport(375, 667);+ const screen = await renderDialog();++ await screen.getByPlaceholder(PLACEHOLDER).fill("Boulangerie");+ await expect+ .element(screen.getByRole("group", { name: "Companies" }))+ .toBeVisible();+ const searchedAt = Date.now();+ // any later cache change saves a snapshot that includes the results+ await screen.getByPlaceholder(PLACEHOLDER).fill("B");++ const readSavedCache = () =>+ JSON.parse(localStorage.getItem("REACT_QUERY_OFFLINE_CACHE") ?? "null");+ await expect+ .poll(() => readSavedCache()?.timestamp ?? 0, { timeout: 3000 })+ .toBeGreaterThan(searchedAt);+ expect(JSON.stringify(readSavedCache())).not.toContain("globalSearch");+ });+it("reports when nothing matches", async () => {const screen = await renderDialog();diff --git a/src/components/atomic-crm/search/useGlobalSearch.ts b/src/components/atomic-crm/search/useGlobalSearch.tsindex 1767fcbd..2b3246a7 100644--- a/src/components/atomic-crm/search/useGlobalSearch.ts+++ b/src/components/atomic-crm/search/useGlobalSearch.ts@@ -40,6 +40,7 @@ export const useGlobalSearch = (queryFn: () =>dataProvider.globalSearch(debouncedQuery, resources, MAX_RESULTS),enabled: isEnabled,+ meta: { persist: false },});return {