Lock the layout while adding/replacing/removing nodes

Experimental optimization: postpones the re-layout until after we're finished modifying the DOM tree to avoid redundant re-layouts.