Skip to content

Commit 731a03b

Browse files
committed
fix: graceful handling of localStorage quota exceeded
When tree is too large (>5-10MB), localStorage.setItem throws QuotaExceededError. This change: - Shows clearer warning message instead of error - Falls back to memory-only storage (window.treeData) - Clears localStorage cache to free space - Doesn't affect functionality - tree still works in memory
1 parent 1389b39 commit 731a03b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/hooks/useTree.jsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,20 @@ export const useTree = (currentUser) => {
453453
window.treeData = tree;
454454
}
455455
} catch (error) {
456-
console.error("Failed to save tree to localStorage:", error);
456+
// QuotaExceededError: Tree too large for localStorage
457+
// Not critical - tree is still in memory and available via window.treeData
458+
if (error.name === 'QuotaExceededError') {
459+
console.warn('⚠️ Tree too large for localStorage cache, using memory only');
460+
// Still make it globally available for reminder monitor
461+
window.treeData = tree;
462+
// Clear the cached data to free up space
463+
try {
464+
localStorage.removeItem("cached_tree_data");
465+
localStorage.removeItem(LOCAL_STORAGE_KEY);
466+
} catch (e) {}
467+
} else {
468+
console.error("Failed to save tree to localStorage:", error);
469+
}
457470
}
458471
}, [tree]);
459472
useEffect(() => {

0 commit comments

Comments
 (0)