mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
A dashboard layout change could be silently reverted when a hero score-ring toggle was made around the same moment. Both writes PUT the whole layout to /api/dashboard/widgets, and whichever reached the server last won, so a ring write built from a pre-save snapshot overwrote a fresher Save. Guard the write with optimistic concurrency. The client sends the updatedAt it based its edit on; the route writes conditionally on the stored row still carrying that token (updateMany where updatedAt = base) and returns 409 with a typed body on a stale base, writing nothing. The advanced token rides back on every GET/PUT response so the client can rebase. No migration: the User row already has an @updatedAt column. On the client, the ring PUT carries only its own fields plus the base token, the Save and ring writes share one mutation scope so they serialise, the Save button and ring controls disable while either write is in flight, and a 409 refetches the winning layout and asks the user to redo the change. Refs #581