Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excalidraw file modified by MetaEdit while drawing causes loss of data #50

Closed
zsviczian opened this issue Dec 11, 2021 · 4 comments · Fixed by #56
Closed

Excalidraw file modified by MetaEdit while drawing causes loss of data #50

zsviczian opened this issue Dec 11, 2021 · 4 comments · Fixed by #56

Comments

@zsviczian
Copy link

Please see this issue raised by @zhl111 for Excalidraw #296.

@zhl111 singled out MetaEdit as the root cause of the data loss by way of elimination... i.e. turning off plugins one-by-one until only MetaEdit was left.

I haven't done detailed testing, however, my assumptions are the following:

  • It seems that while editing an Excalidraw drawing somehow MetaEdit is triggered. This could be linked to Excalidraw autosave.
  • When MetaEdit is triggered, it probably modifies the excalidraw.md file, which in turn is interpreted by Excalidraw as a trigger to reload the drawing. Note, that I monitor background file changes to allow use-cases such as editing the same file side by side in markdown mode and in drawing mode, as well as to handle file sync events, such as when using Obsidian sync.

I recommend adding the following logic to onFileModify() (and potentially other relevant functions) avoid this issue:
if (app.workspace.activeLeaf.view.getViewType()==="excalidraw") return;

@chhoumann
Copy link
Owner

Hey @zsviczian, thank you very much for reporting this!

This onFileModify function helps facilitate a queue, and by rejecting the active pane rather than the file that the event regards, possible issues can occur.

I've made a fix, but it depends on metadata in Excalidraw files. Does Excalidraw files always have a metadata key with Excalidraw in the name?

const metadata = await this.app.metadataCache.getFileCache(outfile);
const keys = Object.keys(metadata?.frontmatter);
if (keys && keys.some(key => key.toLowerCase().contains("excalidraw"))) {
    return;
}

@zsviczian
Copy link
Author

zsviczian commented Jan 19, 2022 via email

chhoumann added a commit that referenced this issue Jan 21, 2022
@m-paul
Copy link

m-paul commented Mar 1, 2022

I'm encountering an exception attributed to this code change here. Looks like when OnFileModifyAutomatorManager.onFileModify is called, the object returned from this.app.metadataCache.getFileCache(outfile) doesn't always have a frontmatter property, which results in uncaught in promise excpetion TypeError: Cannot convert undefined or null to object when the next line is called.

@zsviczian
Copy link
Author

It seems metachache is updated asynchronously.

This is my isExcalidraw() function. I do check if frontmatter exists...

https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/857f41ad0710d4708e815eeecb3435f425cf71ce/src/main.ts#L1791-L1797

on a related note, I have a separate event handler to monitor metachache changes and to maintain a list of Excalidraw drawings:

https://github.com/zsviczian/obsidian-excalidraw-plugin/blob/857f41ad0710d4708e815eeecb3435f425cf71ce/src/main.ts#L1493-L1529

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants