diff --git a/src/mdx.ts b/src/mdx.ts index acfd29534dbfaa..169bd8492cbb55 100644 --- a/src/mdx.ts +++ b/src/mdx.ts @@ -531,26 +531,41 @@ export async function getFileBySlug(slug: string): Promise { const outdir = path.join(root, 'public', 'mdx-images'); await mkdir(outdir, {recursive: true}); + // If the file contains content that depends on the Release Registry (such as an SDK's latest version), avoid using the cache for that file, i.e. always rebuild it. + // This is because the content from the registry might have changed since the last time the file was cached. + // If a new component that injects content from the registry is introduced, it should be added to the patterns below. + const skipCache = + source.includes('@inject') || + source.includes('(cacheFile), - cp(assetsCacheDir, outdir, {recursive: true}), - ]); - return cached; - } catch (err) { - if ( - err.code !== 'ENOENT' && - err.code !== 'ABORT_ERR' && - err.code !== 'Z_BUF_ERROR' - ) { - // If cache is corrupted, ignore and proceed - // eslint-disable-next-line no-console - console.warn(`Failed to read MDX cache: ${cacheFile}`, err); + try { + const [cached, _] = await Promise.all([ + readCacheFile(cacheFile), + cp(assetsCacheDir, outdir, {recursive: true}), + ]); + return cached; + } catch (err) { + if ( + err.code !== 'ENOENT' && + err.code !== 'ABORT_ERR' && + err.code !== 'Z_BUF_ERROR' + ) { + // If cache is corrupted, ignore and proceed + // eslint-disable-next-line no-console + console.warn(`Failed to read MDX cache: ${cacheFile}`, err); + } } } } @@ -685,7 +700,7 @@ export async function getFileBySlug(slug: string): Promise { }, }; - if (assetsCacheDir && cacheFile) { + if (assetsCacheDir && cacheFile && !skipCache) { await cp(assetsCacheDir, outdir, {recursive: true}); writeCacheFile(cacheFile, JSON.stringify(resultObj)).catch(e => { // eslint-disable-next-line no-console