From 342374b97fd9005683d917497d9b1e0df65888a0 Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 28 May 2026 18:05:03 -0600 Subject: [PATCH] Guard preset lookup, drop dead Media import and volume*1 no-op Address Greptile review on PR #447: - Fall back to the minimum preset when an unrecognized/stale water_calculator_preset is read from localStorage, so a bad persisted value can no longer crash the component on mount. - Remove the unused Media import. - Simplify the metric branch of waterWeight (volume * 1 -> volume). Co-Authored-By: Claude Opus 4.8 (1M context) --- app/src/components/calculators/WaterCalculator.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/components/calculators/WaterCalculator.js b/app/src/components/calculators/WaterCalculator.js index 42ac3744..b91ce9a7 100644 --- a/app/src/components/calculators/WaterCalculator.js +++ b/app/src/components/calculators/WaterCalculator.js @@ -3,7 +3,6 @@ import {GridColumn, Input, Label, TableBody, TableCell, TableHeader, TableHeader import Grid from "semantic-ui-react/dist/commonjs/collections/Grid"; import {Form, Header, Segment, Table} from "../Theme"; import {InfoPopup, roundDigits, Toggle, useLocalStorage} from "../Common"; -import {Media} from "../../contexts/contexts"; // Pure calculation functions for the Water Storage calculator. // @@ -54,7 +53,7 @@ export function waterWeight(volume, metric) { if (!(volume > 0)) { return null; } - return metric ? volume * 1 : volume * 8.345; + return metric ? volume : volume * 8.345; } /** @@ -217,8 +216,10 @@ export function WaterCalculator() { DURATION_STOPS.indexOf(14)); // Reset the editable rates to the preset's defaults whenever the preset or unit changes. + // Fall back to the minimum preset if localStorage holds an unrecognized/stale key, so a + // bad persisted value can never crash the component on mount. React.useEffect(() => { - const p = WATER_PRESETS[preset]; + const p = WATER_PRESETS[preset] ?? WATER_PRESETS.minimum; setRates(metric ? {...p.metric} : {...p.imperial}); }, [preset, metric]);