Prismic API returning stale data

Describe your question/issue in detail

Hello Prismic Team!
I use a Prismic API link to retrieve content from our Prismic repository (things like articles, information about companies, etc). I then serve that content via our client using Next.JS.

I have noticed that some of my API information is up-to-date, while the information in other places is stale info -- for instance, one section of the website is showing the newest information on a company, whereas a different website is showing old information for that company (e.g. image links, title, etc).

I have checked that I am using up-to-date CDN links ({repo}.cdn.prismic.io/api/v2) and I am quite sure I do not have two versions of the same documents. Can you advise on what could be causing this?

Impacted feature

API CDN

What steps have you taken to resolve this issue already?

Update document
Unpublish and republish document
local debugging

Errors

None

Your Role

Sole Developer

Hosting provider

Vercel

Package.json file

{
"name": "thom",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"slicemachine": "start-slicemachine"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.2.1",
"@fortawesome/free-brands-svg-icons": "^6.3.0",
"@fortawesome/free-solid-svg-icons": "^6.2.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"@next/font": "13.1.0",
"@piwikpro/next-piwik-pro": "^1.0.4",
"@piwikpro/react-piwik-pro": "^1.1.1",
"@prismicio/client": "^7.0.0",
"@prismicio/next": "^1.5.0",
"@prismicio/react": "^2.7.4",
"@prismicio/slice-simulator-react": "^0.2.3",
"eslint": "8.30.0",
"eslint-config-next": "13.1.0",
"lodash": "^4.17.21",
"next": "13.4.5",
"next-transpile-modules": "^10.0.0",
"prismic-javascript": "^3.0.2",
"pure-react-carousel": "^1.30.1",
"react": "18.2.0",
"react-countup": "^6.4.1",
"react-dom": "18.2.0",
"react-fast-marquee": "^1.3.5",
"react-icons": "^4.7.1",
"react-marquee-slider": "^1.1.5",
"react-responsive": "^9.0.2",
"react-transition-group": "^4.4.5",
"styled-components": "^5.3.9"
},
"devDependencies": {
"@prismicio/types": "^0.2.7",
"slice-machine-ui": "^0.7.1"
}
}

Steps to reproduce

Simply fetching data and returning via a CreateClient endpoint seems to be causing the issue. The section with outdated info uses this:

  const endpoint = "https://thomnext.cdn.prismic.io/api/v2";
  const token = process.env.TOKEN;
  const client = prismic.createClient(endpoint, { accessToken: token });

Whereas the section with updated info uses this context instead:

  // Fetch companies
  const companyResponse = await client.getByType('company', { pageSize: 100 });
  const companies = companyResponse.results;

  // Fetch a specific page by UID
  const page = await client.getByUID('pageh', params.uid);

  return {
    props: {
      page,
      articles,
      team,
      companies
    }
  };
}

export async function getStaticPaths() {
  const client = createClient();
  const pages = await client.getByType('pageh');

  return {
    paths: pages.results.map(page => {
      return { params: { uid: page.uid } }
    }),
    fallback: false
  };
}

const Page = ({ page, articles, team, companies }) => {
  return (
    <SliceZone 
      slices={page.data.slices} 
      components={components} 
      context={{ "articles": articles, "team": team, "companies": companies }}
    />
  );
}

Hi Harry,

My first thought is that this sounds like a caching problem with Vercel.

Can you check out this thread for solutions?

Thanks.

Hello Phil,
I have indeed checked this out. I have added that env var to Vercel and rebuilt, by triggering the webhook from Prismic and from Vercel. I also want to let you know, this error does not just happen in production - it happens in my local environment as well.

Is there a possibility that one of the methods I mentioned in the post is grabbing the oldest version, and then not updating it? What else could be the cause, any ideas? I'd be happy to share the GitHub repo with the file name and file numbers if necessary, or any other snippets that may be helpful.

Hi again @Phil just wanted to bump this, the solutions in the thread did not solve the issue. Do you have any other suggestions on what might cause this? Do the different retrieval mechanisms get different versions in the content history or something?

Hi Harry,

Sorry I've been backed up busy.

If this is only happening locally try deleting you .next file in your project and working from there.

Maybe there's an unintentional cache of the master ref set-up.

You can always very the API is sending the latest data by checking your API browser:
https://your-repo-name.cdn.prismic.io/api/v2

You can also see what the latest master ref is there and cross reference with your project.

My feeling is that there is a cache somewhere happening.

Hi @Phil ,

No worries, I know how it goes. This is not only happening locally -- this is happening in my production environment. I have my site deployed via Vercel and have ensured the cache setting indicated in the linked thread is set correctly.

Is there any other place where the data might be cached? Is there any API-side caching or version history that might be sending me to older versions?

This can be closed, Phil - it was user error on the editor side :sweat_smile:

1 Like