A small note editing screen shows the autosave status. After a recent PR, users are reporting strange behavior: when the screen is closed quickly, the state sometimes changes after leaving the page, and when reopening, extra entries can appear in the save log.
DraftEditorViewModel screen must trigger autosave only for the latest text passed to update(text:).close(), no deferred operations must change status, and they must not call DraftSaving.save(_:).status must become saved.saved or failed from the canceled operation.DraftEditorViewModel with DraftSaverSpy.update(text: "A"), then immediately update(text: "AB").savedTexts log.And separately:
DraftEditorViewModel with DraftSaverSpy.update(text: "bye") and immediately close().status and the savedTexts log."AB".close() there should be no new saves and no state changes from the canceled task.Swift 6@MainActor for DraftEditorViewModel, Task.sleep for deterministic delayasync contextUse line comments to explain the problem, its impact, the fix and how to test it.