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({ )}