Hi folks, I just want to give a heads-up so that you perhaps don’t fall into the same problems as I did
_Platform_gatherEffects has issues when given a deep Cmd.batch bag (no issues with wide one, it seems): see Ellie. (Change between
init to illustrate the two behaviours).
Cmd.batch [cmd, Cmd.batch [cmd, Cmd.batch [cmd, .......]]]
Cmd.batch [cmd, cmd, cmd, cmd, cmd, ...]
This only affects Chrome for me, not Safari. (Perhaps Safari has just higher stack frames limit and would crash later?). The limit seems to be around 4.4k layers.
Now this is admittedly a stupid way to construct Cmds, but it does come up naturally as a solution to some problems, eg. if you have a high-level
Effect type that you later convert to a
List (Cmd msg). A function to interpret one Effect might look like
interpretEffect : Effect -> Model -> (Model, Cmd msg), and multiple:
interpretEffects : List Effect -> Model -> (Model, Cmd msg). Now they might depend on each other (how do they change the Model?) so you can’t just concatMap stuff together, you need to thread it through with
List.foldl. That’s where the deepness of the resulting Cmd bag comes from. Send 10k effects to
interpretEffects at once and you have a runtime exception.
So, while this might be classified as a bad usage of Cmd.batch (and indeed in our app we chunk the lists given to
interpretEffects to lists of ~800 items each), perhaps the
_Platform_gatherEffects function could be changed to allow for it?