fix(client): try to resolve the edit/readonly race condition

This commit is contained in:
perf3ct 2025-05-09 16:35:26 +00:00
parent 3b7285ba5d
commit 226c8dacfb
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232

View File

@ -260,6 +260,20 @@ class NoteContext extends Component implements EventListener<"entitiesReloaded">
return true; 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(); const blob = await this.note.getBlob();
if (!blob) { if (!blob) {
return false; return false;