fix: don't use route changes to clear the navigator, misclearing favicon (#2423)

This commit is contained in:
soxa 2025-08-16 00:59:51 +02:00 committed by GitHub
parent 5f4e7c8a8b
commit 4a83723dbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,5 @@
import { useCallback, useEffect, useRef, useState, startTransition, createContext, useContext } from 'react' import { useCallback, useEffect, useRef, useState, startTransition, createContext, useContext } from 'react'
import styles from './comment.module.css' import styles from './comment.module.css'
import { useRouter } from 'next/router'
import LongPressable from './long-pressable' import LongPressable from './long-pressable'
import { useFavicon } from './favicon' import { useFavicon } from './favicon'
@ -28,7 +27,6 @@ export function useCommentsNavigatorContext () {
} }
export function useCommentsNavigator () { export function useCommentsNavigator () {
const router = useRouter()
const { setHasNewComments } = useFavicon() const { setHasNewComments } = useFavicon()
const [commentCount, setCommentCount] = useState(0) const [commentCount, setCommentCount] = useState(0)
// refs in ref to not re-render on tracking // refs in ref to not re-render on tracking
@ -161,11 +159,10 @@ export function useCommentsNavigator () {
navigatorRef.current = { trackNewComment, untrackNewComment, scrollToComment, clearCommentRefs } navigatorRef.current = { trackNewComment, untrackNewComment, scrollToComment, clearCommentRefs }
} }
// clear the navigator on route changes // clear the navigator on unmount
useEffect(() => { useEffect(() => {
router.events.on('routeChangeStart', clearCommentRefs) return () => clearCommentRefs()
return () => router.events.off('routeChangeStart', clearCommentRefs) }, [clearCommentRefs])
}, [clearCommentRefs, router.events])
return { navigator: navigatorRef.current, commentCount } return { navigator: navigatorRef.current, commentCount }
} }