Skip to content

Commit

Permalink
🐛 shield localStorage and window objects
Browse files Browse the repository at this point in the history
  • Loading branch information
astoilkov committed Jun 6, 2024
1 parent 18ece4c commit d2c05e1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/utils/savedAvailableLengthGuess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export default function savedAvailableLengthGuess(): number {
function updateAvailableLength() {
if (isDevToolsOpen()) {
const length = guessAvailableLength();
localStorage.setItem(STORAGE_KEY, String(length));
try {
localStorage.setItem(STORAGE_KEY, String(length));
} catch {}
}
}

Expand All @@ -30,4 +32,6 @@ function isDevToolsOpen(): boolean {
}

updateAvailableLength();
window.addEventListener("resize", updateAvailableLength);
if (typeof window !== "undefined") {
window.addEventListener("resize", updateAvailableLength);
}

0 comments on commit d2c05e1

Please sign in to comment.