evancz/Elm — pull request #350 by timthelion (2013-11-17 16:16:07+00:00)
Title: Que notify: fix for https://github.com/evancz/Elm/issues/339 and https://github.com/evancz/Elm/issues/224

I hope that this pull request fixes the text not updating bug in Elm.
In this pull request you'll find a few things:
Some of the debugging code that allowed me to track down the bug(commented out). All of those conditions were met before the bug was fixed. I've also put https://github.com/adamw 's test case into the source tree. I hope he doesn't mind :)

Before we get started, I'd like you to test whether my fix actually works. Here is Adam's test with my patched version of the runtime.
http://thobbs.cz/works/2013/text-update-bug/TextUpdate.html

So the bug:

Well, it took me almost 3 days to track it down. That's a new record for me. Perhaps I'm getting old...

It's a pretty subtle one though. During a given round, dom elements may be created, at which point the domUpdate gets called. The domUpdate function calls the resizeIfNeeded function, and that(under certain conditions) calls the "notify" function. The "notify" function starts a new round(synchronously), but the previous round hasn't finished running. This new round, kind of awkwardly overwrites the state of the previous round, then completes. The previous round, the one which called domUpdate, then continues, with the now corrupted state.

Note: I'm posting a pull request against master, because dev doesn't build on my ancient version of GHC.