Skip to content

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

web: improve app performance by reducing react rerenders

Abdullah Attad0fceed56d1b
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index 98ffd4cfe..5e4156d16 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -87,7 +87,6 @@ function saveContent(noteId: string, ignoreEdit: boolean, content: string) {
const deferredSave = debounceWithId(saveContent, 100);
export default function TabsView() {
- const sessions = useEditorStore((store) => store.sessions);
const documentPreview = useEditorStore((store) => store.documentPreview);
const activeSessionId = useEditorStore((store) => store.activeSessionId);
const arePropertiesVisible = useEditorStore(
@@ -96,6 +95,7 @@ export default function TabsView() {
const isTOCVisible = useEditorStore((store) => store.isTOCVisible);
const [dropRef, overlayRef] = useDragOverlay();
+ const sessions = useEditorStore.getState().sessions;
return (
<>
{IS_DESKTOP_APP ? (
diff --git a/apps/web/src/components/note/index.tsx b/apps/web/src/components/note/index.tsx
index d01d90eb2..6fd23bd41 100644
--- a/apps/web/src/components/note/index.tsx
+++ b/apps/web/src/components/note/index.tsx
@@ -282,7 +282,8 @@ export default React.memo(Note, function (prevProps, nextProps) {
prevProps.notebooks?.dateEdited === nextProps.notebooks?.dateEdited &&
prevProps.tags?.dateEdited === nextProps.tags?.dateEdited &&
prevProps.reminder?.dateModified === nextProps.reminder?.dateModified &&
- prevProps.attachments === nextProps.attachments &&
+ prevProps.attachments?.failed === nextProps.attachments?.failed &&
+ prevProps.attachments?.total === nextProps.attachments?.total &&
prevProps.locked === nextProps.locked
);
});
diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.ts
index b832d1f39..2fa21455d 100644
--- a/apps/web/src/stores/editor-store.ts
+++ b/apps/web/src/stores/editor-store.ts
@@ -438,7 +438,11 @@ class EditorStore extends BaseStore<EditorStore> {
if (index === -1) return;
const session = state.sessions[index] as SessionTypeMap[T[number]];
if (typeof partial === "function") partial(session);
- else state.sessions[index] = { ...session, ...partial };
+ else {
+ for (const key in partial) {
+ session[key] = partial[key] as any;
+ }
+ }
});
};