Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: add tracing to debug empty content on save issue

Abdullah Attaece5b56bdd04
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index 8eb9a8e83..201ffe509 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -68,10 +68,16 @@ import { showNoteLinkingDialog } from "../../common/dialog-controller";
import { scrollIntoViewById } from "@notesnook/editor";
import { IEditor } from "./types";
import { EditorActionBar } from "./action-bar";
+import { logger } from "../../utils/logger";
const PDFPreview = React.lazy(() => import("../pdf-preview"));
function saveContent(noteId: string, ignoreEdit: boolean, content: string) {
+ logger.debug("saving content", {
+ noteId,
+ ignoreEdit,
+ length: content.length
+ });
useEditorStore.getState().saveSessionContent(noteId, ignoreEdit, {
type: "tiptap",
data: content
@@ -310,6 +316,10 @@ function EditorView({
const data = content();
if (!session.content) session.content = { type: "tiptap", data };
else session.content.data = data;
+ logger.debug("scheduling save", {
+ id: session.id,
+ length: data.length
+ });
deferredSave(session.id, session.id, ignoreEdit, data);
}}
options={{
diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts
index 23b3bc0f4..f92dd1bb3 100644
--- a/apps/web/src/stores/editor-store.ts
+++ b/apps/web/src/stores/editor-store.ts
@@ -702,12 +702,19 @@ class EditorStore extends BaseStore<EditorStore> {
const sessionId = getSessionId(currentSession);
if (isLockedSession(currentSession) && partial.content) {
+ logger.debug("Saving locked content", { id });
+
await db.vault.save({
content: partial.content,
sessionId,
id
});
} else {
+ if (partial.content)
+ logger.debug("Saving content", {
+ id,
+ length: partial.content.data.length
+ });
await db.notes.add({
...partial.note,
dateEdited:
diff --git a/packages/core/src/collections/content.ts b/packages/core/src/collections/content.ts
index 5068640f2..643993f1b 100644
--- a/packages/core/src/collections/content.ts
+++ b/packages/core/src/collections/content.ts
@@ -35,6 +35,7 @@ import { InternalLink } from "../utils/internal-link";
import { tinyToTiptap } from "../migrations";
import { EVENTS } from "../common";
import { DeleteEvent, UpdateEvent } from "../database";
+import { logger } from "../logger";
export const EMPTY_CONTENT = (noteId: string): UnencryptedContentItem => ({
noteId,
@@ -82,6 +83,7 @@ export class Content implements ICollection {
if (content.noteId && !content.id) {
// find content from noteId
+ logger.debug("finding content id", { id: content.noteId });
content.id = (
await this.db
.sql()
@@ -112,6 +114,13 @@ export class Content implements ICollection {
? { locked: false as const, data: unencryptedData }
: undefined;
+ if (contentData)
+ logger.debug("updating content", {
+ id: content.noteId,
+ contentId: content.id,
+ length: JSON.stringify(contentData.data).length
+ });
+
await this.collection.update([content.id], {
dateEdited: content.dateEdited,
localOnly: content.localOnly,
@@ -147,6 +156,12 @@ export class Content implements ICollection {
: { locked: false, data: unencryptedData || "<p></p>" })
};
+ logger.debug("inserting content", {
+ id: content.noteId,
+ contentId: content.id,
+ length: JSON.stringify(contentItem.data).length
+ });
+
await this.collection.upsert(contentItem);
if (content.sessionId)
diff --git a/packages/core/src/collections/notes.ts b/packages/core/src/collections/notes.ts
index 54b3de7b0..fc0abcb28 100644
--- a/packages/core/src/collections/notes.ts
+++ b/packages/core/src/collections/notes.ts
@@ -30,6 +30,7 @@ import { ICollection } from "./collection";
import { NoteContent } from "./session-content";
import { SQLCollection } from "../database/sql-collection";
import { isFalse } from "../database";
+import { logger } from "../logger";
export type ExportOptions = {
format: "html" | "md" | "txt" | "md-frontmatter";
@@ -79,6 +80,7 @@ export class Notes implements ICollection {
let headline = item.headline;
if (item.content && item.content.data && item.content.type) {
+ logger.debug("saving content", { id });
const { type, data } = item.content;
const content = getContentFromData(type, data);