From 33b9a52dfec538efaf4cf0b1d0b6eb8a67c0a5d2 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 29 Mar 2026 10:36:43 -0400 Subject: [PATCH] fix: Empty drafts are not correctly cleared on tab quit (#11899) dquote> fix: Existing drafts should not focus the editor --- .../Document/components/Comments/CommentForm.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/scenes/Document/components/Comments/CommentForm.tsx b/app/scenes/Document/components/Comments/CommentForm.tsx index 1688aff140..ba571cf002 100644 --- a/app/scenes/Document/components/Comments/CommentForm.tsx +++ b/app/scenes/Document/components/Comments/CommentForm.tsx @@ -103,6 +103,11 @@ function CommentForm({ useOnClickOutside(formRef, reset); + React.useEffect(() => { + window.addEventListener("beforeunload", reset); + return () => window.removeEventListener("beforeunload", reset); + }, [reset]); + const handleCreateComment = action(async (event: React.FormEvent) => { event.preventDefault(); @@ -254,11 +259,13 @@ function CommentForm({ const handleMounted = React.useCallback( (ref) => { if (autoFocus && ref && !hasFocusedOnMount.current) { - ref.focusAtStart(); + if (!draft) { + ref.focusAtStart(); + } hasFocusedOnMount.current = true; } }, - [autoFocus] + [autoFocus, draft] ); const presence = animatePresence