Skip to content

Commit fcc8969

Browse files
committed
Merge branch 'padms/3890' into staging
2 parents f9a66ff + 81cd775 commit fcc8969

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

web/sanity/lib/fetch.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ import { optimizedFetch } from './simpleFetch'
1414
export const IS_FETCH_OPTIMIZED =
1515
process.env.NEXT_PUBLIC_OPTIMIZED_SANITY_FETCH === 'true'
1616

17+
const cachedSanityFetch: DefinedFetchType = async options => {
18+
'use cache'
19+
return sanityFetch(options)
20+
}
21+
1722
export const routeSanityFetch: DefinedFetchType = async options => {
18-
if (!IS_FETCH_OPTIMIZED) {
23+
// Drafts must stay uncached and keep stega/visual editing support.
24+
const { isEnabled: isDraft } = await draftMode()
25+
26+
if (isDraft) {
1927
return sanityFetch(options)
2028
}
2129

22-
// drafts must stay uncached and keep stega/visual editing support
23-
const { isEnabled: isDraft } = await draftMode()
24-
25-
return isDraft ? sanityFetch(options) : optimizedFetch(options)
30+
return IS_FETCH_OPTIMIZED
31+
? optimizedFetch(options)
32+
: cachedSanityFetch(options)
2633
}

0 commit comments

Comments
 (0)