Changes lost after writer complained, that the document has been modified externally

I recently edited a document in LibreOffice Writer on my Ubuntu 22.10 laptop. When I closed the window, Writer asked whether to save changes and I clicked “yes”, but then it complained that the document has been modified externally. I didn’t know, what was going on, so I clicked on “cancel” and Writer just closed the window, without saving my changes. I expected a cancel button to cancel the closing of the window, not the saving. Is this the intended behaviour or a bug only experienced by me?

This is a clear bug. Being unable to stop and re-deide is not a correct UX.