chore(SW-663): updated @contentstack/live-preview-utils to latest

This commit is contained in:
Erik Tiekstra
2024-11-07 13:29:12 +01:00
parent 953f860e5d
commit d8751b3fea
8 changed files with 109 additions and 63 deletions

View File

@@ -1,6 +1,5 @@
import "server-only"
// import { ContentstackLivePreview } from "@contentstack/live-preview-utils"
import { ClientError, GraphQLClient } from "graphql-request"
import { Lang } from "@/constants/languages"

View File

@@ -4,7 +4,7 @@ import { GraphQLClient } from "graphql-request"
import { cache } from "react"
import { env } from "@/env/server"
import { getPreviewHash, isPreview } from "@/lib/previewContext"
import { getPreviewHash, isPreviewByUid } from "@/lib/previewContext"
import { request as _request } from "./_request"
@@ -15,10 +15,13 @@ export async function request<T>(
variables?: Record<string, any>,
params?: RequestInit
): Promise<Data<T>> {
const shouldUsePreview = isPreview(variables?.uid)
const shouldUsePreview = variables?.uid
? isPreviewByUid(variables.uid)
: false
const previewHash = getPreviewHash()
const cmsUrl = shouldUsePreview ? env.CMS_PREVIEW_URL : env.CMS_URL
// Creating a new client for each request to avoid conflicting parameters
const client = new GraphQLClient(cmsUrl, {
fetch: cache(async function (url: URL | RequestInfo, params?: RequestInit) {
const wrappedFetch = fetchRetry(fetch, {