eliom icon indicating copy to clipboard operation
eliom copied to clipboard

C.node does not work inside R.node

Open balat opened this issue 9 years ago • 1 comments

It is currently not possible to use C.node directy inside R.node. When the page is generated server-side, the node never changes. This produces a bug very difficult to understand. The workaround is to introduce an intermediate node. But do we have a way to make it work?

Example:

    let sig_r = Eliom_shared.React.S.create true in
    R.node @@
    Eliom_shared.React.S.map
      [%shared fun b ->
        C.node @@ [%client
        if ~%b
        then (print_endline "bop"; D.p [])
        else (print_endline "bap"; D.ul []) ] ]
      (fst sig_r)

The explanation of this behaviour is probably that C.node introduces server-side a temporary node in the page, that is replaced by a client-side node. But R.node cannot find its node anymore.

balat avatar Sep 14 '16 15:09 balat

@balat I can think of a messy hack to make this work. We can automatically add an auxiliary unique class to the C node (the same class for the original server-produced one and the client one). This will allow us to correctly identify the proper node to replace in the R implementation.

However, R.node and C.node are both fragile, and I am not sure that adding hacks like this for covering arbitrary kinds of nesting is worth it. Externally modifying the DOM node (as C implicitly does) is bound to cause problems for R.node. Maybe document the limitation and live with it?

vasilisp avatar Sep 21 '16 13:09 vasilisp