fix: apply code review fixes — double layout, SSE leaks, interval leak, conflict values

- App.tsx: remove double-wrapped MainLayout from /notifications route
- NotificationBell.tsx: decouple SSE from popover open state using ref
- useNotifications.ts: fix interval leak in onerror via ref in cleanup
- notifications.controller.ts: unsubscribe on req.on('close') for SSE Subject
- schedules.controller.ts: use existing schedule values in conflict catch
This commit is contained in:
2026-07-05 23:31:21 +08:00
parent 7020e86809
commit 9e6c136ef0
5 changed files with 19 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
import { useState, useEffect, useCallback } from 'react';
import { useState, useEffect, useCallback, useRef } from 'react';
import api from '../api';
interface Notification {
@@ -41,16 +41,18 @@ export function useNotifications() {
}
};
const pollRef = { current: undefined as number | undefined };
es.onerror = () => {
es.close();
const interval = setInterval(() => {
pollRef.current = setInterval(() => {
fetchUnreadCount();
}, 60_000);
return () => clearInterval(interval);
};
return () => {
es.close();
if (pollRef.current !== undefined) clearInterval(pollRef.current);
};
}, [fetchUnreadCount]);