ocsigen / eliom

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

Rapid succession of comet-requests when using two Eliom_react.Down channels #796

Open paurkedal opened 5 months ago

paurkedal commented 5 months ago

This issue is triggered by an in-application link for a service which uses two downwards react events (or signals). I am using eliom 10.4.1.

The issue can be reproduced as follows. The modified file is attached in case of issues with patching.

$ eliom-distillery -name eliom_react_down_issue -template client-server.basic
$ cd eliom_react_down_issue
$ patch -p0 <<EOF
--- eliom_react_down_issue.eliom.orig   2024-05-24 13:39:14.220081792 +0200
+++ eliom_react_down_issue.eliom        2024-05-24 13:59:58.116249385 +0200
@@ -21,9 +21,22 @@
   Eliom_service.create ~path:(Eliom_service.Path [])
     ~meth:(Eliom_service.Get Eliom_parameter.unit) ()

-let%client main_service = ~%main_service
+let%server make_counter start period =
+  let counter = ref start in
+  Lwt_react.E.from @@ fun () ->
+  Lwt_unix.sleep period |> Lwt.map (fun () -> incr counter; !counter)
+let%server counter1 = make_counter 0 2.0
+let%server counter2 = make_counter 0 3.0

-let%shared () =
+let%server counter_paragraph counter =
+  let client_node = [%client
+    Eliom_content.Html.R.txt
+      (React.S.map (Printf.sprintf "Counter: %d")
+        (React.S.hold 0 ~%(Eliom_react.Down.of_react counter)))
+  ] in
+  Eliom_content.Html.(F.p [C.node client_node])
+
+let%server () =
   App.register ~service:main_service (fun () () ->
     Lwt.return
       Eliom_content.Html.F.(
@@ -36,4 +49,9 @@
                       ~service:(Eliom_service.static_dir ())
                       ["css"; "eliom_react_down_issue.css"])
                  () ])
-          (body [h1 [txt "Welcome from Eliom's distillery!"]])))
+          (body [
+            h1 [txt "Welcome from Eliom's distillery!"];
+            a ~service:main_service [txt "Watch network activity and click me."] ();
+            counter_paragraph counter1;
+            counter_paragraph counter2;
+           ])))
EOF
$ make test.opt

Then open the browser with a debug panel, watch the "Network" activity tab (in Firefox), and press the link:

eliom_react_down_issue.eliom.txt