Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(sync): keep the tree alive for notes not yet synced
Elian Doran46ff48ccdfa6
diff --git a/apps/client/src/entities/fnote.spec.ts b/apps/client/src/entities/fnote.spec.tsindex 9644d05fd0..4638ba5f3e 100644--- a/apps/client/src/entities/fnote.spec.ts+++ b/apps/client/src/entities/fnote.spec.ts@@ -1226,6 +1226,16 @@ describe("FNote system-note predicates", () => {expect(note.getScriptEnv()).toBeNull();});+ it("title stays a string when a note row arrives without a title", () => {+ const note = makeNote({ title: "Real title" });++ // The same skeleton row as above; `NoteTreeWidget.getTitleHtml()` passes the title to+ // `escapeHtml()`, which calls `.replace()` on it.+ note.update({ noteId: note.noteId, blobId: "blob1", isProtected: false } as unknown as FNoteRow);++ expect(note.title).toBe("");+ });+it("getScriptEnv returns frontend / backend / null", () => {expect(makeNote({ type: "code", mime: "text/html" }).getScriptEnv()).toBe("frontend");expect(makeNote({ type: "code", mime: "application/javascript;env=frontend" }).getScriptEnv()).toBe("frontend");diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.tsindex 6b130f9090..fb7b6906ca 100644--- a/apps/client/src/entities/fnote.ts+++ b/apps/client/src/entities/fnote.ts@@ -94,14 +94,14 @@ export default class FNote {update(row: FNoteRow) {this.noteId = row.noteId;- this.title = row.title;this.isProtected = !!row.isProtected;this.type = row.type;- // The server can send a row without a mime: becca materialises "skeleton" notes for- // entities that arrive out of order during sync, and their undefined mime/title are dropped- // outright by JSON serialisation. Defaulting keeps the mime predicates (isTriliumScript(),- // isJavaScript(), ...) from throwing until the real row syncs in.+ // The server can send a row without a mime or title: becca materialises "skeleton" notes+ // for entities that arrive out of order during sync, and JSON serialisation drops their+ // undefined mime/title. Defaulting keeps the mime predicates (isTriliumScript(), ...) and+ // title consumers (escapeHtml() in the tree) from throwing until the real row syncs in.+ this.title = row.title ?? "";this.mime = row.mime ?? "";this.blobId = row.blobId;