From ea33810a4fd5325c8903273a32b848ac12af9775 Mon Sep 17 00:00:00 2001 From: Keith Morris Date: Wed, 31 Dec 2025 17:41:52 -0500 Subject: [PATCH] fix: add error handling and cleanup for draggable handle - Add try-catch for localStorage JSON.parse to handle corrupted data - Remove invalid localStorage key when parsing fails - Add cleanup effect to reset body styles if component unmounts while dragging --- src/components/QuickSettingsPanel.jsx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/QuickSettingsPanel.jsx b/src/components/QuickSettingsPanel.jsx index 6b70412..75f8f24 100644 --- a/src/components/QuickSettingsPanel.jsx +++ b/src/components/QuickSettingsPanel.jsx @@ -43,8 +43,14 @@ const QuickSettingsPanel = ({ const [handlePosition, setHandlePosition] = useState(() => { const saved = localStorage.getItem('quickSettingsHandlePosition'); if (saved) { - const parsed = JSON.parse(saved); - return parsed.y; + try { + const parsed = JSON.parse(saved); + return parsed.y ?? 50; + } catch { + // Remove corrupted data + localStorage.removeItem('quickSettingsHandlePosition'); + return 50; + } } return 50; // Default to 50% (middle of screen) }); @@ -153,6 +159,17 @@ const QuickSettingsPanel = ({ document.body.style.width = ''; }, []); + // Cleanup body styles on unmount in case component unmounts while dragging + useEffect(() => { + return () => { + document.body.style.cursor = ''; + document.body.style.userSelect = ''; + document.body.style.overflow = ''; + document.body.style.position = ''; + document.body.style.width = ''; + }; + }, []); + // Set up global event listeners for drag useEffect(() => { if (dragStartY !== 0) {