ocsigen / eliom

Multi-tier framework for programming web and mobile applications in OCaml.
http://eliom.org
Other
301 stars 53 forks source link

Code containing the following injections is not linked on the client #506

Open sagotch opened 7 years ago

sagotch commented 7 years ago
Code containing the following injections is not linked on the client

This is the error I get in the browser console. It appears when I try to use an external lib (a modified version of ocsigen-start).

I read this https://github.com/ocsigen/eliom/issues/275, but I do not really understand what is happening here. Why isn't the module linked?

I can not give a lot of details about the error, but does anyone know what situation cause this, why, and how to solve it?

sagotch commented 7 years ago

I got a minimal example of my problem.

a.eliom

open%shared Eliom_lib
open%shared Eliom_content
open%shared Html.D

module%shared A_app =
  Eliom_registration.App (
  struct
    let application_name = "a"
    let global_data_path = None
  end)

let%server main_service =
  Eliom_service.create
    ~path:(Eliom_service.Path [])
    ~meth:(Eliom_service.Get Eliom_parameter.unit)
    ()
let%client main_service = ~%main_service

let%shared () =
  A_app.register
    ~service:main_service
    (fun () () ->
       Lwt.return
         (Eliom_tools.F.html
            ~title:"a"
            Html.F.(body [
              h1 [pcdata "Welcome from Eliom's distillery!"];
            ])))

let%shared () =
  A_app.register ~service:Projects.service @@ 
  fun x () ->
  Lwt.return @@
  Eliom_tools.F.html
     ~title:"a"
     Html.F.(body
       [ Eliom_content.Html.C.node [%client div @@
         match B.of_string ~%x with
         | `FOO -> C.data
         ] ]  )

b.eliom

type%shared t = [ `Foo ]

let%shared of_string = function "FOO" -> `FOO | _ -> assert false

let%shared to_string = function `FOO -> "FOO"

open%server Eliom_parameter

let%server service =
  Eliom_service.create
    ~path:(Eliom_service.Path ["project"])
    ~meth:(Eliom_service.Get (suffix (string "project")))
    ()

let%client service = ~%service

c.eliom

open%client Eliom_content.Html.D

let%client data = [ a ~service:B.service [ pcdata "FOO" ] (B.to_string `FOO) ]

The error occurs when I try to use C.data. If I replace

let%client data = [ a ~service:B.service [ pcdata "FOO" ] (B.to_string `FOO) ]

by

let%client data = [ pcdata __LOC__ ]

Everything works.

sagotch commented 7 years ago

Okay, I get it (#275), turning let%client data = .. into let%client data () = ... fixes the thing. But why?

pwbs commented 7 years ago

Does it work if you use

let%client data = lazy ...

?

sagotch commented 7 years ago

As expected, no.

sagotch commented 7 years ago

Note: the same bug prevent me from using my modified version of ocsigen-start: https://github.com/sagotch/ocsature

sagotch commented 7 years ago

The only piece of code which is client side is in ocsature_page.eliom, a simple shared module doing almost nothing.

Adding ocsature.client to CLIENT_PACKAGES (in Makefile.option) produces

sagotch.js:33 Uncaught (3) [0, Array(3), bM]
sagotch.js:8020 Code containing the following injections is not linked on the client:
1
1

And when I try to use the Ocsature_page module:

[eliom:client] Client closure eQGuMd1 not found  (is the module linked on the client?)
[eliom] Async: (Failure
  "Client closure eQGuMd1 not found  (is the module linked on the client?)")

I simply can't work using ocsigen, and I have absolutely no idea about what to do. Is someone working on this issue? Is it really an issue, did I miss something?

sagotch commented 7 years ago
opam pin remove eliom js_of_ocaml ocsigen-i18n ocsigen-start ocsigen-toolkit ocsigenserver pgocaml tyxml

And... it works. I am pretty sure that tyxml was not pinned before (I just added it in a desperate move). I do not use ocsigen-toolkit, nor ocsigen-start. Voila voila...