mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
chore(release): v1.28.42 — snappier lists, correct mood refresh, safer first sign-up
Performance + correctness fixes from the campaign's verified perf-correctness audit (the two server-query findings — comprehensive-generate + boot-discovery distinct — are deferred to a careful separate perf release): - format-locale built a fresh Intl.DateTimeFormat/NumberFormat per call (main-thread stall across every history list). Routed through the existing process-wide formatter-cache keyed on locale + options (timeZone + hour-cycle in the key); output byte-identical. - measurement-list rendered every row twice (desktop table + mobile cards, one CSS-hidden), unvirtualized. Now renders one layout via the SSR-safe useIsMobile(md) hook; row markup + every data-slot unchanged. - moodDependentKeys omitted dashboardSnapshot(), so a mood write left the dashboard tile/score stale ~120s (server cache was already correct). Added it. - register first-user admin was a count-then-create race (two concurrent first sign-ups could both become ADMIN). Now an advisory lock + in-transaction re-count makes first-admin atomic; P2002 maps to 409 instead of 500. Regression test per fix. No migration (0243 still free).
This commit is contained in:
1 parent
9569d1c528
commit
d4be568625
13 files changed
+708
-426
No files matched your search
@@ -269,6 +269,16 @@ describe("dependent-key bundles", () => {
|
||||
expect(keyStrings).toContain(JSON.stringify(["insights"]));
|
||||
});
|
||||
|
||||
// v1.28.42 (M2) — the dashboard snapshot embeds a mood block + feeds the
|
||||
// score ring, but a mood write only invalidated the mood bundle, leaving the
|
||||
// Startseite tile / score stale for up to ~120 s. Mirror the measurement
|
||||
// (v1.18.9) and medication (v1.16.11) bundles. Pin the membership so a future
|
||||
// refactor can't silently drop the dependency again.
|
||||
it("moodDependentKeys bundles the dashboard snapshot (v1.28.42)", () => {
|
||||
const keyStrings = moodDependentKeys.map((k) => JSON.stringify(k));
|
||||
expect(keyStrings).toContain(JSON.stringify(["dashboard", "snapshot"]));
|
||||
});
|
||||
|
||||
it("medicationDependentKeys bundle covers medications + analytics + achievements", () => {
|
||||
const keyStrings = medicationDependentKeys.map((k) => JSON.stringify(k));
|
||||
expect(keyStrings).toContain(JSON.stringify(["medications"]));
|
||||
|
||||
+28
-17
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import type { Locale } from "./i18n/config";
|
||||
import { getDateTimeFormat, getNumberFormat } from "./intl/formatter-cache";
|
||||
import { isValidTimezone } from "./tz/format";
|
||||
|
||||
/**
|
||||
@@ -160,42 +161,52 @@ export function makeFormatters(
|
||||
// so axis month names follow the UI language, not the date-order pin.
|
||||
const dateLocale = dateOrderLocale(dateFormat, intlLocale);
|
||||
|
||||
// v1.28.42 (H2) — the returned closures used to construct a fresh
|
||||
// `Intl.NumberFormat` / `Intl.DateTimeFormat` on every call. `makeFormatters`
|
||||
// is memoised per (locale, tz, timeFormat, dateFormat) on the client, but a
|
||||
// dense history list still calls these closures thousands of times per
|
||||
// render, rebuilding an identical formatter each time (V8's toLocale cache
|
||||
// busts on any options object) → main-thread stalls. Route through the
|
||||
// process-wide formatter cache so each distinct (locale, options) shape is
|
||||
// constructed once. `getDateTimeFormat(...).format(date)` is behaviourally
|
||||
// identical to `Date.prototype.toLocale*String(locale, options)` — the latter
|
||||
// builds the same `Intl.DateTimeFormat` internally — so rendered output is
|
||||
// unchanged. The options carry `timeZone` + the hour-cycle/date-field shape,
|
||||
// so the cache key already distinguishes every variant.
|
||||
return {
|
||||
number: (value, fractionDigits) =>
|
||||
new Intl.NumberFormat(intlLocale, {
|
||||
getNumberFormat(intlLocale, {
|
||||
minimumFractionDigits: fractionDigits,
|
||||
maximumFractionDigits: fractionDigits,
|
||||
}).format(value),
|
||||
|
||||
integer: (value) =>
|
||||
new Intl.NumberFormat(intlLocale, { maximumFractionDigits: 0 }).format(
|
||||
value,
|
||||
),
|
||||
getNumberFormat(intlLocale, { maximumFractionDigits: 0 }).format(value),
|
||||
|
||||
percent: (value, fractionDigits = 0) =>
|
||||
new Intl.NumberFormat(intlLocale, {
|
||||
getNumberFormat(intlLocale, {
|
||||
style: "percent",
|
||||
minimumFractionDigits: fractionDigits,
|
||||
maximumFractionDigits: fractionDigits,
|
||||
}).format(value),
|
||||
|
||||
date: (value) =>
|
||||
asDate(value).toLocaleDateString(dateLocale, {
|
||||
getDateTimeFormat(dateLocale, {
|
||||
timeZone: tz,
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
year: "numeric",
|
||||
}),
|
||||
}).format(asDate(value)),
|
||||
|
||||
dateShort: (value) =>
|
||||
asDate(value).toLocaleDateString(dateLocale, {
|
||||
getDateTimeFormat(dateLocale, {
|
||||
timeZone: tz,
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
}),
|
||||
}).format(asDate(value)),
|
||||
|
||||
dateTime: (value) =>
|
||||
asDate(value).toLocaleString(dateLocale, {
|
||||
getDateTimeFormat(dateLocale, {
|
||||
timeZone: tz,
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
@@ -203,29 +214,29 @@ export function makeFormatters(
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
...hourOpts,
|
||||
}),
|
||||
}).format(asDate(value)),
|
||||
|
||||
time: (value) =>
|
||||
asDate(value).toLocaleTimeString(intlLocale, {
|
||||
getDateTimeFormat(intlLocale, {
|
||||
timeZone: tz,
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
...hourOpts,
|
||||
}),
|
||||
}).format(asDate(value)),
|
||||
|
||||
dateWithWeekday: (value) =>
|
||||
asDate(value).toLocaleDateString(dateLocale, {
|
||||
getDateTimeFormat(dateLocale, {
|
||||
timeZone: tz,
|
||||
weekday: "short",
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
}),
|
||||
}).format(asDate(value)),
|
||||
|
||||
monthShort: (value) =>
|
||||
asDate(value).toLocaleDateString(intlLocale, {
|
||||
getDateTimeFormat(intlLocale, {
|
||||
timeZone: tz,
|
||||
month: "short",
|
||||
}),
|
||||
}).format(asDate(value)),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -37,4 +37,36 @@ describe("formatter-cache", () => {
|
||||
expect(a).toBe(b);
|
||||
expect(a.format(new Date("2026-05-08T12:00:00Z"))).toBe("2026-05-08");
|
||||
});
|
||||
|
||||
// v1.28.42 (H2) — `makeFormatters` routes every date/time closure through
|
||||
// this cache, so the memo key MUST distinguish the two variables that make
|
||||
// otherwise-identical shapes render differently: the profile timezone and
|
||||
// the hour-cycle option. A collision on either would render the wrong wall
|
||||
// clock / wrong local day.
|
||||
it("keys DateTimeFormat by timeZone (no cross-tz collision)", () => {
|
||||
const opts = { hour: "2-digit", minute: "2-digit" } as const;
|
||||
const berlin = getDateTimeFormat("en-US", {
|
||||
...opts,
|
||||
timeZone: "Europe/Berlin",
|
||||
});
|
||||
const tokyo = getDateTimeFormat("en-US", {
|
||||
...opts,
|
||||
timeZone: "Asia/Tokyo",
|
||||
});
|
||||
expect(berlin).not.toBe(tokyo);
|
||||
// 14:30 UTC → 16:30 Berlin (CEST) vs 23:30 Tokyo.
|
||||
const sample = new Date("2026-04-18T14:30:00Z");
|
||||
expect(berlin.format(sample)).not.toBe(tokyo.format(sample));
|
||||
});
|
||||
|
||||
it("keys DateTimeFormat by hour-cycle option", () => {
|
||||
const base = {
|
||||
timeZone: "Europe/Berlin",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
} as const;
|
||||
const auto = getDateTimeFormat("en-US", base);
|
||||
const h24 = getDateTimeFormat("en-US", { ...base, hourCycle: "h23" });
|
||||
expect(auto).not.toBe(h24);
|
||||
});
|
||||
});
|
||||
@@ -105,6 +105,17 @@ export const measurementDependentKeys = [
|
||||
/**
|
||||
* Keys that should be invalidated when a mood entry is created, updated or
|
||||
* deleted.
|
||||
*
|
||||
* v1.28.42 (M2) — `dashboardSnapshot` joins the bundle, mirroring the
|
||||
* measurement (v1.18.9) and medication (v1.16.11) fixes for the same #38
|
||||
* stale-read class. The dashboard snapshot embeds a mood block and feeds the
|
||||
* score ring, but `moodDependentKeys` omitted the key, so a mood logged from
|
||||
* the Startseite quick-entry sheet (or on `/mood`) left the dashboard tile /
|
||||
* score showing the pre-write value for up to ~120 s (the snapshot query runs
|
||||
* refetchOnMount/WindowFocus off with a 120 s poll). The server snapshot bucket
|
||||
* is already hard-evicted on a mood write (`invalidateUserMood` sweeps
|
||||
* `${userId}|`), so the refetch this invalidation triggers returns post-write
|
||||
* data at once.
|
||||
*/
|
||||
export const moodDependentKeys = [
|
||||
queryKeys.moodEntries(),
|
||||
@@ -113,6 +124,7 @@ export const moodDependentKeys = [
|
||||
queryKeys.insightsRoot(),
|
||||
queryKeys.insightsTargets(),
|
||||
queryKeys.gamificationAchievements(),
|
||||
queryKeys.dashboardSnapshot(),
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user