@@ -153,11 +153,13 @@ export const Notifications = memo(function Notifications() {
153153 const preventZoomRef = usePreventZoom ( )
154154
155155 const [ isPaused , setIsPaused ] = useState ( false )
156+ const isPausedRef = useRef ( false )
156157 const [ exitingIds , setExitingIds ] = useState < Set < string > > ( new Set ( ) )
157158 const timersRef = useRef ( new Map < string , ReturnType < typeof setTimeout > > ( ) )
158159
159160 const pauseAll = useCallback ( ( ) => {
160161 setIsPaused ( true )
162+ isPausedRef . current = true
161163 setExitingIds ( new Set ( ) )
162164 for ( const timer of timersRef . current . values ( ) ) clearTimeout ( timer )
163165 timersRef . current . clear ( )
@@ -167,6 +169,10 @@ export const Notifications = memo(function Notifications() {
167169 * Manages per-notification dismiss timers.
168170 * Resets pause state when the notification stack empties so new arrivals get fresh timers.
169171 */
172+ useEffect ( ( ) => {
173+ isPausedRef . current = isPaused
174+ } , [ isPaused ] )
175+
170176 useEffect ( ( ) => {
171177 if ( visibleNotifications . length === 0 ) {
172178 if ( isPaused ) setIsPaused ( false )
@@ -184,21 +190,17 @@ export const Notifications = memo(function Notifications() {
184190 timers . set (
185191 n . id ,
186192 setTimeout ( ( ) => {
187- setExitingIds ( ( prev ) => new Set ( prev ) . add ( n . id ) )
188- const exitKey = `${ n . id } :exit`
189193 timers . delete ( n . id )
190- timers . set (
191- exitKey ,
192- setTimeout ( ( ) => {
193- timers . delete ( exitKey )
194- removeNotification ( n . id )
195- setExitingIds ( ( prev ) => {
196- const next = new Set ( prev )
197- next . delete ( n . id )
198- return next
199- } )
200- } , EXIT_ANIMATION_MS )
201- )
194+ setExitingIds ( ( prev ) => new Set ( prev ) . add ( n . id ) )
195+ setTimeout ( ( ) => {
196+ if ( isPausedRef . current ) return
197+ removeNotification ( n . id )
198+ setExitingIds ( ( prev ) => {
199+ const next = new Set ( prev )
200+ next . delete ( n . id )
201+ return next
202+ } )
203+ } , EXIT_ANIMATION_MS )
202204 } , AUTO_DISMISS_MS )
203205 )
204206 }
0 commit comments