Help tracking possible DOM diffing bug in 0.19

I think I’ve found a bug in the way Elm 0.19 diffs the Model to determine whether to call subscriptions or not. But need help refining my understanding of the problem before I try to file an official bug report. Hoping somebody out there can help…

I found it while trying to convert one of the first programs I wrote to 0.19.1 from 0.18. This code used a conditional subscription to Time.every to determine when to stop an animation (which was achieved just by changing the CSS class of the element). It’s not the way I would do it now, I’d just use andrewMacmurray/elm-delay (which uses Process.sleep under the hood). But back then it was the only way I knew to do it, and was indeed the way recommended to beginners — and probably would still be what a beginner might reach for today.

Anyway after converting to the 0.19.1 and the new elm/time I found the animation wasn’t stopping. I’ve made a minimal example here…

https://ellie-app.com/7bhgBPtf49Xa1

The animation should stop after 1-2 seconds. You should then be able to restart it by clicking on the square, after which it should play for 1-2 seconds again. What actually happens under 0.19 however is that the animation doesn’t stop until you click on the square. Looking at the debugger, you can see that for some reason the subscription to Time.every isn’t firing at all until another click is made. It’s almost as if Elm doesn’t think the model has changed and so doesn’t reprocess the subscriptions.

So I tried to make the example even simpler and came up with this:

https://ellie-app.com/7bhCFf639HMa1

The count should go up one or two counts then stop. You can then get it to continue for another one or two counts by clicking on “Continue”. Strangely this now almost works except that the initial counting (and initial subscription to Time.every) doesn’t work. But then after clicking on “Continue” once, everything then starts working. So clearly simplifying this far gets rid of the bug partially, but not completely.

Anyone out there who understands better the logic of what triggers Elm to re-examine subscriptions, I’d be very grateful if you could help me to narrow down this bug to something I could put in a bug report… or explain (to my embarrassment!) why it’s not a bug (and why it worked as I expected under Elm 0.18).

Thanks!

Hi Jess,
I suspect this is another example of what is referred to as the conditional subscriptions bug.
See, for example: https://github.com/elm/compiler/issues/1776
and also this recent thread on slack:
https://elmlang.slack.com/archives/C13L7S5GR/p1572031426192200?thread_ts=1572031426.192200&cid=C13L7S5GR
So there are several of us actively looking at this, hoping to provide enough detail and root cause to help move the issue forward to resolution.
In the slack thread I referenced above, Evan requested that new issues be entered in github, with inline SSCCE (not just an Ellie link). I would suggest you open an issue on elm/core (as opposed to elm/compiler) but reference the compiler issue 1776 above.

2 Likes

@mthiems @Jess_Bromley I wonder why not everybody is complaining about this issue, as it seems like a pretty common pattern, specially in SPAs with routes. In my particular case 0.19.0 works fine but 0.19.1 does not. If you don’t mind, I’m going to open the issue in elm/core pointing to all the evidences that we have gathered.

Edit: Here’s the issue, https://github.com/elm/core/issues/1064. Please, add any info I might have missed :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.