Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix disposable of optimistic updates
Summary: The basic flow of the bug (as perceived by the user) is: 1. Apply an optimistic update, updating some subscriber S (e.g. a useFragment caller) w new data. 2. Commit a final update (causing the optimistic update to get rebased) 3. Dispose the optimistic update 4. Observe that subscriber S is not correctly notified of the updated state ## The Bug * In step 1 we create a backup value for S that reflects its state pre-optimistic update * In step 2 we: * Restore this backup * Commit the new changes (notably, w/o recalculating each subscription's results) * Snapshot the store prior to rebasing the optimistic update. The last snapshot step is the problematic part: the snapshot used for the backup is the *current value of the subscription*, but this value hasn't been updated to reflect the current state of the store. Note that in practice most final operations will affect the same data that was affected by the optimistic updater, ensuring that the subscription would be recalculated correctly. The bug occurs only when the "final" update is empty (or more specifically, it occurs for all subscriptions affected by the optimistic update but that aren't affected by the final update). ## The Fix The fix is to ensure during the store snapshot that we re-read the backup for stale subscriptions, ensuring that we have a correct backup to return to later. Non-stale subscriptions didn't diverge between their last backup/current value, so we can use their current value as the backup. ## Performance Implications This adds a re-read of a subset of subscriptions during the store snapshot operation - which only occurs when rebasing optimistic updates. This should be a relatively small overhead, and its required for correctness so in the short-term I'd argue we should pay the cost and evaluate. Reviewed By: tyao1 Differential Revision: D19539900 fbshipit-source-id: f684d2b0c7d46e7015d766a2ee819a5be8906bd7
- Loading branch information