Skip to content

Commit

Permalink
Make the initialization code resilient to missed load event
Browse files Browse the repository at this point in the history
Webassembly code is started asynchronously, so it can be executed after
the load event is triggered.
  • Loading branch information
vouillon committed Oct 6, 2023
1 parent 7ed7f69 commit 977eed5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/lib/eliom_client.client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1039,10 +1039,17 @@ let init () =
Js._false
in
Lwt_log.ign_debug ~section "Set load/onload events";
onload_handler :=
Some
(Dom.addEventListener Dom_html.window (Dom.Event.make "load")
(Dom.handler onload) Js._true);
if Dom_html.document##.readyState = Js.string "complete"
then
Lwt.async @@ fun () ->
let%lwt () = Js_of_ocaml_lwt.Lwt_js_events.request_animation_frame () in
let _ = onload () in
Lwt.return_unit
else
onload_handler :=
Some
(Dom.addEventListener Dom_html.window (Dom.Event.make "load")
(Dom.handler onload) Js._true);
add_string_event_listener Dom_html.window "beforeunload" onbeforeunload_fun
false;
ignore
Expand Down

0 comments on commit 977eed5

Please sign in to comment.