Unify daily dog-work status - #61
Conversation
|
daily counts are memoized against an array that is mutated in place useDailySessionCounts() memoizes against [reports, today]. However, the store deliberately mutates nested arrays and objects in place, then only shallow-clones the outer db object to trigger rendering. In particular: createReport() uses db.reports.push(report). React therefore rerenders after an edited report, but reports still has the same reference, so the memoized count is reused. On the dog profile: changing a log from yesterday to today may leave the dog showing not worked today; That directly contradicts the PR’s stated derived-only behavior, where correcting or backdating a report should immediately recompute the canonical count. Fix: depend on the full database snapshot rather than the nested array reference, or simply compute the inexpensive count without useMemo, for example: export function useDailySessionCounts(): Record<string, number> { return useMemo( A component-level regression test should simulate an in-place sessionDate edit followed by a new outer-store snapshot. The current tests validate the pure counting and assignment functions but cannot expose this React memoization failure. Everything else is well aligned with #47: zero/one/multiple states are distinct, attention is limited to assigned dogs in the pinned folder, transferred sources are excluded, and midnight rollover is explicitly handled. CI is fully green. |
|
Addressed in 4c6e637. I removed the memoization entirely, so useDailySessionCounts() now derives the inexpensive count from the current report contents on every database render and cannot be held stale by a stable nested-array reference. I also added a regression that keeps the same reports array/object, mutates sessionDate in place, appends in place, then backdates in place, verifying the counts transition 0 → 1 → 2 → 1. Local validation passes: 21 tests, app and worker typechecks, lint (three pre-existing warnings only), diff check, and production build. |
Summary
sessionDateand local calendar dateReset behavior
The indicator remains derived-only rather than adding a manual reset override. A resettable flag could disagree with the actual logs and with backdated edits; deleting, correcting, or backdating the underlying report immediately recomputes the canonical count instead.
Validation
npm test(20/20)npm run buildnpx tsc -bnpm run lint(only three pre-existing warnings)npm --prefix worker run typecheckgit diff --checkCloses #47