fix(m12): IdeaTimeline auto-refresh on new idea-questions

The /ideas/[id]?tab=timeline page is server-rendered: questions are a
prop snapshot. Without a router.refresh, new questions only show after a
manual page reload — and during a grill-session that's every ~20s.

Fix: in use-notifications-realtime, after dispatching idea-question
events to idea-store + re-syncing the bell, call \`router.refresh()\`.
This re-runs the server-component for whichever page the user is on; on
/ideas/[id] it pulls the new question. On other pages it's a no-op (no
visible state change).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Janpeter Visser 2026-05-05 13:44:15 +02:00
parent 4a86910e66
commit 5793afc709

View file

@ -11,6 +11,7 @@
'use client' 'use client'
import { useEffect, useRef } from 'react' import { useEffect, useRef } from 'react'
import { useRouter } from 'next/navigation'
import { useNotificationsStore, type NotificationQuestion } from '@/stores/notifications-store' import { useNotificationsStore, type NotificationQuestion } from '@/stores/notifications-store'
import { useIdeaStore } from '@/stores/idea-store' import { useIdeaStore } from '@/stores/idea-store'
@ -66,6 +67,7 @@ export function useNotificationsRealtime() {
const sourceRef = useRef<EventSource | null>(null) const sourceRef = useRef<EventSource | null>(null)
const backoffRef = useRef<number>(BACKOFF_START_MS) const backoffRef = useRef<number>(BACKOFF_START_MS)
const reconnectTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null) const reconnectTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const router = useRouter()
useEffect(() => { useEffect(() => {
const init = useNotificationsStore.getState().init const init = useNotificationsStore.getState().init
@ -146,6 +148,11 @@ export function useNotificationsRealtime() {
} else { } else {
remove(payload.id) remove(payload.id)
} }
// M12 hotfix: refresh de current page (server-component) zodat de
// IdeaTimeline-tab op /ideas/[id] de nieuwe vraag oppikt zonder
// dat de gebruiker handmatig moet refreshen. Geen-op als de
// gebruiker elders zit; goedkoop genoeg om altijd te triggeren.
router.refresh()
return return
} }