Skip to content

Commit de49ca5

Browse files
committed
fix(web): allow file refresh to update save baseline after success
A successful save left latestRevision set, so idle query refreshes never updated lastConfirmedContents. A later failed edit then rolled back to the old local save instead of the file now on disk. Reset latestRevision after a successful latest write.
1 parent 236f529 commit de49ca5

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎apps/web/src/components/files/fileSaveCoordinator.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,35 @@ describe("FileSaveCoordinator", () => {
227227
}),
228228
);
229229
});
230+
231+
it("lets idle refreshes update the baseline after a successful save", async () => {
232+
vi.useFakeTimers();
233+
const persist = vi
234+
.fn<(contents: string) => Promise<AtomCommandResult<void, never>>>()
235+
.mockResolvedValueOnce(AsyncResult.success(undefined))
236+
.mockResolvedValueOnce(AsyncResult.failure(Cause.fail(new Error("write failed"))));
237+
const onRollback = vi.fn();
238+
const coordinator = new FileSaveCoordinator({
239+
debounceMs: 500,
240+
initialContents: "disk",
241+
persist,
242+
onPendingChange: vi.fn(),
243+
onConfirmed: vi.fn(),
244+
onRollback,
245+
});
246+
247+
coordinator.change("saved");
248+
await vi.advanceTimersByTimeAsync(500);
249+
await Promise.resolve();
250+
coordinator.syncConfirmed("refreshed");
251+
coordinator.change("latest");
252+
await vi.advanceTimersByTimeAsync(500);
253+
await Promise.resolve();
254+
expect(onRollback).toHaveBeenCalledWith(
255+
expect.objectContaining({
256+
failedContents: "latest",
257+
confirmedContents: "refreshed",
258+
}),
259+
);
260+
});
230261
});

‎apps/web/src/components/files/fileSaveCoordinator.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class FileSaveCoordinator<A = unknown, E = unknown> {
102102
});
103103
return;
104104
}
105+
this.latestRevision = 0;
105106
if (!this.disposed) this.options.onPendingChange(false);
106107
return;
107108
}

0 commit comments

Comments
 (0)