Fix infinite loop when saving empty document