improvement(sockets): cleanup debounce logic + add flush mechanism to…#1152
improvement(sockets): cleanup debounce logic + add flush mechanism to…#1152icecrasher321 merged 4 commits intostagingfrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR implements a comprehensive refactor of the socket operation management system to address data loss issues during workflow transitions. The changes replace component-level debouncing with a centralized operation queue system that provides robust flushing mechanisms.
The core architectural improvement is the replacement of simple timeout-based debouncing with a more sophisticated system that stores pending operations alongside their timeouts. The operation queue store now maintains PendingDebouncedOperation objects that contain both the timeout reference and the actual operation data, enabling recovery of pending operations that would previously be lost during navigation or page refreshes.
Key changes include:
- Centralized debouncing: Removed
debounceMsparameters from individual components like the Code component'suseSubBlockValuehook, consolidating all debouncing logic into the operation queue store - Operation flushing mechanisms: Added
flushAllDebounced(),flushDebouncedForBlock(),flushDebouncedForWorkflow(), andflushDebouncedForVariable()methods to immediately process pending operations before workflow switches or page unloads - Enhanced data persistence: Integrated flush calls into critical navigation points including the beforeUnload handler, socket context workflow switching, and input component blur events
- Workflow-aware processing: Implemented priority-based operation processing that favors operations for the currently registered workflow, improving performance in multi-workflow environments
- Cleanup mechanisms: Added
cancelOperationsForWorkflow()to properly clean up operations when leaving workflows
The refactor removes a complex global window-based subblock update mechanism from the collaborative workflow system, replacing it with the more reliable operation queue approach. This eliminates potential race conditions and memory leaks while providing better maintainability.
Confidence score: 4/5
- This PR addresses a real data loss issue with a well-architected solution that centralizes operation management
- Score reflects the comprehensive nature of changes across multiple critical files in the collaborative editing system
- Pay close attention to the operation queue store implementation and socket context changes as these handle the core data persistence logic
8 files reviewed, 2 comments
simstudioai#1152) * improvement(sockets): cleanup debounce logic + add flush mechanism to not lose ops * fix optimistic update overwritten race condition * fix * fix forever stuck in processing
Summary
Sockets server cleanup of unused fields debouncedMs. Add operation flushing capability to not lose operations on switching workflows or quick refresh.
Type of Change
Testing
Tested persistence, quick switching of workflows + refresh after long copying of ops.
Checklist