mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 23:55:20 +00:00
Fix caching strategy for icon fetching (#4289)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user