ocsigen / eliom

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

Client node outside a client session #323

Open xapantu opened 8 years ago

xapantu commented 8 years ago

Creating a client node outside a request leads to weird javascript errors. Here is the code:

[%%shared
    open Eliom_lib
    open Eliom_content
    open Html5.D
]

module Ocaloudcore_app =
  Eliom_registration.App (
    struct
      let application_name = "ocaloudcore"
    end)

let main_service =
  Eliom_service.App.service ~path:[] ~get_params:Eliom_parameter.unit ()

let test = 
  Html5.C.node [%client
    h2 [pcdata "Welcome from Eliom's distillery!"]]

let () =
  Ocaloudcore_app.register
    ~service:main_service
    (fun () () ->
      Lwt.return
        (Eliom_tools.F.html
           ~title:"ocaloudcore"
           ~css:[["css";"ocaloudcore.css"]]
           Html5.D.(body [
             test
           ])))

And the error from Firefox:

[eliom:client] Cannot apply unwrapping (i.e. utilize it in whatsoever form) on request node AhHRE8SdNEM8 before the document is initially loaded #text "" ocaloudcore.js:5917:31

uncaught exception: 0,248,Failure,-3,Cannot apply unwrapping (i.e. utilize it in whatsoever form) on request node AhHRE8SdNEM8 before the document is initially loaded <unknown>
[eliom] Async: (Failure
  "Cannot apply unwrapping (i.e. utilize it in whatsoever form) on request node AhHRE8SdNEM8 before the document is initially loaded") ocaloudcore.js:5918:1

Well I guess it can make some sense to disallow this.

But it should either work, or raise an exception at runtime, but it should not (more or less) silently fail on the client !

With Eliom 5.0.0

rand00 commented 7 years ago

This was an issue that confused me quite a bit, and when I found out became a bit depressed (taken with a grain of salt) - when one is used to functional semantics with referential transparency...