From 3b57ce7c89b656f39c663b840d97786f59f28781 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Fri, 3 Jul 2026 21:12:09 +0100 Subject: [PATCH] fix: comment error boundary --- .../public/locales/en-US/translation.json | 1 + .../src/components/layouts/global/aside.tsx | 7 +++- .../comment/components/comment-dialog.tsx | 19 ++++++---- .../comment/components/comment-editor.tsx | 26 ++++++------- .../components/comment-error-boundary.tsx | 38 +++++++++++++++++++ 5 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 apps/client/src/features/comment/components/comment-error-boundary.tsx diff --git a/apps/client/public/locales/en-US/translation.json b/apps/client/public/locales/en-US/translation.json index 6a7f600d1..333282a12 100644 --- a/apps/client/public/locales/en-US/translation.json +++ b/apps/client/public/locales/en-US/translation.json @@ -83,6 +83,7 @@ "Failed to restore page": "Failed to restore page", "Failed to fetch recent pages": "Failed to fetch recent pages", "Failed to import pages": "Failed to import pages", + "Failed to load comments. An error occurred.": "Failed to load comments. An error occurred.", "Failed to load page. An error occurred.": "Failed to load page. An error occurred.", "Failed to update data": "Failed to update data", "Failed to create base": "Failed to create base", diff --git a/apps/client/src/components/layouts/global/aside.tsx b/apps/client/src/components/layouts/global/aside.tsx index 556adbf17..47ac46c11 100644 --- a/apps/client/src/components/layouts/global/aside.tsx +++ b/apps/client/src/components/layouts/global/aside.tsx @@ -1,6 +1,7 @@ import { ActionIcon, Box, Group, ScrollArea, Title, Tooltip } from "@mantine/core"; import { IconX } from "@tabler/icons-react"; import CommentListWithTabs from "@/features/comment/components/comment-list-with-tabs.tsx"; +import { CommentErrorBoundary } from "@/features/comment/components/comment-error-boundary.tsx"; import { useAtom } from "jotai"; import { asideStateAtom } from "@/components/layouts/global/hooks/atoms/sidebar-atom.ts"; import React, { ReactNode, useEffect } from "react"; @@ -28,7 +29,11 @@ export default function Aside() { switch (tab) { case "comments": - component = ; + component = ( + + + + ); title = "Comments"; break; case "toc": diff --git a/apps/client/src/features/comment/components/comment-dialog.tsx b/apps/client/src/features/comment/components/comment-dialog.tsx index 6eadc86a6..32350b3bf 100644 --- a/apps/client/src/features/comment/components/comment-dialog.tsx +++ b/apps/client/src/features/comment/components/comment-dialog.tsx @@ -11,6 +11,7 @@ import { } from "@/features/comment/atoms/comment-atom"; import CommentEditor from "@/features/comment/components/comment-editor"; import CommentActions from "@/features/comment/components/comment-actions"; +import { CommentErrorBoundary } from "@/features/comment/components/comment-error-boundary"; import { currentUserAtom } from "@/features/user/atoms/current-user-atom"; import { useCreateCommentMutation } from "@/features/comment/queries/comment-query"; import { asideStateAtom } from "@/components/layouts/global/hooks/atoms/sidebar-atom"; @@ -170,14 +171,16 @@ function CommentDialog({ editor, pageId, readOnly }: CommentDialogProps) { - - + + + + ); diff --git a/apps/client/src/features/comment/components/comment-editor.tsx b/apps/client/src/features/comment/components/comment-editor.tsx index d9ad96675..e75ac08a5 100644 --- a/apps/client/src/features/comment/components/comment-editor.tsx +++ b/apps/client/src/features/comment/components/comment-editor.tsx @@ -6,13 +6,9 @@ import { Color } from "@tiptap/extension-color"; import { Mention, LinkExtension, - CustomTable, - TableRow, - TableCell, - TableHeader, - TableView, TiptapImage, SharedStorage, + Attachment, } from "@docmost/editor-ext"; import ImageView from "@/features/editor/components/image/image-view"; import classes from "./comment.module.css"; @@ -24,6 +20,8 @@ import EmojiCommand from "@/features/editor/extensions/emoji-command"; import mentionRenderItems from "@/features/editor/components/mention/mention-suggestion"; import MentionView from "@/features/editor/components/mention/mention-view"; import { platformModifierKey } from "@/lib"; +import { TableKit } from "@tiptap/extension-table"; +import AttachmentView from "@/features/editor/components/attachment/attachment-view.tsx"; interface CommentEditorProps { defaultContent?: any; @@ -81,14 +79,11 @@ const CommentEditor = forwardRef( return ReactNodeViewRenderer(MentionView); }, }), - SharedStorage, - CustomTable.configure({ - resizable: false, - View: TableView, + TableKit, + Attachment.configure({ + view: AttachmentView, }), - TableRow, - TableCell, - TableHeader, + SharedStorage, TiptapImage.configure({ view: ImageView, allowBase64: false, @@ -139,7 +134,12 @@ const CommentEditor = forwardRef( // websocket on another browser). Skip for editable editors to avoid // resetting the cursor position on every keystroke. useEffect(() => { - if (!editable && commentEditor && !commentEditor.isDestroyed && defaultContent) { + if ( + !editable && + commentEditor && + !commentEditor.isDestroyed && + defaultContent + ) { commentEditor.commands.setContent(defaultContent); } }, [defaultContent, editable, commentEditor]); diff --git a/apps/client/src/features/comment/components/comment-error-boundary.tsx b/apps/client/src/features/comment/components/comment-error-boundary.tsx new file mode 100644 index 000000000..a99c0da66 --- /dev/null +++ b/apps/client/src/features/comment/components/comment-error-boundary.tsx @@ -0,0 +1,38 @@ +import { ReactNode } from "react"; +import { ErrorBoundary } from "react-error-boundary"; +import { Button } from "@mantine/core"; +import { IconAlertTriangle } from "@tabler/icons-react"; +import { useTranslation } from "react-i18next"; +import { EmptyState } from "@/components/ui/empty-state.tsx"; + +type CommentErrorBoundaryProps = { + children: ReactNode; +}; + +// Contain comment-editor render throws (e.g. schema errors) so they don't unmount the whole app. +export function CommentErrorBoundary({ children }: CommentErrorBoundaryProps) { + const { t } = useTranslation(); + + return ( + ( + + {t("Try again")} + + } + /> + )} + > + {children} + + ); +}