From d3650781d7e06a7f74e248a1d8709e62c3a0c465 Mon Sep 17 00:00:00 2001 From: Andrew Jiang Date: Fri, 20 Dec 2024 17:53:12 -0500 Subject: [PATCH] fix: preload search v2 key --- .../api/fern-docs/search/{ => v1/key}/route.ts | 0 packages/fern-docs/ui/src/docs/DocsPage.tsx | 16 ++++++++++++++-- .../ui/src/services/useSearchService.ts | 11 +++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) rename packages/fern-docs/bundle/src/app/api/fern-docs/search/{ => v1/key}/route.ts (100%) diff --git a/packages/fern-docs/bundle/src/app/api/fern-docs/search/route.ts b/packages/fern-docs/bundle/src/app/api/fern-docs/search/v1/key/route.ts similarity index 100% rename from packages/fern-docs/bundle/src/app/api/fern-docs/search/route.ts rename to packages/fern-docs/bundle/src/app/api/fern-docs/search/v1/key/route.ts diff --git a/packages/fern-docs/ui/src/docs/DocsPage.tsx b/packages/fern-docs/ui/src/docs/DocsPage.tsx index e1162fcf3c..3ecfdcfa2a 100644 --- a/packages/fern-docs/ui/src/docs/DocsPage.tsx +++ b/packages/fern-docs/ui/src/docs/DocsPage.tsx @@ -2,6 +2,7 @@ import dynamic from "next/dynamic"; import { ReactElement } from "react"; import { HydrateAtoms, + useFeatureFlag, useMessageHandler, useSetJustNavigated, type DocsProps, @@ -58,10 +59,21 @@ export function DocsPage(pageProps: DocsProps): ReactElement | null { } ); + const isSearchV2Enabled = useFeatureFlag("isSearchV2Enabled"); + const isApiPlaygroundEnabled = useFeatureFlag("isApiPlaygroundEnabled"); + return ( <> - - + + {isApiPlaygroundEnabled && ( + + )} diff --git a/packages/fern-docs/ui/src/services/useSearchService.ts b/packages/fern-docs/ui/src/services/useSearchService.ts index 3c21d8bbbe..9d204c39ea 100644 --- a/packages/fern-docs/ui/src/services/useSearchService.ts +++ b/packages/fern-docs/ui/src/services/useSearchService.ts @@ -29,10 +29,13 @@ export function useSearchConfig(): SearchConfig { return { isAvailable: false }; } - const { data } = useApiRouteSWR("/api/fern-docs/search", { - refreshInterval: 1000 * 60 * 60 * 2, // 2 hours - revalidateOnFocus: false, - }); + const { data } = useApiRouteSWR( + "/api/fern-docs/search/v1/key", + { + refreshInterval: 1000 * 60 * 60 * 2, // 2 hours + revalidateOnFocus: false, + } + ); return data ?? { isAvailable: false }; }