From d01d83e2c6094c81ed93933fb4907b72636101df Mon Sep 17 00:00:00 2001 From: llama <100429699+iamllama@users.noreply.github.com> Date: Tue, 7 Jan 2025 22:13:43 +0800 Subject: [PATCH] convert floats to single-precision before comparing in isModified (#3686) --- ts/routes/deck-options/lib.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ts/routes/deck-options/lib.ts b/ts/routes/deck-options/lib.ts index 549157757..a7295ddf6 100644 --- a/ts/routes/deck-options/lib.ts +++ b/ts/routes/deck-options/lib.ts @@ -12,7 +12,7 @@ import { DeckConfig, DeckConfig_Config, DeckConfigsForUpdate_CurrentDeck_Limits import { updateDeckConfigs } from "@generated/backend"; import { localeCompare } from "@tslib/i18n"; import { promiseWithResolver } from "@tslib/promise"; -import { cloneDeep, isEqual } from "lodash-es"; +import { cloneDeep, isEqual, isEqualWith } from "lodash-es"; import { tick } from "svelte"; import type { Readable, Writable } from "svelte/store"; import { get, readable, writable } from "svelte/store"; @@ -337,7 +337,16 @@ export class DeckOptionsState { async isModified(): Promise { const original = await this.originalConfigsPromise; const current = this.getAllConfigs(); - return !isEqual(original, current); + return !isEqualWith(original, current, (lhs, rhs) => { + if (typeof lhs === "number" && typeof rhs === "number") { + // rslib hands us 32-bit floats (f32), while ts uses 64-bit floats + // SpinBox and ParamsInput both round their values as f64 on blur + // while the original config's corresponding value remains an f32 + // so we convert both to f32 before checking for equality + return Math.fround(lhs) === Math.fround(rhs); + } + // undefined means fallback to isEqual + }); } resolveOriginalConfigs(): void {