File tree Expand file tree Collapse file tree 3 files changed +32
-15
lines changed
Expand file tree Collapse file tree 3 files changed +32
-15
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { ExcalidrawWrapper } from "./ExcalidrawWrapper";
44import { debounce } from "./utils/debounce" ;
55import { capture } from "./utils/posthog" ;
66import posthog from "./utils/posthog" ;
7+ import { normalizeCanvasData } from "./utils/canvasUtils" ;
78import { useSaveCanvas } from "./api/hooks" ;
89import type * as TExcalidraw from "@atyrode/excalidraw" ;
910import type { NonDeletedExcalidrawElement } from "@atyrode/excalidraw/element/types" ;
@@ -40,20 +41,6 @@ export default function App({
4041 useCustom ( excalidrawAPI , customArgs ) ;
4142 useHandleLibrary ( { excalidrawAPI } ) ;
4243
43- function normalizeCanvasData ( data : any ) {
44- if ( ! data ) return data ;
45- const appState = { ...data . appState } ;
46- appState . width = undefined ;
47- if ( "width" in appState ) {
48- delete appState . width ;
49- }
50- if ( "height" in appState ) {
51- delete appState . height ;
52- }
53- appState . collaborators = new Map ( ) ;
54- return { ...data , appState } ;
55- }
56-
5744 useEffect ( ( ) => {
5845 if ( excalidrawAPI && canvasData ) {
5946 excalidrawAPI . updateScene ( normalizeCanvasData ( canvasData ) ) ;
Original file line number Diff line number Diff line change 11import React , { useState , useCallback } from "react" ;
22import { Dialog } from "@atyrode/excalidraw" ;
33import { useCanvasBackups , CanvasBackup } from "../api/hooks" ;
4+ import { normalizeCanvasData } from "../utils/canvasUtils" ;
45import "../styles/BackupsDialog.scss" ;
56
67interface BackupsModalProps {
@@ -24,7 +25,8 @@ const BackupsModal: React.FC<BackupsModalProps> = ({
2425 const handleRestoreBackup = ( ) => {
2526 if ( selectedBackup && excalidrawAPI ) {
2627 // Load the backup data into the canvas
27- excalidrawAPI . updateScene ( selectedBackup . data ) ;
28+ const normalizedData = normalizeCanvasData ( selectedBackup . data ) ;
29+ excalidrawAPI . updateScene ( normalizedData ) ;
2830 setSelectedBackup ( null ) ;
2931 handleClose ( ) ;
3032 }
Original file line number Diff line number Diff line change 1+ /**
2+ * Normalizes canvas data by removing width and height properties from appState
3+ * and resetting collaborators to an empty Map.
4+ *
5+ * This is necessary when loading canvas data to ensure it fits properly in the current viewport
6+ * and doesn't carry over collaborator information that might be stale.
7+ *
8+ * @param data The canvas data to normalize
9+ * @returns Normalized canvas data
10+ */
11+ export function normalizeCanvasData ( data : any ) {
12+ if ( ! data ) return data ;
13+
14+ const appState = { ...data . appState } ;
15+
16+ // Remove width and height properties
17+ if ( "width" in appState ) {
18+ delete appState . width ;
19+ }
20+ if ( "height" in appState ) {
21+ delete appState . height ;
22+ }
23+
24+ // Reset collaborators (https://github.com/excalidraw/excalidraw/issues/8637)
25+ appState . collaborators = new Map ( ) ;
26+
27+ return { ...data , appState } ;
28+ }
You can’t perform that action at this time.
0 commit comments