A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: fix editor rerendering on session type change from new to default (#7759)
Ammar Ahmed8df7b5c56b74
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsxindex 88c9b15f2..3645da838 100644--- a/apps/web/src/components/editor/index.tsx+++ b/apps/web/src/components/editor/index.tsx@@ -224,13 +224,14 @@ export default function TabsView() {);}-const MemoizedEditorView = React.memo(- EditorView,- (prev, next) =>+const MemoizedEditorView = React.memo(EditorView, (prev, next) => {+ return (prev.session.id === next.session.id &&- prev.session.type === next.session.type &&- prev.session.needsHydration === next.session.needsHydration-);+ (prev.session.type === next.session.type ||+ (prev.session.type === "new" && next.session.type === "default")) &&+ !!prev.session.needsHydration === !!next.session.needsHydration+ );+});function EditorView({session}: {@@ -251,10 +252,14 @@ function EditorView({const event = db.eventManager.subscribe(EVENTS.syncItemMerged,async (item?: MaybeDeletedItem<Item>) => {+ const defaultSession = session as DefaultEditorSession;+ const sessionType = useEditorStore+ .getState()+ .getSession(defaultSession.id)?.type;if (- session.type === "new" ||+ sessionType === "new" ||!editor ||- !session.note ||+ !defaultSession.note ||!item ||isDeleted(item) ||(item.type !== "tiptap" && item.type !== "note") ||@@ -265,8 +270,9 @@ function EditorView({}const isContent =- item.type === "tiptap" && item.noteId === session.note.id;- const isNote = item.type === "note" && item.id === session.note.id;+ item.type === "tiptap" && item.noteId === defaultSession.note.id;+ const isNote =+ item.type === "note" && item.id === defaultSession.note.id;if (isContent && lastChangedTime.current < item.dateModified) {if (!item.locked) return editor.updateContent(item.data);@@ -275,7 +281,7 @@ function EditorView({.catch(() => EV.publish(EVENTS.vaultLocked));if (!result) return;editor.updateContent(result.data);- } else if (isNote && session.note.title !== item.title) {+ } else if (isNote && defaultSession.note.title !== item.title) {AppEventManager.publish(AppEvents.changeNoteTitle, {sessionId: session.id,title: item.title,diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.tsindex 9ed54a412..cc261a093 100644--- a/apps/web/src/stores/editor-store.ts+++ b/apps/web/src/stores/editor-store.ts@@ -910,8 +910,8 @@ class EditorStore extends BaseStore<EditorStore> {ignoreEdit?: boolean;}) => {- const currentSession = this.getSession(id, ["new", "default"]);- if (!currentSession) return;+ const session = this.getSession(id, ["new", "default"]);+ if (!session) return;// do not allow saving of readonly sessionif (partial.note?.readonly) return;@@ -919,6 +919,13 @@ class EditorStore extends BaseStore<EditorStore> {await saveMutex.runExclusive(async () => {this.setSaveState(id, 0);try {+ // Get session again as it might have changed to default.+ const currentSession =+ session.type === "new"+ ? this.getSession(id, ["new", "default"])+ : session;++ if (!currentSession) return;const sessionId = getSessionId(currentSession);let noteId ="note" in currentSession ? currentSession.note.id : partial.note?.id;@@ -1041,8 +1048,8 @@ class EditorStore extends BaseStore<EditorStore> {this.setSaveState(id, SaveState.NotSaved);console.error(err);if (err instanceof Error) logger.error(err);- if (isLockedSession(currentSession) && "note" in currentSession) {- this.get().openSession(currentSession.note, { force: true });+ if (isLockedSession(session) && "note" in session) {+ this.get().openSession(session.note, { force: true });}}});