Fix rendering race condition

First commit is tests that fail. Second commit is patch for issue #3 .