From 226c8dacfb6291cff0ab03a47f7acc3cd116c1e1 Mon Sep 17 00:00:00 2001 From: perf3ct Date: Fri, 9 May 2025 16:35:26 +0000 Subject: [PATCH] fix(client): try to resolve the edit/readonly race condition --- apps/client/src/components/note_context.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/apps/client/src/components/note_context.ts b/apps/client/src/components/note_context.ts index 6c93fcc5b..6a984fc0b 100644 --- a/apps/client/src/components/note_context.ts +++ b/apps/client/src/components/note_context.ts @@ -260,6 +260,20 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded"> return true; } + // Before checking size for auto read-only status, + // ensure any pending changes are saved to prevent data loss + if (this.ntxId && (this.note.type === "text" || this.note.type === "code")) { + try { + // Trigger the same event that's used when switching notes, which already + // has the implementation to save pending changes + await appContext.triggerEvent("beforeNoteSwitch", { noteContext: this }); + } catch (e) { + console.debug("Error saving pending changes before read-only check:", e); + // Continue with the check even if saving fails + } + } + + // Now that we've saved any pending changes, get the updated blob size const blob = await this.note.getBlob(); if (!blob) { return false;