Skip to content

Commit

Permalink
BUGFIX: Catch and remove broken settings from localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebobo committed Jul 20, 2023
1 parent be0d524 commit 07766ab
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ export function localStorageEffect<T = any>(
const fullKey = `${STORAGE_PREFIX}.${key}`;
const savedValueJSON = localStorage.getItem(fullKey);
if (savedValueJSON != null) {
let savedValue = JSON.parse(savedValueJSON);
if (validate) {
savedValue = validate(savedValue);
try {
let savedValue = JSON.parse(savedValueJSON);
if (validate) {
savedValue = validate(savedValue);
}
setSelf(savedValue);
} catch (e) {
console.warn(`[MEDIA UI]: Could not parse saved value for stored setting ${fullKey}`);
localStorage.removeItem(fullKey);
}
setSelf(savedValue);
}
onSet((newValue, previousValue: T | undefined, isReset) => {
// Don't write the state in selection screen
Expand Down

0 comments on commit 07766ab

Please sign in to comment.