Reference solution
The findings below are ordered by priority.
Findings
1. Completions mutate one preview instead of an outcome ledger
Location: src/optimistic-profile-editor.tsx:25-47
requestId is created but no per-revision outcome is retained. Each callback writes directly to savedProfile, so an older success can overwrite a newer optimistic submission and an older failure can restore a stale snapshot. Merely ignoring older completions is also insufficient: if request two fails back to request one's optimistic value and request one later fails, that value would remain displayed even though neither save succeeded.
Store pending, applied, superseded, and failed outcomes by revision and derive the visible preview from that ledger, falling back through lower revisions to the initial confirmed profile. Pass the stable session and increasing revision already supported by the API so a late lower revision cannot overwrite a higher server revision.
2. An old completion clears status owned by a newer request
Location: src/optimistic-profile-editor.tsx:41-47
Both branches unconditionally clear pending, and the failure branch replaces one shared error. If request one settles while request two is still pending, the editor claims all saving is finished or displays a failure without retaining which revision owns it.
Derive pending from whether any ledger entry remains unfinished. Retain errors with their owning revisions, display the highest failed revision until the next submit, and do not allow an unrelated completion to clear or replace it.
3. A response discards edits typed after submission
Location: src/optimistic-profile-editor.tsx:39-42
Every applied or superseded response replaces draft with the returned canonical profile. If the user edits the biography while the request is in flight, those unsaved keystrokes disappear.
Record the response in its ledger entry, but replace the form draft only when it still field-for-field matches that revision's submitted snapshot; otherwise preserve the newer draft.
4. Millisecond timestamps are not unique idempotency keys
Location: src/optimistic-profile-editor.tsx:34-38
Two separate submissions started during the same millisecond receive the same key. A backend deduplicating by that key can treat the second profile revision as a retry of the first and never persist it.
Derive the key from the stable editorSessionId and monotonically increasing clientRevision already sent to the API.
Reasonable non-findings
- Starting a later save without disabling the button is required by the overlap contract.
- Copying
draft into submitted prevents later controlled-input updates from mutating that request payload.
- Functional draft updates correctly preserve the sibling field.
- Rendering the error with
role="alert" is appropriate for the latest save failure once completion ownership is fixed.