Skip to content

Fix Force favicon refresh with cache-busting for notification state (Safari compatibility) #2264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions components/nav/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,24 @@ export function NavSelect ({ sub: subName, className, size }) {
export function NavNotifications ({ className }) {
const hasNewNotes = useHasNewNotes()

useEffect(() => {
const setFavicon = (href) => {
// Remove all existing favicon link tags
const links = document.querySelectorAll('link[rel="icon"], link[rel="shortcut icon"]')
links.forEach(link => link.parentNode.removeChild(link))
// Create new favicon link with cache-busting query
const link = document.createElement('link')
link.rel = 'shortcut icon'
link.type = 'image/png'
link.href = href + '?v=' + Date.now()
document.head.appendChild(link)
}
setFavicon(hasNewNotes ? '/favicon-notify.png' : '/favicon.png')
}, [hasNewNotes])

return (
<>
{/* fallback for SSR, but will be replaced on client by useEffect */}
<Head>
<link rel='shortcut icon' href={hasNewNotes ? '/favicon-notify.png' : '/favicon.png'} />
</Head>
Expand Down