Skip to content

[BUG] Event handler not being executed #1948

@bikallem

Description

@bikallem

Describe the bug
I am trying the counters sample from ocaml-vdom repo (https://github.com/LexiFi/ocaml-vdom/tree/master/examples/counters). I have put the (modes wasm) in the dune file. However, trying to view the UI in the browser results in blank screen. I can see that both the counters.bc.wasm.js and counters.bc.wasm files are loaded correctly in the chrome inspect tab. There are no error in the console. It looks like https://github.com/LexiFi/ocaml-vdom/blob/master/examples/counters/counters.ml#L36 is never hit.

As an experiment I tried the following:

let () =
  let readystatechange = Dom_html.Event.make "readystatechange" in
  let _ =
    Dom_html.(
      addEventListener document readystatechange
        (handler (fun _ev ->             
             let state = document##.readyState in
             (* Console.console##log state; *)
             if Js.to_string state = "complete" then run ();
             Js._false))
        Js._false)
  in
  ()

This works intermittently, i.e. sometimes it correctly renders the counter ui and at other times, it renders blank. You have to refresh the browser a few times and that seems to do the trick.

Expected behavior
The event handler should load/execute correctly when using ocaml-vdom/Js_browser.

Versions
6.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions