fix(decoder): connect even when the browser storage is full
A big installation outgrew the localStorage quota; saveState() threw QuotaExceededError and, since connecting saves first, the decoder never came online. The local copy is only a cache of the server state, so a write that doesn't fit now drops it instead of throwing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c8a797fe6f
commit
2c6c37f6ca
9 files changed
+99
-4
No files matched your search
+5
-1
@@ -30,6 +30,7 @@ import { renderEventManagerMarkup } from "./event_manager_view.js";
|
||||
import { renderEventManagerView } from "./event_manager_controller.js";
|
||||
import { createDefaultAmmcConfigHelper, getManagedWsUrlHelper, loadAmmcConfigFromBackendHelper, saveAmmcConfigToBackendHelper, refreshAmmcStatusHelper, startManagedAmmcHelper, stopManagedAmmcHelper, applyPersistedStateHelper, hydrateFromBackendHelper, scheduleBackendSyncHelper, syncStateToBackendHelper, pingBackendHelper, checkAppVersionHelper, startAppVersionPollingHelper, startOverlaySyncHelper, startBackgroundHydrationHelper, startOverlayRotationHelper, startOverlayLiveRefreshHelper, ensureAudioContextHelper, playPassingBeepHelper, playFinishSirenHelper, playLeaderCueHelper, playStartCueHelper, playBestLapCueHelper, pushOverlayEventHelper, getSpeechVoicesHelper, speakTextHelper, announceRaceStartedHelper, announceRaceFinishedHelper, handleSessionTimerTickHelper, tickClockHelper } from "./runtime_services.js";
|
||||
import { connectDecoderHelper, disconnectDecoderHelper, processDecoderMessageHelper } from "./decoder_runtime.js";
|
||||
import { writeLocalCache } from "./local_cache.js";
|
||||
import { normalizeTrainingState as normalizeTrainingStateLogic, syncTrainingLedger as syncTrainingLedgerLogic, buildDriverTrainingStats as buildDriverTrainingStatsLogic, buildDriverTimingChannelStats as buildDriverTimingChannelStatsLogic, buildDriverActivePracticeStats as buildDriverActivePracticeStatsLogic, buildEvenLapsProgress as buildEvenLapsProgressLogic, buildStepTrainingProgress as buildStepTrainingProgressLogic, buildTrainingRecommendation as buildTrainingRecommendationLogic, getTrainingGoalProgress as getTrainingGoalProgressLogic, getNextTrainingMilestone as getNextTrainingMilestoneLogic, buildTrainingMissions as buildTrainingMissionsLogic, buildTrainingHighlights as buildTrainingHighlightsLogic, getClubTrainingGoalProgress as getClubTrainingGoalProgressLogic, countDriverExerciseSessions as countDriverExerciseSessionsLogic, countExerciseSessions as countExerciseSessionsLogic, buildTrainingPaceBuckets as buildTrainingPaceBucketsLogic, buildTrainingWeekdayStats as buildTrainingWeekdayStatsLogic, buildTrainingStintAnalysis as buildTrainingStintAnalysisLogic, buildTrainingMarkerComparisons as buildTrainingMarkerComparisonsLogic } from "./training_logic.js";
|
||||
import { renderTrainingView } from "./training_views.js";
|
||||
import { renderResultsArchiveView } from "./results_archive_view.js";
|
||||
@@ -757,6 +758,7 @@ function getSessionTypeChoices(mode) {
|
||||
return mode === "track" ? SESSION_TYPES.filter((type) => type !== "team_race") : SESSION_TYPES;
|
||||
}
|
||||
const STORAGE_KEY = "rc_timing_control_v1";
|
||||
let localCacheFull = false;
|
||||
const DEFAULT_LANGUAGE = "sv";
|
||||
const DEFAULT_THEME = "dark";
|
||||
const AVAILABLE_THEMES = ["dark", "nord", "light"];
|
||||
@@ -5079,7 +5081,9 @@ function loadState() {
|
||||
|
||||
function saveState(options = {}) {
|
||||
const persistable = buildPersistableState();
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(persistable));
|
||||
const cached = writeLocalCache(localStorage, STORAGE_KEY, persistable);
|
||||
if (!cached.ok && !localCacheFull) console.warn("Browser storage is full; the local cache is dropped and the server's state is used.", cached.error);
|
||||
localCacheFull = !cached.ok;
|
||||
if (!options.skipBackend) {
|
||||
localStateVersion += 1;
|
||||
localStateDirty = true;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// The browser's localStorage copy of the state is only a cache: the server's SQLite state is the
|
||||
// truth and every page load hydrates from it. A big installation (results, training ledger, logo)
|
||||
// outgrows the ~5 MB quota, and setItem then throws - which used to abort whatever called
|
||||
// saveState(), e.g. connecting the decoder. A cache that can't be written is dropped instead
|
||||
// (the page then starts from the server like a fresh browser); a cut-down copy is never kept,
|
||||
// since a partial state could be synced back over the server's.
|
||||
export function writeLocalCache(storage, key, value) {
|
||||
try {
|
||||
storage.setItem(key, JSON.stringify(value));
|
||||
return { ok: true };
|
||||
} catch (error) {
|
||||
try { storage.removeItem(key); } catch {}
|
||||
return { ok: false, error };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user