fix(client): make the new rollbacks roll back only what they wrote

The rollbacks this branch added were snapshot-shaped: capture the whole
collection before the write, restore it on any failure. That is wrong in two
ways at once. It undoes work the server already accepted when a later step is
the one that fails, and it throws away whatever a collaborator's socket event
applied while the requests were in flight.

The day-plan reorder is the clearest case: five awaits, and a failing day-note
write reverted transport positions the server had already stored. It now
records only the fields it is about to overwrite, per booking, and drops each
one as its request lands - so a note failure reaches the catch with nothing to
undo, and a booking that arrived mid-write survives.

The notification toggle had the same shape underneath: the rollback was made
surgical but the request still shipped the whole matrix built from the
pre-toggle render, so two overlapping toggles overwrote each other anyway. It
sends the one cell that changed. The test pinned the disagreement as correct;
it asserts the payload now.

Photo reorder awaits allSettled rather than all, so the UI is not snapped back
while the remaining writes are still landing - a partial run really does leave
the server holding part of the new order, and only a total refusal justifies
restoring the old one. Both the desktop editor and the mobile sheet, which was
still swallowing every rejection.

Also: the geolocation start guard is a run generation now, because a start
issued after a stop re-sets a plain flag while the first run is still parked in
the iOS permission prompt; a category rename reports once for the batch and
rethrows, so the settings dialog stops closing as if it had worked; and a 404'd
import job stops telling the user their file was invalid when it had simply
expired.

The clipboard fallback for plain-HTTP installs was pasted into three files by
this branch. It is one helper now, and the two copy buttons in the members
modal that still called navigator.clipboard unguarded use it too. Same for the
fourth local-date helper written next to the three that already import the
existing one.
This commit is contained in:
Maurice
2026-08-23 11:23:09 +02:00
committed by Maurice
parent 818021908f
commit 7c6a17c020
27 changed files with 522 additions and 130 deletions
@@ -772,12 +772,13 @@ describe('NotificationsTab', () => {
it('FE-COMP-NOTIFICATIONS-031: a failing toggle leaves a later toggle alone', async () => {
const user = userEvent.setup();
const bodies: Record<string, Record<string, boolean>>[] = [];
let rejectEmail!: () => void;
server.use(
http.put('/api/notifications/preferences', async ({ request }) => {
const body = (await request.json()) as Record<string, Record<string, boolean>>;
// The first write is the email flip; in-app is still untouched there.
if (body.trip_invite.inapp === true) {
bodies.push(body);
if (body.trip_invite?.email !== undefined) {
return new Promise<Response>(resolve => {
rejectEmail = () => resolve(HttpResponse.json({ error: 'nope' }, { status: 500 }) as unknown as Response);
});
@@ -795,7 +796,11 @@ describe('NotificationsTab', () => {
// Flipped while the email write is still hanging.
await user.click(inapp);
await waitFor(() => expect(bodies).toHaveLength(2));
await waitFor(() => expect(screen.getAllByRole('button')[1]).toHaveAttribute('aria-pressed', 'false'));
// The in-app write must not carry the email cell, or the server would keep the
// value the failing write is about to take back.
expect(bodies[1].trip_invite.email).toBeUndefined();
rejectEmail();
@@ -116,14 +116,16 @@ export default function NotificationsTab(): React.ReactElement {
const toggle = async (eventType: string, channel: string) => {
if (!matrix) return
const current = matrix.preferences[eventType]?.[channel] ?? true
const updated = {
...matrix.preferences,
[eventType]: { ...matrix.preferences[eventType], [channel]: !current },
}
setMatrix(m => m ? { ...m, preferences: updated } : m)
setMatrix(m => m ? {
...m,
preferences: { ...m.preferences, [eventType]: { ...m.preferences[eventType], [channel]: !current } },
} : m)
setSaving(true)
try {
await notificationsApi.updatePreferences(updated)
// Only the toggled cell goes out. The server merges what it gets, and sending the
// whole matrix would carry this render's value for every other cell — a second
// toggle made while this request is in flight would be overwritten by it.
await notificationsApi.updatePreferences({ [eventType]: { [channel]: !current } })
} catch {
// Only this cell rolls back — restoring the whole snapshot would also undo a
// toggle the user made while this request was in flight.