A full-featured CRM built with React, shadcn/ui, and Supabase.
Report global search failures while offline
François Zaninottob99f17c3e482
diff --git a/src/components/atomic-crm/search/GlobalSearchDialog.test.tsx b/src/components/atomic-crm/search/GlobalSearchDialog.test.tsxindex 61bcacf7..bae630ca 100644--- a/src/components/atomic-crm/search/GlobalSearchDialog.test.tsx+++ b/src/components/atomic-crm/search/GlobalSearchDialog.test.tsx@@ -1,6 +1,7 @@import { page } from "vitest/browser";import { beforeEach, describe, expect, it } from "vitest";import { render } from "vitest-browser-react";+import { onlineManager } from "@tanstack/react-query";import { StoryWrapper, buildContact } from "@/test/StoryWrapper";@@ -306,6 +307,34 @@ describe("GlobalSearchDialog", () => {expect(JSON.stringify(readSavedCache())).not.toContain("globalSearch");});+ it("reports a failed search instead of loading forever while offline", async () => {+ const screen = await render(+ <StoryWrapper+ dataProvider={{+ globalSearch: async () => {+ throw new Error("Failed to fetch");+ },+ }}+ >+ <GlobalSearchDialog open onOpenChange={() => {}} />+ </StoryWrapper>,+ );+ const input = screen.getByPlaceholder(PLACEHOLDER);+ await expect.element(input).toBeVisible();++ onlineManager.setOnline(false);+ try {+ await input.fill("Boulangerie");++ // react-query retries 3 times with a backoff before giving up+ await expect+ .element(screen.getByRole("alert"), { timeout: 10_000 })+ .toBeVisible();+ } finally {+ onlineManager.setOnline(true);+ }+ }, 15_000);+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 2b3246a7..36f5c7ed 100644--- a/src/components/atomic-crm/search/useGlobalSearch.ts+++ b/src/components/atomic-crm/search/useGlobalSearch.ts@@ -41,6 +41,9 @@ export const useGlobalSearch = (dataProvider.globalSearch(debouncedQuery, resources, MAX_RESULTS),enabled: isEnabled,meta: { persist: false },+ // offlineFirst (the app default) pauses a failed search while offline,+ // leaving the dialog loading forever instead of reporting the error+ networkMode: "always",});return {