πŸ‘€ Our most exciting product launch yet πŸš€ Join us May 8th for Sanity Connect

Issues with new document types not showing up in Next.js app using Sanity

10 replies
Last updated: Mar 19, 2024
Using next js (14, app router) and sanity, I seem to be having issues when I create a new document type, add documents and then try to use it in my app straight away. Seems like they don't show up. Toggling on and off the "useCdn" property in the client fixed it when it happened before, but I'm having the same issues again. Anyone know what to do?
Mar 18, 2024, 11:25 AM
big ol' blocker right now which is sad
Mar 18, 2024, 11:34 AM
Is there no way to use something more dynamic when live developing with content?
Mar 18, 2024, 12:48 PM
some kind of "npx sanity-force-refresh"
Mar 18, 2024, 1:08 PM
next js cache issue πŸ™ƒ
//disable caching for development

export const revalidate = 0;
Mar 18, 2024, 1:11 PM
Hello
user N
, same issue here. On Vision I'm abled to query with the latest data, but unfortunatly from NextJs the data is outdated. I tried switching apiVersion and disabling cdn but is still getting old data.
Mar 18, 2024, 5:26 PM
if you're in a next.js app router component, try disabling the cache. worked for me.
Mar 18, 2024, 5:27 PM
is disabled: "useCdn: false,"
Mar 18, 2024, 5:31 PM
that won't disable the next js cache
Mar 18, 2024, 5:47 PM
// page.jsx/tsx
import { client } from "@/lib/client";
import Component from "@/components/component"
// ... other imports

// disable caching for development
export const revalidate = 0;
// ↑ ↑ ↑ ↑ this is what you need @Sergio Vergara 

async function Page() {
  const data = await client.fetch(`*[_type == "post"] | order(order asc)`);

  return (
    <div className="...">
      <Component data={data} />
    </div>
  );
}

export default Page;
Mar 18, 2024, 5:49 PM
It works! Thank you
user N
Mar 19, 2024, 2:23 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?