Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions frontend/src/components/documents/DocumentEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,13 @@ export default function DocumentEditor({ document, onDocumentUpdate, onFetchCont
throw new Error("Excalidraw API not available");
}

// Don't store appState - it's not needed and causes race conditions
const sceneData = {
elements: excalidrawRef.current.getSceneElements(),
files: excalidrawRef.current.getFiles(),
};

// For image generation, we need appState temporarily
const sceneDataWithAppState = {
...sceneData,
appState: excalidrawRef.current.getAppState(),
files: excalidrawRef.current.getFiles(),
};

const b64image = await generateExcalidrawImageBase64(sceneDataWithAppState);
const b64image = await generateExcalidrawImageBase64(sceneData);
contentToSave = {
raw: sceneData,
image: b64image
Expand Down
13 changes: 2 additions & 11 deletions frontend/src/components/editors/ExcalidrawEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ const UIOptions = { canvasActions: { export: false, loadScene: false } }

export default function ExcalidrawEditor({ initialData, onChange, readOnly, excalidrawRef }) {
const { resolvedTheme } = useTheme();
const previousElementsRef = useRef(null);
const previousFilesRef = useRef(null);

const clean = useMemo(() => {
const sanitized = sanitizeInitialData(initialData);
Expand All @@ -86,18 +84,11 @@ export default function ExcalidrawEditor({ initialData, onChange, readOnly, exca
...sanitized,
appState,
};
}, []);
}, [initialData, readOnly, resolvedTheme]);

const handleChange = useCallback((elements, appState, files) => {
if (!readOnly && onChange) {
const elementsChanged = JSON.stringify(elements) !== JSON.stringify(previousElementsRef.current);
const filesChanged = JSON.stringify(files) !== JSON.stringify(previousFilesRef.current);

if (elementsChanged || filesChanged) {
previousElementsRef.current = JSON.parse(JSON.stringify(elements));
previousFilesRef.current = JSON.parse(JSON.stringify(files));
onChange({ elements, files });
}
onChange({ elements, appState, files });
}
}, [readOnly, onChange]);

Expand Down
Loading