Fix bug in `setView`

Only remove the previously-existing view if it differs from the new
view. This prevents the removal of deeply-nested views.