mozilla-b2g/gaia — pull request #19174 by jrburke (2014-05-12 22:22:15+00:00)
Title: Bug 1009183 - [email] activity launch, return to message list, no messages shown

This bug was caused by the Cards.pushDefaultCard() behavior in the Cards implementation. mail_common, when finding that removing the current card would result in no cards displayed, calls Cards.pushDefaultCard().

That is implemented by mail_app, which pushes a message_list card. Then, mail_common, once the card has been pushed on the stack, removes the originally targeted card for removal. In these activity/notification cases, it would have been a compose or message_reader card.

So the issue is that the message_list card is pushed into the DOM, but **not** as the topmost, visible card. When message_list is calls vscroll's setData, it triggers the vscroll init, and vscroll's measurement of this.itemHeight is 0 because the card is hidden, and that causes havoc in the indexAtScrollPosition() method, causing a divide by 0, which leads to sadness.

So the fix was to only call setData() if the card is visible, and to also check if data needs to be set in message_list's onCardVisible() method.

Overall, I like this change because it means the vscroll avoids doing work until it is actually visible, which allows for things like other card animations to complete without the possibility of the vscroll work stealing computing resources.

In my ideal world, some of this could be hidden within vscroll, but in this case it would have mean vscroll knowing about the particulars of when cards are displayed to work, which would make vscroll more coupled to email app-specific code.