ractivejs/ractive — pull request #1533 by Rich-Harris (2014-11-30 02:00:53+00:00)
Title: gh-1483

**not ready for merge**

This is to address #1483, #1529, and possibly #1431. The issue is that if you have nested conditional sections...

```html
{{#if foo.length || bar.length}}
{{#if foo === bar}}

{{/if}}
{{/if}}
```

...and the inner condition (`foo === bar`) becomes truthy at the same time as the outer condition (`foo.length || bar.length`) becomes falsy, the intro transition on the `` never has its `start()` method called, which causes an error when the `` is unrendered. (It's not *quite* as straightforward as that - if you replace the outer condition with `foo !== bar`, for example, the bug doesn't present - it's something to do with child properties. The order matters, in other words.)

Really, the inner `` shouldn't get rendered at all, since in the first state it shouldn't be rendered because `foo === bar` is falsy, and in the second state it shouldn't be rendered because `foo.length || bar.length` is falsy. The transition issue is is just a symptom of that fact that it's being rendered incorrectly during the switch from one state to another.

The only real way to solve this problem is to order dependants so that outer sections are updated before inner sections. Ractive did have such a mechanism at one point, but it meant quite a bit of complexity, and since (apparently) no tests depended on it, it was killed off during a refactor. I *think* the same thing could be done more simply than the old implementation though - rather than flushing all priority 1 dependants (which might cause a bunch of priority 1+n dependants to be unregistered), then all priority 2 dependants, and so on until we'd reached the lowest priority, it should be possible to get a snapshot of *all* dependants affected by a set of changes, order them by priority, and go through the whole list in one step. If one of the dependants in the list is unregistered by the time we get to it, no matter - it's just a noop.