also untrack descendants of an outlined new comment; micro-optimize classList logic (#2463)

This commit is contained in:
soxa 2025-08-29 20:26:46 +02:00 committed by GitHub
parent 6f67aaaef9
commit 4ff3dfa412
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -117,15 +117,18 @@ export default function Comment ({
const unsetOutline = () => { const unsetOutline = () => {
if (!ref.current) return 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 const classes = ref.current.classList
if (hasOutline && !hasOutlineUnset) { const hasOutline = classes.contains('outline-new-comment')
ref.current.classList.add('outline-new-comment-unset') const hasInjectedOutline = classes.contains('outline-new-injected-comment')
// untrack the new comment const hasOutlineUnset = classes.contains('outline-new-comment-unset')
navigator?.untrackNewComment(ref)
} // 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(() => { useEffect(() => {