feat(transcription): handle 409 rename-mid-edit conflict on block save (B12b)
When PersonService renames a person while a transcriber is editing a block that mentions them, the block-save endpoint returns 409 (carrying the new ErrorCode.PERSON_RENAME_CONFLICT from PR-A). saveBlock now: 1. Refetches the latest server snapshot of the block. 2. Calls mergeBlockOnConflict to combine: server's mentionedPersons (post-rename displayNames win) + transcriber's unsaved text + any local-only mentions added since the last save. 3. Updates the local block state with the merged result. 4. Re-throws so the autosave indicator surfaces the conflict and the pending payload is preserved for retry (B12). The merge logic is a pure function so it can be unit-tested in isolation and reused for any future conflict-resolution scenarios. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -98,6 +98,21 @@ async function saveBlock(
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ text, mentionedPersons })
|
||||
});
|
||||
if (res.status === 409) {
|
||||
// Rename-mid-edit (B12b): refetch latest, merge so transcriber input survives.
|
||||
const { mergeBlockOnConflict } = await import('$lib/utils/blockConflictMerge');
|
||||
const fresh = await fetch(`/api/documents/${doc.id}/transcription-blocks/${blockId}`);
|
||||
if (fresh.ok) {
|
||||
const serverBlock = await fresh.json();
|
||||
const merged = mergeBlockOnConflict({
|
||||
serverBlock,
|
||||
localText: text,
|
||||
localMentions: mentionedPersons
|
||||
});
|
||||
transcriptionBlocks = transcriptionBlocks.map((b) => (b.id === blockId ? merged : b));
|
||||
}
|
||||
throw new Error('Conflict resolved — please save again');
|
||||
}
|
||||
if (!res.ok) throw new Error('Save failed');
|
||||
const updated = await res.json();
|
||||
transcriptionBlocks = transcriptionBlocks.map((b) => (b.id === blockId ? updated : b));
|
||||
|
||||
Reference in New Issue
Block a user