Skip to content

Commit

Permalink
fix: don't refresh search preview data (#1276)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tackley authored Jul 29, 2024
1 parent 8d24c0c commit 8b043a1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/search/preview/data.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -57,7 +57,7 @@ const fetcher = (suffix: string) =>
export function useLandingPageData(
slug: string,
): UseSearchDataReturn<SearchData> {
const { data, isLoading } = useSWR<ServerSearchData>(slug, fetcher);
const { data, isLoading } = useSWRImmutable<ServerSearchData>(slug, fetcher);

if (!data) {
return { loading: isLoading };
Expand All @@ -80,7 +80,7 @@ export function useKeywordData(
landingPageUrl: string,
): UseSearchDataReturn<string[]> {
const qs = new URLSearchParams({ url: landingPageUrl });
const { data, isLoading } = useSWR<string[]>(
const { data, isLoading } = useSWRImmutable<string[]>(
`${slug}/keywords?${qs}`,
fetcher,
);
Expand Down

0 comments on commit 8b043a1

Please sign in to comment.