fix(frontend): Weekly view must always send an explicit date to /grade #104
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: Jinemi/thermograph#104
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/weekly-utc-today-date"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The bug
Reported from Kaunas (UTC+3): at ~05:00 local on the 26th, the Weekly tab renders the 25th. The Day Detail page, asked for the same date, is correct.
Cause
runGrade()infrontend/static/app.jsdeliberately dropped thedate=parameter from the/api/v2/graderequest whenever the selected date equalled the viewer's local today — an old cache-key optimisation, so the URL would match the dateless URL the cross-view prefetch seeded.With no
datesupplied, the backend falls back to its own clock, which is UTC (api_grade'sdatedefault inbackend/web/app.py). Between local midnight and UTC midnight, any viewer east of UTC asks for today and is served yesterday. Every other date works, because those are sent explicitly.day.jsalways sends the date, which is exactly why Day Detail stayed correct.The cache-key "optimisation" was the other half of the same bug rather than a reason to keep it:
cache.js'sviewFetches()seeded the grade slice under that same dateless URL, stamped fresh for the viewer's local day regardless of which day the server actually resolved — so a same-tab navigation that had already prefetched the cell (e.g. arriving from the Day page) could serve the stale, server-resolved slice straight out of IndexedDB with no live request going out at all.The fix
static/app.js—runGrade()now builds exactly one URL and always includesdate=.dateInput.valuecan come back empty from a cleared native date field, so it falls back totodayISO()rather than ever sendingdate=empty (an empty value hits the identical server-side UTC fallback).day.jsalready guards the same input the same way.static/cache.js— the prefetch is kept working rather than dropped:viewFetches()seeds the grade slice under the dated URL (matching what the view now requests), the/cellbundle request states the client's localtoday, and seeding usesbundle.today— the date the server actually resolved — so the seeded key stays byte-identical to the per-view request even if the two ever disagree across a midnight boundary.tests/unit/test_app_js_grade_date.py— regression guard. There is no JS/DOM test harness in this repo to driveapp.jsand assert on the realfetch()URL, so this treats the shipped source as data over the existing served-asset route (GET {B}/app.js) and asserts the structural property: one grade URL, always with an explicit non-emptydate=. It fails against the pre-fix source. A source guard, not a substitute for a behavioural test.Backend needs no change for the correctness fix —
/gradealready honours an explicitdate.