When using Next.js with MDXRemote and GraphCMS, the content not getting updated after serializing mdxSource might be due to caching. Next.js, by default, caches the output of pages to improve performance. If your content is not updating, it's possible that the cached version is being served, and you're not seeing the latest changes.

To resolve this issue, you can try the following solutions:

  1. Disable Server-Side Caching (Development): When running your Next.js app in development mode, you can disable server-side caching by setting the cache option to "no-cache" for the renderToString function.

    // pages/api/mdx.js (or wherever you're using MDXRemote) import { serialize } from 'next-mdx-remote/serialize'; // ... export default async function handler(req, res) { // Fetch MDX content from GraphCMS or other sources const mdxContent = await fetchMdxContent(); // Serialize MDX content to React components const mdxSource = await serialize(mdxContent); // Disable server-side caching res.setHeader('Cache-Control', 'no-cache'); // Return the serialized MDX content res.status(200).json({ mdxSource }); }

    Note: Disabling caching in development mode can help you see the changes immediately during development. However, in production, you may want to leverage caching for performance reasons.

  2. Purge Cache (Production): If you are running your Next.js app in production, and the content is not updating as expected, it's possible that the previous cached versions are still being served. You can try purging the cache to force Next.js to generate new versions of the pages with the latest content. Most hosting platforms have ways to clear the cache for your application.

  3. Incremental Static Regeneration (ISR): If you are using Next.js' Incremental Static Regeneration feature, consider setting a shorter revalidate time to ensure that the pages are regenerated frequently with the latest content.

  4. Use Preview Mode (if applicable): If your content is being edited in a CMS (e.g., GraphCMS), some CMS platforms offer preview mode. Ensure that you are using the preview mode correctly to see the latest changes in the content before publishing.

Remember that caching can significantly improve the performance of your application, so it's essential to strike a balance between caching for performance benefits and making sure that the latest content is displayed to users when needed.

Have questions or queries?
Get in Touch