JSaddle Warp is causing issues with XHR requests on FireFox
According to [https://github.com/ghcjs/jsaddle/issues/64](this issue), FireFox doesn't allow strict XHR requests, only async ones. When trying to view a static shpadoinkle site, updates will not reflect on FireFox. Below is a reproducible example:
# while inside shpadoinkle
nix-shell --command "ghcid --command 'cabal repl examples:counter' --run"
Then, load localhost:8080
in FireFox. You'll see that when loading the page, all is well. Yet, when you try to engage an event handler, like Increment
, you'll see an error similar to the following:
Error : Unexpected Duplicate. syncCallbacks=True nBatch=3 nExpected=5
Likewise, in FireFox's console, you'll see the following warning:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help http://xhr.spec.whatwg.org/
Although it's a warning, it still kills the javascript runtime.
The offending code comes from JSaddle - specifically, the front-end code that it uses to facilitate the serverside effect result replication: https://hackage.haskell.org/package/jsaddle-warp-0.9.8.0/docs/src/Language.Javascript.JSaddle.WebSockets.html#jsaddleJs%27
Specifically, I think the offending line is the following: https://github.com/ghcjs/jsaddle/blob/master/jsaddle-warp/src/Language/Javascript/JSaddle/WebSockets.hs#L233 - it relies on a strict parse of the XHR result. I'll do some more research on this to see if I can make a fixed fork.
However, once we develop a fix for jsaddle, how should we go about integrating it into the shpadoinkle stack? Just add it to our nix overlay?
EDIT: I just found where to apply a custom build of jsaddle in shpadoinkle's overlay: https://gitlab.com/platonic/shpadoinkle/-/blob/master/nix/overlay-shpadoinkle.nix#L21
EDIT: This is also an important issue, because it doesn't only affect firefox, but also Edge >13. I'm sure that market percentage is large enough to be a concern. Source: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Synchronous_and_Asynchronous_Requests#synchronous_request