From ad6d39ac55bb1e9d2ab9d16ff3e1d4cf0deda71d Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 23 Sep 2026 21:54:33 -0400 Subject: [PATCH] perf: Render simple read-only comments without an editor view (#13871) * perf: Render simple read-only comments without an editor view Read-only editor content made of paragraphs, basic marks, hard breaks, emoji and lists is rendered from the schema DOMSerializer instead of mounting a ProseMirror view per comment. Anything needing a node view or plugin falls back to the full editor. Notification comment previews now use the same read-only path. * fix: Forward className on the static editor path --- app/components/Editor.tsx | 24 +-- .../Notifications/NotificationListItem.tsx | 10 +- app/models/helpers/ProsemirrorHelper.test.ts | 143 ++++++++++++++++ app/models/helpers/ProsemirrorHelper.ts | 73 ++++++++- shared/utils/ProsemirrorHelper.test.ts | 153 ++++-------------- shared/utils/ProsemirrorHelper.ts | 43 ++--- 6 files changed, 278 insertions(+), 168 deletions(-) create mode 100644 app/models/helpers/ProsemirrorHelper.test.ts diff --git a/app/components/Editor.tsx b/app/components/Editor.tsx index 1e2e7c0753..6df4c8ce88 100644 --- a/app/components/Editor.tsx +++ b/app/components/Editor.tsx @@ -7,7 +7,7 @@ import { mergeRefs } from "react-merge-refs"; import type { Optional } from "utility-types"; import EditorContainer from "@shared/editor/components/Styles"; import { AttachmentPreset } from "@shared/types"; -import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper"; +import { ProsemirrorHelper } from "~/models/helpers/ProsemirrorHelper"; import AsyncEditor from "~/components/AsyncEditor"; import ClickablePadding from "~/components/ClickablePadding"; import ErrorBoundary from "~/components/ErrorBoundary"; @@ -200,9 +200,12 @@ function Editor({ ref, ...props }: Props & { ref?: React.Ref }) { [updateComments] ); - const paragraphs = React.useMemo(() => { + // Read-only content that needs no node views or plugins is rendered from + // the schema alone, avoiding an editor view per instance. + const staticHTML = React.useMemo(() => { if (props.readOnly && typeof props.value === "object") { - return ProsemirrorHelper.getPlainParagraphs(props.value); + const node = ProsemirrorHelper.toStaticNode(props.value); + return node ? ProsemirrorHelper.toHTML(node) : undefined; } return undefined; }, [props.readOnly, props.value]); @@ -210,22 +213,21 @@ function Editor({ ref, ...props }: Props & { ref?: React.Ref }) { return ( <> - {paragraphs ? ( + {staticHTML !== undefined ? ( -
- {paragraphs.map((paragraph, index) => ( -

- {paragraph.content?.map((content) => content.text)} -

- ))} -
+
) : ( // The boundary must live between the lazy editor and any ancestor diff --git a/app/components/Notifications/NotificationListItem.tsx b/app/components/Notifications/NotificationListItem.tsx index 104d69a9c8..657a224843 100644 --- a/app/components/Notifications/NotificationListItem.tsx +++ b/app/components/Notifications/NotificationListItem.tsx @@ -64,6 +64,10 @@ function NotificationListItem({ notification, onNavigate }: Props) { [notification] ); const menuAction = useMenuAction(actions); + const commentData = React.useMemo( + () => toJS(notification.comment?.data), + [notification.comment?.data] + ); return ( @@ -82,10 +86,8 @@ function NotificationListItem({ notification, onNavigate }: Props) {