From 4ff3dfa4129c36d871aa636432550294315447eb Mon Sep 17 00:00:00 2001 From: soxa <6390896+Soxasora@users.noreply.github.com> Date: Fri, 29 Aug 2025 20:26:46 +0200 Subject: [PATCH] also untrack descendants of an outlined new comment; micro-optimize classList logic (#2463) --- components/comment.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/components/comment.js b/components/comment.js index 6c4c9019..633b855c 100644 --- a/components/comment.js +++ b/components/comment.js @@ -117,15 +117,18 @@ export default function Comment ({ const unsetOutline = () => { if (!ref.current) return - const hasOutline = ref.current.classList.contains('outline-new-comment') || ref.current.classList.contains('outline-new-injected-comment') - const hasOutlineUnset = ref.current.classList.contains('outline-new-comment-unset') - // don't try to unset the outline if the comment is not outlined or we already unset the outline - if (hasOutline && !hasOutlineUnset) { - ref.current.classList.add('outline-new-comment-unset') - // untrack the new comment - navigator?.untrackNewComment(ref) - } + const classes = ref.current.classList + const hasOutline = classes.contains('outline-new-comment') + const hasInjectedOutline = classes.contains('outline-new-injected-comment') + const hasOutlineUnset = classes.contains('outline-new-comment-unset') + + // don't try to untrack and unset the outline if the comment is not outlined or we already unset the outline + if (!(hasInjectedOutline || hasOutline) || hasOutlineUnset) return + + classes.add('outline-new-comment-unset') + // untrack new comment and its descendants if it's not a live comment + navigator?.untrackNewComment(ref, { includeDescendants: hasOutline }) } useEffect(() => {