fix: add idle watcher interval cleanup and resource management#5769
fix: add idle watcher interval cleanup and resource management#5769DhyaniKavya wants to merge 1 commit intosugarlabs:masterfrom
Conversation
- Store interval ID in _idleWatcherIntervalId property - Store reset handler in _resetIdleTimer for cleanup - Prevent duplicate intervals with clearInterval check - Add cleanupIdleWatcher() method to remove interval and event listeners - No behavior changes to idle detection or FPS throttling
|
✅ All Jest tests passed! This PR is ready to merge. |
|
@DhyaniKavya @vanshika2720 what do you think? |
There was a problem hiding this comment.
@DhyaniKavya this is duplicate of PR #5770
please close this .
|
@vanshika2720 Just thinking from a maintainability point of view. |
|
@vanshika2720 sure , i am closing this PR. Forgot to close it before. Thankyou |
issue : #5768
Problem:-
The idle watcher in js/activity.js creates a setInterval that runs every second to monitor inactivity and adjust the frame rate. The interval ID is not stored, and the activity reset event listeners are attached using a handler reference that cannot be removed.
As a result:
-the interval cannot be cleared if the activity is reinitialized
-duplicate intervals could accumulate in future lifecycle scenarios
-event listeners cannot be removed during teardown
-unnecessary resource usage may occur in long sessions or development reloads
-While this does not cause immediate user-visible errors, it represents incomplete lifecycle and resource management.
Solution:-
-This PR enables proper lifecycle cleanup while preserving all existing behavior:
-stores the idle watcher interval ID
-prevents duplicate intervals from being created
-stores the reset handler for listener removal
-adds a cleanup method to remove the interval and listeners
-does not change idle detection logic or behavior
Changes Made:-
-File modified:
->js/activity.js
->store interval ID for cleanup
->prevent duplicate interval creation
->store reset handler reference
->add cleanupIdleWatcher() method for lifecycle cleanup
Testing Performed:-
-Manual Verification
-Idle throttling activates after inactivity
-Frame rate restores on activity
-Playback and interaction behavior unchanged
-No console errors observed
-Automated Testing
Jest: ✅ all tests passed⚠️ pre-existing repository configuration warning (no new lint errors introduced)
Prettier: ✅ formatting verified
ESLint:
Impact:-
-Improves resource and lifecycle management
-Prevents duplicate idle watcher intervals
-Enables safe cleanup for future modularization and testing
-Improves maintainability and long-session efficiency
-No breaking changes
Notes:-
This change is intentionally minimal and non-breaking. The cleanup method is opt-in and does not alter current behavior. It provides proper lifecycle handling for future use cases such as testing, development reloads, or modular integration.
Happy to adjust if maintainers prefer a different approach.