From 8b043a18e4b079248e47bde53a109478bb4721b9 Mon Sep 17 00:00:00 2001 From: Graham Tackley Date: Mon, 29 Jul 2024 09:05:30 +0100 Subject: [PATCH] fix: don't refresh search preview data (#1276) The default of swr is to refresh the data on screen activation, network reconnect etc. This is not needed for the search preview data as the data is very unlikely to change within one user session, generating needless requests that return the same data. See https://swr.vercel.app/docs/revalidation#disable-automatic-revalidations --- src/search/preview/data.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/search/preview/data.ts b/src/search/preview/data.ts index 0d3d096f..6dae36ac 100644 --- a/src/search/preview/data.ts +++ b/src/search/preview/data.ts @@ -1,7 +1,7 @@ /* eslint-disable lingui/no-unlocalized-strings */ import { CountryDomain } from "@/user/views/user/search/types"; import { buildAdServerEndpoint } from "@/util/environment"; -import useSWR from "swr"; +import useSWRImmutable from "swr/immutable"; /* this is the data we get back from the server */ interface ServerSearchData { @@ -57,7 +57,7 @@ const fetcher = (suffix: string) => export function useLandingPageData( slug: string, ): UseSearchDataReturn { - const { data, isLoading } = useSWR(slug, fetcher); + const { data, isLoading } = useSWRImmutable(slug, fetcher); if (!data) { return { loading: isLoading }; @@ -80,7 +80,7 @@ export function useKeywordData( landingPageUrl: string, ): UseSearchDataReturn { const qs = new URLSearchParams({ url: landingPageUrl }); - const { data, isLoading } = useSWR( + const { data, isLoading } = useSWRImmutable( `${slug}/keywords?${qs}`, fetcher, );