Skip to content

Commit 6f99ace

Browse files
committed
Merge branch 'padms/3890' into staging
2 parents fcc8969 + c683fba commit 6f99ace

2 files changed

Lines changed: 5 additions & 12 deletions

File tree

web/app/[locale]/(pages)/[...slug]/page.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import { getLocale } from 'next-intl/server'
88
import { decodeSlugs } from '@/lib/helpers/getFullUrl'
99
import { Flags } from '@/sanity/helpers/datasetHelpers'
1010
import { getNameFromIso } from '@/sanity/helpers/localization'
11-
import { IS_FETCH_OPTIMIZED, routeSanityFetch } from '@/sanity/lib/fetch'
12-
import { optimizedFetch } from '@/sanity/lib/simpleFetch'
11+
import { routeSanityFetch } from '@/sanity/lib/fetch'
1312
import { constructSanityMetadata, getPage } from '@/sanity/pages/utils'
1413
import { menuQuery as globalMenuQuery } from '@/sanity/queries/menu'
1514
import {
@@ -31,16 +30,11 @@ const NewsPage = dynamic(() => import('@/templates/news/News'))
3130
const TopicPage = dynamic(() => import('@/templates/topic/TopicPage'))
3231
const MagazineRoom = dynamic(() => import('@/templates/magazine/Magazineroom'))
3332

34-
const getSanityFetch = (isDraftMode: boolean) =>
35-
isDraftMode || !IS_FETCH_OPTIMIZED ? routeSanityFetch : optimizedFetch
36-
3733
export async function generateMetadata({
3834
params,
3935
}: PageProps<'/[locale]/[...slug]'>): Promise<Metadata> {
4036
//array, separated by /. e.g. [news, last slug]
4137
const { slug: encodedSlug, locale } = await params
42-
const { isEnabled: isDraftMode } = await draftMode()
43-
const sanityFetch = getSanityFetch(isDraftMode)
4438
const slug = decodeSlugs(encodedSlug) as string[]
4539

4640
const sanityLang = getNameFromIso(locale)
@@ -65,7 +59,7 @@ export async function generateMetadata({
6559
query = magazineroomMetaQuery
6660
}
6761

68-
const { data: metaData }: { data: any } = await sanityFetch({
62+
const { data: metaData }: { data: any } = await routeSanityFetch({
6963
query,
7064
params: {
7165
lang: sanityLang,
@@ -87,10 +81,9 @@ export default async function Page({ params, searchParams }: Props) {
8781
/* const isInPresentationToolContext =
8882
(await cookies()).get('preview-fetch-dest')?.value === 'iframe' */
8983
const { isEnabled: isDraftMode } = await draftMode()
90-
const sanityFetch = getSanityFetch(isDraftMode)
9184
let pageContent = null
9285
const [siteMenuResult, pageResults] = await Promise.all([
93-
sanityFetch({
86+
routeSanityFetch({
9487
query: Flags.HAS_FANCY_MENU ? globalMenuQuery : simpleMenuQuery,
9588
params: {
9689
lang: getNameFromIso(locale) ?? 'en_GB',
@@ -101,7 +94,7 @@ export default async function Page({ params, searchParams }: Props) {
10194
slug: decodeSlugs(slug),
10295
locale,
10396
searchParams: resolvedSearchParams,
104-
fetch: sanityFetch,
97+
fetch: routeSanityFetch,
10598
}),
10699
])
107100
pageContent = pageResults

web/sanity/lib/simpleFetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use cache'
21
import { cacheTag } from 'next/cache'
32
import type { DefinedFetchType } from 'next-sanity/live'
43
import { client as simpleClient } from './simpleClient'
@@ -10,6 +9,7 @@ export const optimizedFetch: DefinedFetchType = async ({
109
perspective = 'published',
1110
requestTag = 'optimized-fetch',
1211
}) => {
12+
'use cache'
1313
console.log('Fetching with optimized fetch:', {
1414
tags,
1515
perspective,

0 commit comments

Comments
 (0)