@ -76,16 +59,28 @@ export function NotificationProvider({ children }: { children: React.ReactNode }
active
active
])
])
// Defer so we don't trigger state updates during the same commit as consumer renders (avoids "Cannot update NotificationList while rendering NotificationProvider")
useEffect(()=>{
useEffect(()=>{
lett2: ReturnType<typeofsetTimeout>|null=null
constt=setTimeout(()=>{
setNewNotifications([])
setNewNotifications([])
t2=setTimeout(()=>{
updateNotificationsSeenAt(!active)
updateNotificationsSeenAt(!active)
},[active])
},0)
},0)
return()=>{
clearTimeout(t)
if(t2!==null)clearTimeout(t2)
}
},[active,updateNotificationsSeenAt])
useEffect(()=>{
useEffect(()=>{
if(!pubkey)return
if(!pubkey)return
constdeferredReset=setTimeout(()=>{
setNewNotifications([])
setNewNotifications([])
setReadNotificationIdSet(newSet())
setReadNotificationIdSet(newSet())
},0)
// Track if component is mounted
// Track if component is mounted
constisMountedRef={current: true}
constisMountedRef={current: true}
@ -262,6 +257,7 @@ export function NotificationProvider({ children }: { children: React.ReactNode }
// Cleanup function
// Cleanup function
return()=>{
return()=>{
clearTimeout(deferredReset)
isMountedRef.current=false
isMountedRef.current=false
if(subCloserRef.current){
if(subCloserRef.current){
subCloserRef.current.close()
subCloserRef.current.close()
@ -322,7 +318,7 @@ export function NotificationProvider({ children }: { children: React.ReactNode }
}
}
},[filteredNewNotifications])
},[filteredNewNotifications])
constgetNotificationsSeenAt=()=>{
constgetNotificationsSeenAt=useCallback(()=>{
if(notificationsSeenAt>=0){
if(notificationsSeenAt>=0){
returnnotificationsSeenAt
returnnotificationsSeenAt
}
}
@ -330,25 +326,34 @@ export function NotificationProvider({ children }: { children: React.ReactNode }