sanity-io / next-sanity

Sanity.io toolkit for Next.js

Home Page:https://www.sanity.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

for some reason it seems my data isn't updating both in production and development

geraldAp opened this issue · comments

import { groq } from "next-sanity";
import { client } from "./lib/client";
import { Leaders , Service, BlogData, Blog } from "@/utils/Types";
// leaders
export async function getLeaders() : Promise<Leaders[]> {
const data = await client.fetch(
groq*[_type == "leader"] | order(_createdAt asc) { _id, name, jobDescription, leaderBio, 'leaderImage': leaderImage.asset->url, },
{
next: {revalidate : 30}
}
)
return data
}
// services
export async function getServices() : Promise<Service[]> {
const data = await client.fetch(

    groq`*[_type == "service"]{
        _id,
        title,
        "slug": slug.current,
        summary,
        'serviceImage': serviceImage.asset->url
    }`
    , {
         next: {revalidate : 30}
    }
)

return data

}
// get a single service
export async function getService(slug: string) : Promise {
const data = await client.fetch(
groq*[_type == "service" && slug.current == $slug][0]{ _id, title, "slug": slug.current, description, 'serviceImage': serviceImage.asset->url }, {
slug,
}
)

return data

}
// get all blogs
export async function getBlogs() : Promise {
const data = await client.fetch(
groq*[_type == "post"] | order(_createdAt desc){ _id, title, publishedAt, body, "author": author->name, "slug": slug.current, "mainImage": mainImage.asset->url } , {
next: {revalidate : 30}
}
)

type firstDataType = typeof data[0]
const firstData: firstDataType = data[0]
return { data, firstData }

}
// get a single blogs
export async function getBlog(slug: string) : Promise {
const data = await client.fetch(
groq*[_type == "post" && slug.current == $slug ][0]{ _id, title, publishedAt, body, "author": author->name, "slug": slug.current, "mainImage": mainImage.asset->url } , {
slug,
}
)
return data
}

queried my data just fine but still when i update see no updates and i tried changing the revalidition approches force dynamic works but even that the changes aren't fast and i have to reload so many times. I have used hygraph cms and it was fine for me why is sanity and next doing me like this ?

I am also having major updates getting the production cache to refresh. It seems like it appeared a few weeks ago. Of all the caching mechanisms I have in sanity and nextjs, I am starting to suspect there might be an issue in this library. I wish that vercel, sanity or the author of this library were to give us simple guidelines for how to update our data. This is maddening!

honestly and It won't sit well with my clients if they try updating data and it doesn't show

I don't think the collaborative parties between nextjs and sanity know how big of a deal this is. Rebuilding the app used to clear the data cache, now it doesn't. This is a big problem! Until we can figure out a better way (next: revalidate does not seem to work and no-store does not seem to work either) you can manually clear the cache in the Vercel dashboard.

Hi,

This library is only using native fetch under the hood and forwards headers such as next.revalidate to the underlying fetch method. We don't have any next specific logic that interacts with the cache.

In a sense, doing this:

const data = await client.fetch(groq, params, {next: {revalidate: 30}})

Is functionally equivalent to:

const {result} = await fetch(`https://api.sanity.io/...`, {next: {revalidate: 30}})

There's not much we can do on our side, we recommend you open an issue at: https://github.com/vercel/next.js/issues/new/choose

hmmmmmmmmmmmmmmmmmm

so ideally how would you have gone about it ?

Great thanks for the clarification. It appears to me these fetch options simply don't work. I will follow further in the nextjs side