Frontend Architecture Audit
Issues Identified
1. Excessive Polling & "Thundering Herd" Problems
The frontend makes aggressive use of setInterval across multiple components to fetch data (e.g., EmergencyPage, GossipGraph). In some areas, these intervals interact poorly with retry logic.
useCommandApiStatus.js: Contained a critical bug wheresetIntervalcontinued running even after the backend was marked offline, whilesetTimeoutretry logic concurrently fired. This created exponential background polling, degrading browser performance and network availability.
2. State Leaks on Unmounted Components
AlertFeed.jsx: Inside asetIntervalloop, asetTimeoutwas used to delay a state update. The interval was cleared on unmount, but the timeout was not, leading to React state updates on an unmounted component.
3. Missing Event Listener Cleanup
continuousPlatformService.js: Functions likebindWsPollListenersattach globalwindowanddocumentevent listeners (e.g.,visibilitychange,cepheus:vision-ws-open). Although structured as singletons, lack of explicitremoveEventListenercan cause issues during HMR or if the app's initialization cycle runs multiple times.
4. Direct Mutation of Global State
GossipGraph.jsx: Manual mutations of thezustandstore variables (e.g.,faceRes[camId] = ...) were spotted instead of using immutable updates. This can cause components relying on those specific slices of state to bypass re-renders or suffer from tearing.
Recommendations
- Consolidate polling loops into the central WebSocket (
wsVisionSingleton.js). - Always return a cleanup function in
useEffectthat clears all asynchronous boundaries (setTimeoutandsetInterval). - Switch to structured state updaters via
zustandactions rather than shallow copying and mutating nested store objects.