From 996b946e860797e16a0abf25688a3fcc51c2dbd7 Mon Sep 17 00:00:00 2001 From: Cody Olsen Date: Thu, 21 Nov 2024 16:58:59 +0100 Subject: [PATCH] test fetch query --- next-enterprise/sanity.types.ts | 6 ++++-- next-enterprise/src/app/ThemeButton.tsx | 1 - next-enterprise/src/app/layout.tsx | 16 +++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/next-enterprise/sanity.types.ts b/next-enterprise/sanity.types.ts index 80d4f33..a9fbdf7 100644 --- a/next-enterprise/sanity.types.ts +++ b/next-enterprise/sanity.types.ts @@ -171,15 +171,17 @@ export type AllSanitySchemaTypes = export declare const internalGroqTypeReferenceTo: unique symbol // Source: ./src/app/layout.tsx // Variable: THEME_QUERY -// Query: *[_id == "theme"][0]{background,text} +// Query: *[_id == "theme"][0]{background,text,"fetchedAt": now()} export type THEME_QUERYResult = | { background: null text: null + fetchedAt: string } | { background: string | null text: string | null + fetchedAt: string } | null @@ -190,7 +192,7 @@ export type DEMO_QUERYResult = string | null declare module '@sanity/client' { interface SanityQueries { - '*[_id == "theme"][0]{background,text}': THEME_QUERYResult + '*[_id == "theme"][0]{background,text,"fetchedAt": now()}': THEME_QUERYResult '*[_type == "demo" && slug.current == $slug][0].title': DEMO_QUERYResult } } diff --git a/next-enterprise/src/app/ThemeButton.tsx b/next-enterprise/src/app/ThemeButton.tsx index e03567e..15b46c8 100644 --- a/next-enterprise/src/app/ThemeButton.tsx +++ b/next-enterprise/src/app/ThemeButton.tsx @@ -1,6 +1,5 @@ 'use client' -import type {SyncTag} from '@sanity/client' import {useTransition} from 'react' import {randomColorTheme} from './actions' diff --git a/next-enterprise/src/app/layout.tsx b/next-enterprise/src/app/layout.tsx index 4f5ba6f..b018100 100644 --- a/next-enterprise/src/app/layout.tsx +++ b/next-enterprise/src/app/layout.tsx @@ -6,14 +6,18 @@ import {SanityLive} from './SanityLive' import {ThemeButton} from './ThemeButton' import {TimeSince} from './TimeSince' -const THEME_QUERY = defineQuery(`*[_id == "theme"][0]{background,text}`) +const THEME_QUERY = defineQuery(`*[_id == "theme"][0]{background,text,"fetchedAt": now()}`) export default async function RootLayout({ children, }: Readonly<{ children: React.ReactNode }>) { - const {data, fetchedAt} = await sanityFetch({query: THEME_QUERY}) + const { + data, + // This timestamp is inaccurate without 'use cache' + // fetchedAt, + } = await sanityFetch({query: THEME_QUERY}) return (
- - - + {data?.fetchedAt && ( + + + + )} {children}