Skip to content

Commit

Permalink
fix: preload search v2 key (#1927)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored Dec 21, 2024
1 parent d607ece commit 6b5ee7b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
16 changes: 14 additions & 2 deletions packages/fern-docs/ui/src/docs/DocsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dynamic from "next/dynamic";
import { ReactElement } from "react";
import {
HydrateAtoms,
useFeatureFlag,
useMessageHandler,
useSetJustNavigated,
type DocsProps,
Expand Down Expand Up @@ -58,10 +59,21 @@ export function DocsPage(pageProps: DocsProps): ReactElement | null {
}
);

const isSearchV2Enabled = useFeatureFlag("isSearchV2Enabled");
const isApiPlaygroundEnabled = useFeatureFlag("isApiPlaygroundEnabled");

return (
<>
<LinkPreloadApiRoute href="/api/fern-docs/search" />
<LinkPreloadApiRoute href="/api/fern-docs/auth/api-key-injection" />
<LinkPreloadApiRoute
href={
isSearchV2Enabled
? "/api/fern-docs/search/v2/key"
: "/api/fern-docs/search/v1/key"
}
/>
{isApiPlaygroundEnabled && (
<LinkPreloadApiRoute href="/api/fern-docs/auth/api-key-injection" />
)}
<NextSeo />
<InitializeTheme />
<SearchDialog />
Expand Down
11 changes: 7 additions & 4 deletions packages/fern-docs/ui/src/services/useSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ export function useSearchConfig(): SearchConfig {
return { isAvailable: false };
}

const { data } = useApiRouteSWR<SearchConfig>("/api/fern-docs/search", {
refreshInterval: 1000 * 60 * 60 * 2, // 2 hours
revalidateOnFocus: false,
});
const { data } = useApiRouteSWR<SearchConfig>(
"/api/fern-docs/search/v1/key",
{
refreshInterval: 1000 * 60 * 60 * 2, // 2 hours
revalidateOnFocus: false,
}
);

return data ?? { isAvailable: false };
}

0 comments on commit 6b5ee7b

Please sign in to comment.