Ensure the modal closes before the view can be closed