thomashoneyman / purescript-halogen-hooks

Reusable stateful logic in Halogen, inspired by React Hooks
https://thomashoneyman.com/articles/introducing-halogen-hooks
MIT License
114 stars 13 forks source link

Runtime exception when running two hooks components at the same time #73

Closed hrajchert closed 2 years ago

hrajchert commented 2 years ago

Hi! First of all thanks a lot for this great project, I really like the idea :).

We are running into a weird runtime exception when having 2 hooks components running side by side: Screen Shot 2022-04-19 at 10 15 29

The screenshot above corresponds to the Simulation pane of a tool called Marlowe Playground. The page has 5 components called currencyInput (highlighted in red) and one component called instantInput (highlighted in green). For some reason, if the instantInput raises an output the currencyInput receives unexpected data (highlighted in red) which results in the runtime exception.

If I comment the line that raises the output for InstantInput then I don't have this problem Screen Shot 2022-04-19 at 11 22 10

One caveat of this project: It is using custom helpers we call sub-modules, which emulates the Elm architecture with Lenses. We made this as a way to have global state before you created halogen-store. In another project in the same repo we are not using the sub-components anymore thanks to your library <3.

Steps to reproduce

This can be reproduced in the debug-halogen-hooks branch of the repo. It is necessary to use nix-shell with the binaries cache preconfigured. Then follow these steps to launch the playground client (the backend is not needed for this).

After the page is running on localhost, you can:

  1. Open an example
  2. Select "Escrow - Marlowe"
  3. Click "Send to simulator"
  4. The runtime error appears in the console
thomashoneyman commented 2 years ago

Thanks for the report, @hrajchert. I haven't seen this happen before.

If I'm following correctly, you have:

I'm pressed for time this week so it's difficult for me to set up your reproduction, but I am curious what happens if you trace the value through each of those steps and pinpoint the moment in which it becomes undefined. When I have some more time I can help dig into exactly what's going on.