chore: More sidebar performance fixes (#10470)

This commit is contained in:
Tom Moor authored and GitHub committed 2025-10-25 15:05:19 +00:00
1 parent 7ab247f367
commit adc11aee9f
4 files changed
+64 -47

No files matched your search

@@ -326,6 +326,62 @@ function InnerDocumentLink(
const contextMenuAction = useDocumentMenuAction({ documentId: node.id });
const labelElement = React.useMemo(
() => (
<EditableTitle
title={title}
onSubmit={handleTitleChange}
isEditing={isEditing}
onEditing={setIsEditing}
canUpdate={canUpdate}
maxLength={DocumentValidation.maxTitleLength}
ref={editableTitleRef}
/>
),
[title, handleTitleChange, isEditing, setIsEditing, canUpdate]
);
const menuElement = React.useMemo(
() =>
document && !isMoving && !isEditing && !isDraggingAnyDocument ? (
<Fade>
{can.createChildDocument && (
<Tooltip content={t("New doc")}>
<NudeButton
aria-label={t("New nested document")}
onClick={(ev) => {
ev.preventDefault();
setIsAddingNewChild();
setExpanded();
}}
>
<PlusIcon />
</NudeButton>
</Tooltip>
)}
<DocumentMenu
document={document}
onRename={handleRename}
onOpen={handleMenuOpen}
onClose={handleMenuClose}
/>
</Fade>
) : undefined,
[
document,
isMoving,
isEditing,
isDraggingAnyDocument,
can.createChildDocument,
t,
setIsAddingNewChild,
setExpanded,
handleRename,
handleMenuOpen,
handleMenuClose,
]
);
return (
<ActionContextProvider
value={{
@@ -351,17 +407,7 @@ function InnerDocumentLink(
contextAction={contextMenuAction}
to={toPath}
icon={iconElement}
label={
<EditableTitle
title={title}
onSubmit={handleTitleChange}
isEditing={isEditing}
onEditing={setIsEditing}
canUpdate={canUpdate}
maxLength={DocumentValidation.maxTitleLength}
ref={editableTitleRef}
/>
}
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 ? (
<Fade>
{can.createChildDocument && (
<Tooltip content={t("New doc")}>
<NudeButton
aria-label={t("New nested document")}
onClick={(ev) => {
ev.preventDefault();
setIsAddingNewChild();
setExpanded();
}}
>
<PlusIcon />
</NudeButton>
</Tooltip>
)}
<DocumentMenu
document={document}
onRename={handleRename}
onOpen={handleMenuOpen}
onClose={handleMenuClose}
/>
</Fade>
) : undefined
}
menu={menuElement}
/>
</DropToImport>
</div>
+2 -3
View File
@@ -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;
+2 -2
View File
@@ -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,
+2 -2
View File
@@ -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