From b172a4c9d6601f166104f9297e51761517a2f2ee Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 9 Jul 2026 15:27:08 -0600 Subject: [PATCH] Calculators: never store NaN as the Kelvin temperature. Clearing the temperature input stored parseFloat('') = NaN, rendering every Kelvin cell as NaN and persisting the invalid value in localStorage across reloads. Clearing now falls back to room temperature, non-numeric input is ignored, and a bad stored value decodes to the default. Co-Authored-By: Claude Fable 5 --- .../calculators/ElectricalCalculators.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/components/calculators/ElectricalCalculators.js b/app/src/components/calculators/ElectricalCalculators.js index 4a272e08..ba223e68 100644 --- a/app/src/components/calculators/ElectricalCalculators.js +++ b/app/src/components/calculators/ElectricalCalculators.js @@ -455,15 +455,27 @@ export const calcKelvinMilliVoltDrop = (amps, resistancePerKiloLength, length, const FourWireKelvinCalculator = ({wireType, isSAE, length}) => { const [ampsRange] = useState([1, 5, 10]); // Stored in Celsius; displayed in Fahrenheit when SAE. Default is room temperature. + const decodeTemperature = (value) => { + const temperature = parseFloat(value); + return Number.isFinite(temperature) ? temperature : REFERENCE_TEMPERATURE_C; + }; const [temperatureC, setTemperatureC] = useLocalStorage( - 'calculators.kelvin.temperature_c', REFERENCE_TEMPERATURE_C, parseFloat, (num) => num.toString()); + 'calculators.kelvin.temperature_c', REFERENCE_TEMPERATURE_C, decodeTemperature, (num) => num.toString()); const resistances = isSAE ? resistancesPerKFeet[wireType] : resistancesPerKm[wireType]; const displayTemperature = isSAE ? roundDigits(temperatureC * 9 / 5 + 32, 1) : roundDigits(temperatureC, 1); const handleTemperatureChange = (value) => { + if (value === '') { + // Never store NaN; fall back to room temperature when the input is cleared. + setTemperatureC(REFERENCE_TEMPERATURE_C); + return; + } const temperature = parseFloat(value); + if (!Number.isFinite(temperature)) { + return; + } setTemperatureC(isSAE ? (temperature - 32) * 5 / 9 : temperature); };