From d123e5e35b64ee8594f0713537c91d193ed19b61 Mon Sep 17 00:00:00 2001 From: imperosol Date: Wed, 6 May 2026 12:39:27 +0200 Subject: [PATCH] fix: `QuotaExceededError` on user pictures load --- sas/static/bundled/sas/user/pictures-index.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/sas/static/bundled/sas/user/pictures-index.ts b/sas/static/bundled/sas/user/pictures-index.ts index d4c75f17..c9e67eeb 100644 --- a/sas/static/bundled/sas/user/pictures-index.ts +++ b/sas/static/bundled/sas/user/pictures-index.ts @@ -35,8 +35,23 @@ document.addEventListener("alpine:init", () => { // biome-ignore lint/style/useNamingConvention: from python api query: { users_identified: [config.userId] }, } as PicturesFetchPicturesData); - localStorage.setItem(localStorageInvalidationKey, config.nbPictures.toString()); - localStorage.setItem(localStorageKey, JSON.stringify(pictures)); + try { + localStorage.setItem(localStorageInvalidationKey, config.nbPictures.toString()); + localStorage.setItem(localStorageKey, JSON.stringify(pictures)); + } catch { + // an exception is raised if the localstorage is entirely filled + // so just delete all cached user pictures. + // A cache hit is not worth the page breaking. + Object.keys(localStorage) + .filter( + (key) => + key.startsWith("user") && + (key.endsWith("Pictures") || key.endsWith("PicturesNumber")), + ) + .forEach((key) => { + localStorage.removeItem(key); + }); + } return pictures; },