I’m having trouble with my NextJS blog that uses the Notion API for content. It’s weird because everything works fine on my local machine. I can make changes in Notion and see them right away. But when I deploy to Vercel, it’s like the app is stuck. The changes I make in Notion don’t show up on the live site. I’ve tried deploying straight from Vercel instead of going through Github, but no luck. Here’s a simplified version of my code:
I encountered a similar issue with my NextJS app on Vercel using the Notion API. The problem turned out to be caching. Vercel caches API responses by default, which can cause delays in reflecting Notion updates.
To fix this, I added a revalidation strategy to my pages. In your getStaticProps function, try adding a revalidate property:
This tells Next.js to regenerate the page after 60 seconds if a request comes in. You can adjust the time based on how frequently you update your content.
Also, make sure your environment variables are correctly set in Vercel. Sometimes, issues can arise from mismatched API keys between local and production environments.
If the problem persists, you might want to implement ISR (Incremental Static Regeneration) or switch to getServerSideProps for more dynamic content fetching.
Have you considered the potential impact of Vercel’s edge caching on your application? This could be the root cause of your sync issues. To address this, you might want to implement a custom caching strategy or utilize Vercel’s on-demand Incremental Static Regeneration (ISR).
For a quick fix, try adding cache-control headers to your API routes:
export default async function handler(req, res) {
res.setHeader('Cache-Control', 's-maxage=1, stale-while-revalidate');
// Your existing code here
}
This instructs Vercel to revalidate the cache more frequently. Additionally, ensure your Notion integration token has the correct permissions and is properly set in your Vercel environment variables. If the problem persists, you might need to investigate Vercel’s function logs for any API-related errors.