Prevent deeply nested elements causing stack overflow