fix(insights): preserve stored layout dimension on a partial PUT

A PUT that omits sections (an iOS tiles-only reorder) reset the user's
section customization to defaults, and symmetrically a sections-only PUT
reset the stored tiles. serializeInsightsLayout now takes the resolved
stored layout and falls back to it — not to defaults — for whichever
dimension the body omits; the PUT handler loads the stored layout first.
A first-ever single-dimension PUT (no stored layout) still fills
defaults, so the v2 blob stays complete. Pins the merge behaviour with
three unit cases.
This commit is contained in:
Marc-André Bombeck committed 2026-06-14 10:15:47 +02:00
1 parent 7b0688b37e
commit 7fa10b43a0
3 files changed
+110 -9

No files matched your search

+6 -1
View File
@@ -170,7 +170,12 @@ export const PUT = apiHandler(async (request: NextRequest) => {
return returnAllZodIssues(parsed.error, 422);
}
const normalized = serializeInsightsLayout(parsed.data);
// v1.16.13 — load the user's stored layout so a PUT that omits a
// dimension (iOS reorders tiles with a tiles-only body, no `sections`
// key) preserves the other dimension's customization instead of
// resetting it to defaults.
const previous = await buildInsightsLayout(user.id);
const normalized = serializeInsightsLayout(parsed.data, previous);
await prisma.user.update({
where: { id: user.id },