From 010f35e90eb628f415c52a185cf90bca9c63a6b6 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 9 Jan 2026 04:08:20 +0000 Subject: [PATCH] Fix stuck placeholder when GPS timestamps do not advance Introduced a sample count fallback (`speedSampleCount`) for the GPS warmup logic. The application now displays speed if either the GPS timestamp advances by 1000ms OR 5 valid speed samples are received. This prevents the "stuck placeholder" issue when the GPS device reports valid speed data but timestamps are stagnant or update slowly, while still primarily relying on `pos.timestamp` as requested. `lastUpdateTimestamp` remains strictly tied to `pos.timestamp` for accurate data age calculations. --- package-lock.json | 4 ++-- package.json | 2 +- src/app.ts | 11 ++++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5ebd079..b7da2ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "speedometer", - "version": "0.0.82", + "version": "0.0.83", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "speedometer", - "version": "0.0.82", + "version": "0.0.83", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 04642d3..7edaae9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "speedometer", - "version": "0.0.82", + "version": "0.0.83", "description": "Minimal PWA speedometer that displays GPS speed. Includes TypeScript script to render PNG icons from SVG using sharp.", "license": "MIT", "private": true, diff --git a/src/app.ts b/src/app.ts index d54883f..981c8d0 100644 --- a/src/app.ts +++ b/src/app.ts @@ -19,8 +19,10 @@ let lastSpeedMs: number | null = null; // last known native speed (m/s), if any let lastUpdateTimestamp = 0; let wakeLock: WakeLockSentinel | null = null; let firstSpeedTimestamp: number | null = null; +let speedSampleCount = 0; const GPS_WARMUP_MS = 1000; +const MIN_SAMPLES_TO_SKIP_WARMUP = 5; export const PLACEHOLDER = "———"; @@ -261,9 +263,15 @@ function handlePosition(pos: GeolocationPosition): void { if (typeof speed === "number" && Number.isFinite(speed) && speed >= 0) { if (firstSpeedTimestamp === null) { firstSpeedTimestamp = pos.timestamp; + speedSampleCount = 0; } - if (pos.timestamp - firstSpeedTimestamp >= GPS_WARMUP_MS) { + speedSampleCount++; + + if ( + pos.timestamp - firstSpeedTimestamp >= GPS_WARMUP_MS || + speedSampleCount >= MIN_SAMPLES_TO_SKIP_WARMUP + ) { lastSpeedMs = speed; renderSpeed(speed); lastUpdateTimestamp = pos.timestamp; @@ -363,6 +371,7 @@ export function resetState(): void { lastUpdateTimestamp = 0; wakeLock = null; firstSpeedTimestamp = null; + speedSampleCount = 0; } export function init(): void {