Skip to content

Commit

Permalink
Add try catch in FluentDesignTheme to prevent crash on invalid localS…
Browse files Browse the repository at this point in the history
…torage (#2204)
  • Loading branch information
MarvinKlein1508 authored Jun 19, 2024
1 parent a64ff6a commit f87ecab
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ export function addThemeChangeEvent(dotNetHelper, id) {
}
});

const theme = element.themeStorage.readLocalStorage()
return theme == null ? theme : JSON.stringify(theme);
try {
// This can fail when localStorage does not contain a valid JSON object
const theme = element.themeStorage.readLocalStorage()
return theme == null ? theme : JSON.stringify(theme);
} catch (error) {
ClearLocalStorage(id);
console.error(`FluentDesignTheme: failing to load theme from localStorage.`, error);
}

}

return null;
Expand Down

0 comments on commit f87ecab

Please sign in to comment.