Fix caching strategy for icon fetching (#4289)

This commit is contained in:
conico974
2026-06-08 13:46:32 +02:00
committed by GitHub
parent 595435ac4a
commit fd73a9912b
+4 -1
View File
@@ -234,7 +234,7 @@ async function getInlineIconSource(
fetch(getIconAssetURL(style, icon), {
// There is no benefit in caching this in Vercel, as we already cache in the Runtime Cache.
cache:
process.env.GITBOOK_RUNTIME === 'cloudflare' ? 'force-cache' : 'no-cache',
process.env.GITBOOK_RUNTIME === 'cloudflare' ? 'force-cache' : 'no-store',
}).then(async (response) => {
if (!response.ok) {
throw new Error('Failed to fetch icon');
@@ -248,6 +248,9 @@ async function getInlineIconSource(
return await request;
} catch {
console.warn(`Failed to fetch icon ${icon} with style ${style} after multiple attempts`);
// We don't want to store failed attempts in the cache. Otherwise it may crash subsequent attempts to fetch the same icon and will crash the entire page
// It's very visible in dev, where the map will stay around
rawSvgPromises.delete(cacheKey);
return null;
}
}