From adc11aee9fd917d9b78f804aac704f20005f79c8 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 25 Oct 2025 17:05:19 +0200 Subject: [PATCH] chore: More sidebar performance fixes (#10470) --- .../Sidebar/components/DocumentLink.tsx | 98 +++++++++++-------- app/models/Collection.ts | 5 +- app/models/Document.ts | 4 +- app/models/base/Model.ts | 4 +- 4 files changed, 64 insertions(+), 47 deletions(-) diff --git a/app/components/Sidebar/components/DocumentLink.tsx b/app/components/Sidebar/components/DocumentLink.tsx index 251858080c..3106d6fed1 100644 --- a/app/components/Sidebar/components/DocumentLink.tsx +++ b/app/components/Sidebar/components/DocumentLink.tsx @@ -326,6 +326,62 @@ function InnerDocumentLink( const contextMenuAction = useDocumentMenuAction({ documentId: node.id }); + const labelElement = React.useMemo( + () => ( + + ), + [title, handleTitleChange, isEditing, setIsEditing, canUpdate] + ); + + const menuElement = React.useMemo( + () => + document && !isMoving && !isEditing && !isDraggingAnyDocument ? ( + + {can.createChildDocument && ( + + { + ev.preventDefault(); + setIsAddingNewChild(); + setExpanded(); + }} + > + + + + )} + + + ) : undefined, + [ + document, + isMoving, + isEditing, + isDraggingAnyDocument, + can.createChildDocument, + t, + setIsAddingNewChild, + setExpanded, + handleRename, + handleMenuOpen, + handleMenuClose, + ] + ); + return ( - } + label={labelElement} isActive={isActiveCheck} isActiveDrop={isOverReparent && canDropToReparent} depth={depth} @@ -370,35 +416,7 @@ function InnerDocumentLink( scrollIntoViewIfNeeded={sidebarContext === "collections"} isDraft={isDraft} ref={ref} - menu={ - document && - !isMoving && - !isEditing && - !isDraggingAnyDocument ? ( - - {can.createChildDocument && ( - - { - ev.preventDefault(); - setIsAddingNewChild(); - setExpanded(); - }} - > - - - - )} - - - ) : undefined - } + menu={menuElement} /> diff --git a/app/models/Collection.ts b/app/models/Collection.ts index a4c062301c..4983570d00 100644 --- a/app/models/Collection.ts +++ b/app/models/Collection.ts @@ -1,5 +1,5 @@ import invariant from "invariant"; -import { action, computed, observable, runInAction } from "mobx"; +import { action, comparer, computed, observable, runInAction } from "mobx"; import { CollectionPermission, FileOperationFormat, @@ -16,7 +16,6 @@ import { client } from "~/utils/ApiClient"; import User from "./User"; import Field from "./decorators/Field"; import { AfterChange } from "./decorators/Lifecycle"; -import isEqual from "lodash/isEqual"; export default class Collection extends ParanoidModel { static modelName = "Collection"; @@ -157,7 +156,7 @@ export default class Collection extends ParanoidModel { return this.sort.field === "index"; } - @computed({ equals: isEqual }) + @computed({ equals: comparer.structural }) get sortedDocuments(): NavigationNode[] | undefined { if (!this.documents) { return undefined; diff --git a/app/models/Document.ts b/app/models/Document.ts index a55f906a63..30cce9e593 100644 --- a/app/models/Document.ts +++ b/app/models/Document.ts @@ -2,7 +2,7 @@ import { addDays, differenceInDays } from "date-fns"; import i18n, { t } from "i18next"; import capitalize from "lodash/capitalize"; import floor from "lodash/floor"; -import { action, autorun, computed, observable, set } from "mobx"; +import { action, autorun, comparer, computed, observable, set } from "mobx"; import type { JSONObject, NavigationNode, @@ -652,7 +652,7 @@ export default class Document extends ArchivableModel implements Searchable { ); } - @computed + @computed({ equals: comparer.structural }) get asNavigationNode(): NavigationNode { return { type: NavigationNodeType.Document, diff --git a/app/models/base/Model.ts b/app/models/base/Model.ts index 0872cc361c..b5f862ce09 100644 --- a/app/models/base/Model.ts +++ b/app/models/base/Model.ts @@ -1,5 +1,5 @@ import pick from "lodash/pick"; -import { observable, action } from "mobx"; +import { observable, action, toJS } from "mobx"; import { JSONObject } from "@shared/types"; import type Store from "~/stores/base/Store"; import Logger from "~/utils/Logger"; @@ -148,7 +148,7 @@ export default abstract class Model { continue; } // @ts-expect-error TODO - if (isEqual(this[key], data[key])) { + if (isEqual(toJS(this[key]), data[key])) { continue; } // @ts-expect-error TODO