fix: don't use route changes to clear the navigator, misclearing favicon (#2423)
This commit is contained in:
parent
5f4e7c8a8b
commit
4a83723dbf
@ -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 }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user