This short-circuiting cleverness here needs a comment.  I suggest:
If we know the size of the elements (distance !== NaN), we can calculate that, otherwise fail-over to doing the actual math.  Note that touching clientHeight will trigger a re-flow.  We expect the latter case to happen during the very first addition of messages to the UI.