From fd73a9912be485fb1c8fed147ada94e1c142eace Mon Sep 17 00:00:00 2001 From: conico974 Date: Mon, 8 Jun 2026 13:46:32 +0200 Subject: [PATCH] Fix caching strategy for icon fetching (#4289) --- packages/gitbook/src/lib/icons/inline.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/gitbook/src/lib/icons/inline.ts b/packages/gitbook/src/lib/icons/inline.ts index d24108348..fef583074 100644 --- a/packages/gitbook/src/lib/icons/inline.ts +++ b/packages/gitbook/src/lib/icons/inline.ts @@ -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; } }