[OCaml] High Intensity Training Online
fix resync the workout timer when the tab is shown
The elapsed timer ticks on a one-second interval and recomputes from the workout start epoch, so its value is always correct when it ticks. Browsers throttle setInterval in background tabs, though, so the display can lag while the tab is hidden and only catch up on the next throttled tick after the user returns. Add a visibilitychange listener that ticks immediately when the tab becomes visible, so the elapsed time updates continuously from the moment logging resumes rather than after a delayed interval. Presentation only; no doctrine bearing.
lib/web/workout_client.ml
@@ -323,6 +323,16 @@
323
323
(Dom_html.handler popstate)
324
324
Js._false
325
325
|> ignore;
326
Added:
(* Background tabs throttle [setInterval], so the elapsed count can lag while
327
Added:
the tab is hidden. Tick once the moment the tab is shown again, so the
328
Added:
timer catches up at once rather than after the next throttled interval. *)
329
Added:
Dom_html.addEventListener document
330
Added:
(Dom_html.Event.make "visibilitychange")
331
Added:
(Dom_html.handler (fun _ ->
332
Added:
tick ();
333
Added:
Js._true))
334
Added:
Js._false
335
Added:
|> ignore;
326
336
(* Mark the document as script-enhanced so CSS can hide no-JS fallbacks such
327
337
as the exercise-selector submit button. Set only once the client runs, so
328
338
a no-JS visitor keeps every fallback. *)