Let an open tab notice what another device did - #137
Merged
Merged
Conversation
A dose logged on a phone at 20:22 still showed as due on a desktop at 20:47. Both online, both signed in, and sync working: the protocol edited on the desktop at 19:01 was already on the phone. SyncRunner starts a run on four things, and every one is about this device: its own data changing, its own tab becoming visible, its own network coming back, startup. A tab that is open, in the foreground and untouched matches none of them, and visibilitychange does not fire for a tab you never looked away from. The one state where somebody is staring at the screen was the one state that never asked. So it asks, once a minute, while visible. The request is a fetch of one small record and decideSync answers "in-step" when nothing moved, so the cost of the common case is one small GET a minute. Skipped while hidden, since a hidden tab has nothing to show, becoming visible is already a trigger, and browsers throttle timers there anyway. The engine already did its half correctly, and there is now a test named for the incident holding it: asked, a device with nothing to send takes what another device left, as a clean pull rather than a question. Written into 06-traps.md: a list of triggers assembled from local events has no entry for "somebody else did something", and the gap is invisible in testing because a developer reloads constantly and a reload is a trigger.
|
Someone is attempting to deploy a commit to the Arun's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A dose logged on a phone at 20:22 still showed as due on a desktop at 20:47. Both devices online, both signed in, and sync working: the protocol edited on the desktop at 19:01 was already on the phone. Four exports, taken from both devices across the evening, confirmed it was one record's worth of difference and nothing else.
What was missing
SyncRunnerstarts a run on four things, and every one of them is about this device:A tab that is open, in the foreground and untouched matches none of them, and
visibilitychangedoes not fire for a tab you never looked away from. The one state in which somebody is staring at the screen was the one state that never asked the server anything.The fix
One minute, while visible. The request is a fetch of one small record, and
decideSyncanswers "in-step" when nothing moved, so the common case costs one small GET a minute and transfers no data either way.Skipped while hidden: a hidden tab has nothing to show, becoming visible is already a trigger, and browsers throttle timers there anyway.
The engine already did its half correctly. There is now a test named for the incident holding it: asked, a device with nothing of its own to send takes what the other device left, as a clean pull rather than as a question.
Written down
06-traps.md: a list of triggers assembled from local events has no entry for "somebody else did something", and the gap is invisible in testing because a developer reloads constantly and a reload is a trigger. Worth checking against any future trigger list: at least one entry has to come from outside this device.Checks
npx tsc --noEmitclean,npx next lintclean, 1714 tests pass (1 new).