fix(autosave) : retry constellation version conflicts
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { useEffect, useEffectEvent, useRef, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import { saveWithConflictRetry } from "@/lib/editor/autosave";
|
||||
import { parseLocalDraft as parseStoredDraft, serializeLocalDraft } from "@/lib/editor/local-draft";
|
||||
|
||||
export type AutosaveState = "saved" | "unsaved" | "saving" | "incomplete" | "error";
|
||||
@@ -95,7 +96,9 @@ export function useAutosave<Value, Draft = Value>({
|
||||
setSaving(true);
|
||||
setErrorFingerprint(null);
|
||||
try {
|
||||
const result = await persist(snapshot, version);
|
||||
const attempt = await saveWithConflictRetry(persist, snapshot, version);
|
||||
const result = attempt.response;
|
||||
if (attempt.retried) setVersion(attempt.version);
|
||||
if (result.status === "error" || result.status === "conflict") {
|
||||
if (result.currentVersion) setVersion(result.currentVersion);
|
||||
setErrorFingerprint(snapshotFingerprint);
|
||||
|
||||
Reference in New Issue
Block a user