-
Notifications
You must be signed in to change notification settings - Fork 115
fix: prevent user actions from being blocked by event filtering optimizations #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…izations When optimistic updates back up with slow sync responses, rapid user actions on the same key would get filtered out by recentlySyncedKeys logic, causing UI to stop responding. This change distinguishes between user-triggered and sync-triggered recomputations to prevent blocking legitimate user actions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🦋 Changeset detectedLatest commit: 5340138 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@tanstack/db-example-react-todo @tanstack/db
@tanstack/electric-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: +40 B (+0.07%) Total Size: 58.1 kB
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 1.05 kB ℹ️ View Unchanged
|
…atching This fix resolves a critical issue where rapid user interactions (like clicking multiple checkboxes) would cause the UI to become unresponsive when optimistic updates backed up with slow sync responses. ## Root Cause Analysis The issue had two main components: 1. **Event Filtering Problem**: User actions on recently synced keys were being filtered out by `recentlySyncedKeys` logic, which was designed to prevent duplicate sync events but was incorrectly blocking legitimate user actions. 2. **Batching Problem**: Once sync transactions started, `shouldBatchEvents` would become true, causing all subsequent events (including user actions) to be batched instead of immediately updating the UI, making it appear frozen. ## Solution 1. **Added `triggeredByUserAction` parameter** to `recomputeOptimisticState()` to distinguish between user-initiated and sync-initiated recomputations 2. **Modified event filtering** to allow user actions through even when keys are in `recentlySyncedKeys` 3. **Updated batching logic** so user actions bypass batching via `forceEmit=true`, ensuring immediate UI updates while still batching sync-related events for performance 4. **Fixed all transaction creation paths** to pass `triggeredByUserAction=true` for direct user operations (insert, update, delete) ## Key Changes - Modified `recomputeOptimisticState()` to accept `triggeredByUserAction` parameter - Updated sync status filtering to allow user actions through - Modified complex filtering to skip when `triggeredByUserAction=true` - Updated `emitEvents()` to accept `forceEmit` parameter for user actions - Fixed direct operation transaction calls to pass correct parameters - Added comprehensive test case to prevent regression ## Test Coverage - New test case reproduces the original issue and verifies the fix - Test confirms rapid user actions on recently synced keys are not blocked - Existing tests continue to pass 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Document UI responsiveness fix for rapid user interactions - Explain root causes: event filtering and batching issues - Detail solution: triggeredByUserAction parameter and forceEmit logic 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
samwillis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, let's get this out but keep an eye out for side effects.
|
Side effects like excessive renders? |
Summary
Detailed Problem Analysis
This issue manifested when users rapidly clicked checkboxes in the todo app. The symptoms:
Root Cause Analysis
The issue had two critical components:
1. Event Filtering Problem
User actions on recently synced keys were being filtered out by
recentlySyncedKeyslogic. This logic was designed to prevent duplicate sync events but was incorrectly blocking legitimate user actions because:recentlySyncedKeys2. Batching Problem
Once sync transactions started,
shouldBatchEventswould becometrue, causing all subsequent events (including user actions) to be batched instead of immediately updating the UI:Solution Implementation
1. Added User Action Context
recomputeOptimisticState()to accepttriggeredByUserActionparametertriggeredByUserAction=truetriggeredByUserAction=false2. Smart Event Filtering
triggeredByUserAction=true, events are allowed through even if keys are inrecentlySyncedKeys3. Intelligent Batching
emitEvents()to acceptforceEmitparameterforceEmit=truebypasses batching for immediate UI updates4. Comprehensive Code Path Coverage
Fixed all transaction creation paths:
collection.insert()callscollection.update()callscollection.delete()callsKey Implementation Details
Test Coverage
New test case:
should not block user actions when keys are recently syncedVerification
✅ Manual testing: Can no longer reproduce the issue with rapid checkbox clicking
✅ Automated tests: All existing tests pass + new regression test
✅ Performance: Sync batching optimizations preserved
✅ User experience: UI remains responsive under all conditions
This fix ensures that user interactions are never blocked by optimization logic, while preserving all performance benefits for sync operations.
🤖 Generated with Claude Code