Fix delay when closing viewer