Skip to content

Commit feecfaf

Browse files
committed
fix: prevent whiteboard data loss on Capture Screen and settings overwrite
- Save whiteboard on unmount (Capture Screen, resize) and visibility change - Merge existing settings when saving App config to avoid overwriting whiteboard/teleprompter Made-with: Cursor
1 parent 0ce829c commit feecfaf

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,7 +2396,9 @@ export default function App() {
23962396

23972397
useEffect(() => {
23982398
if (!settingsLoadedRef.current) return;
2399+
const current = loadSettings();
23992400
saveSettings({
2401+
...current,
24002402
glowColor,
24012403
pipPos,
24022404
fullPagePipPos,

src/components/ExcalidrawBoard.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,17 @@ export function ExcalidrawBoard({ onCanvasLayersChange, onWhiteboardTextureChang
414414

415415
useEffect(() => {
416416
const onBeforeUnload = () => flushPersist();
417+
const onVisibilityChange = () => {
418+
if (document.visibilityState === "hidden") flushPersist();
419+
};
417420
window.addEventListener("beforeunload", onBeforeUnload);
418421
window.addEventListener("pagehide", onBeforeUnload);
422+
document.addEventListener("visibilitychange", onVisibilityChange);
419423
return () => {
420424
window.removeEventListener("beforeunload", onBeforeUnload);
421425
window.removeEventListener("pagehide", onBeforeUnload);
426+
document.removeEventListener("visibilitychange", onVisibilityChange);
427+
flushPersist(); // Save when unmounting (e.g. Capture Screen collapses whiteboard)
422428
};
423429
}, [flushPersist]);
424430

0 commit comments

Comments
 (0)