From 7426ed785fcdad5ca9968a082eed5ecb8a374db5 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 14 Dec 2025 17:10:18 -0500 Subject: [PATCH] fix: New comment auto-focus (#10911) * refactor * fix: autoFocus on comment editor --- app/components/AuthenticatedLayout.tsx | 2 +- .../Notifications/NotificationListItem.tsx | 2 +- .../components/{ => Comments}/CommentEditor.tsx | 0 .../components/{ => Comments}/CommentForm.tsx | 17 +++++++++-------- .../{ => Comments}/CommentSortMenu.tsx | 0 .../components/{ => Comments}/CommentThread.tsx | 0 .../{ => Comments}/CommentThreadItem.tsx | 0 .../components/{ => Comments}/Comments.tsx | 4 ++-- .../components/{ => Comments}/HighlightText.ts | 0 9 files changed, 13 insertions(+), 12 deletions(-) rename app/scenes/Document/components/{ => Comments}/CommentEditor.tsx (100%) rename app/scenes/Document/components/{ => Comments}/CommentForm.tsx (97%) rename app/scenes/Document/components/{ => Comments}/CommentSortMenu.tsx (100%) rename app/scenes/Document/components/{ => Comments}/CommentThread.tsx (100%) rename app/scenes/Document/components/{ => Comments}/CommentThreadItem.tsx (100%) rename app/scenes/Document/components/{ => Comments}/Comments.tsx (99%) rename app/scenes/Document/components/{ => Comments}/HighlightText.ts (100%) diff --git a/app/components/AuthenticatedLayout.tsx b/app/components/AuthenticatedLayout.tsx index 5cd459dcac..c4898c6321 100644 --- a/app/components/AuthenticatedLayout.tsx +++ b/app/components/AuthenticatedLayout.tsx @@ -32,7 +32,7 @@ import { PortalContext } from "./Portal"; import CommandBar from "./CommandBar"; const DocumentComments = lazyWithRetry( - () => import("~/scenes/Document/components/Comments") + () => import("~/scenes/Document/components/Comments/Comments") ); const DocumentHistory = lazyWithRetry( () => import("~/scenes/Document/components/History") diff --git a/app/components/Notifications/NotificationListItem.tsx b/app/components/Notifications/NotificationListItem.tsx index 2641436d73..2c2b98521d 100644 --- a/app/components/Notifications/NotificationListItem.tsx +++ b/app/components/Notifications/NotificationListItem.tsx @@ -15,7 +15,7 @@ import { UnreadBadge } from "../UnreadBadge"; import lazyWithRetry from "~/utils/lazyWithRetry"; const CommentEditor = lazyWithRetry( - () => import("~/scenes/Document/components/CommentEditor") + () => import("~/scenes/Document/components/Comments/CommentEditor") ); type Props = { diff --git a/app/scenes/Document/components/CommentEditor.tsx b/app/scenes/Document/components/Comments/CommentEditor.tsx similarity index 100% rename from app/scenes/Document/components/CommentEditor.tsx rename to app/scenes/Document/components/Comments/CommentEditor.tsx diff --git a/app/scenes/Document/components/CommentForm.tsx b/app/scenes/Document/components/Comments/CommentForm.tsx similarity index 97% rename from app/scenes/Document/components/CommentForm.tsx rename to app/scenes/Document/components/Comments/CommentForm.tsx index 6b4bde99b3..907e041861 100644 --- a/app/scenes/Document/components/CommentForm.tsx +++ b/app/scenes/Document/components/Comments/CommentForm.tsx @@ -25,6 +25,7 @@ import useStores from "~/hooks/useStores"; import { Bubble } from "./CommentThreadItem"; import { HighlightedText } from "./HighlightText"; import lazyWithRetry from "~/utils/lazyWithRetry"; +import { mergeRefs } from "react-merge-refs"; const CommentEditor = lazyWithRetry(() => import("./CommentEditor")); @@ -247,15 +248,15 @@ function CommentForm({ } }; - // Focus the editor when it's a new comment just mounted, after a delay as the - // editor is mounted within a fade transition. - React.useEffect(() => { - setTimeout(() => { + // Focus the editor when it's a new comment just mounted + const handleMounted = React.useCallback( + (ref) => { if (autoFocus) { - editorRef.current?.focusAtStart(); + ref?.focusAtStart(); } - }, 0); - }, [autoFocus]); + }, + [autoFocus] + ); const presence = animatePresence ? { @@ -310,7 +311,7 @@ function CommentForm({ )}