better handle layout invalidation. close #549