ocaml-vdom icon indicating copy to clipboard operation
ocaml-vdom copied to clipboard

ocaml-vdom not working with wasm_of_ocaml

Open bikallem opened this issue 10 months ago • 3 comments

I recently tried to run the examples in this repo with the newly released wasm_of_ocaml (https://discuss.ocaml.org/t/ann-js-of-ocaml-6-0-1-wasm-of-ocaml/16160). I tried the counters app. It builds okay. However, running in the browser doesn't render much. Jsoo samples manipulating dom works out of the box, so I presumed vdom would work well with wasm_of_ocaml. Is there some quick setting I can use perhaps to make this work?

bikallem avatar Apr 22 '25 11:04 bikallem

Hello, thanks for the report. I tried to build ocaml-vdom with wasm_of_ocaml but the wasm_of_ocaml OPAM package fails to build on my old machine (the binaryen-bin package runs out of memory I think), so it will take me some time to investigate. If you have more precise description of the issue you are facing, that could be useful in the meantime. Thanks.

nojb avatar Apr 24 '25 14:04 nojb

See https://github.com/ocsigen/js_of_ocaml/issues/1948

vouillon avatar Apr 24 '25 15:04 vouillon

Thanks for the pointer @vouillon! I understand that onload may trigger before the script is evaluated so one should use the following shim instead of a direct call to Window.set_onload in order to be WASM-compatible (with an obvious definition for Js_browser.Document.ready_state):

let set_onload f =
  let open Js_browser in
  if Document.ready_state document = "complete" then f ()
  else Window.set_onload f

@bikallem would you like to give it a try and report back if it works? Thanks!

nojb avatar Apr 24 '25 16:04 nojb