From 7a82ca338300a6ac2a5dea714cbdf0a1545b6bf8 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Tue, 4 Aug 2026 18:10:27 +0000 Subject: [PATCH 1/6] fix: stop Canvas Navigation mode resetting to Custom on reload Navigation Mode is stored independently of the Left Mouse Click Behavior and Mouse Wheel Scroll overrides it implies, and the three were kept in sync by cross-writes in onChange. Two paths lost the mode the user picked: - applySettingLocally fired onChange before committing the new value, so the overrides written by a preset read back the mode it replaced, decided they no longer matched it, and demoted it to 'custom'. Commit the value first so the cascade observes the mode it is applying. - A mode stored before the overrides shipped in 1.27.4 is the only value on record, so the overrides loaded as their defaults, which describe 'legacy'. The override handlers then rewrote any other stored mode to 'custom' on the first load after upgrading. Treat a stored preset as authoritative instead: on registration it now supplies the overrides that were never stored. The second point is why fixing only the write order is not enough, and why the override handlers are not simply muted during registration - that would keep the dropdown reading Standard while the canvas still panned and zoomed like Legacy. --- browser_tests/tests/canvasSettings.spec.ts | 54 +++++++++++++++++++ .../settings/constants/coreSettings.ts | 42 ++++++++++----- src/platform/settings/settingStore.test.ts | 15 ++++++ src/platform/settings/settingStore.ts | 12 +++-- 4 files changed, 106 insertions(+), 17 deletions(-) diff --git a/browser_tests/tests/canvasSettings.spec.ts b/browser_tests/tests/canvasSettings.spec.ts index 7449839e657..16498f2e778 100644 --- a/browser_tests/tests/canvasSettings.spec.ts +++ b/browser_tests/tests/canvasSettings.spec.ts @@ -188,6 +188,60 @@ test.describe('Canvas settings', { tag: '@canvas' }, () => { }) }) + test.describe('Comfy.Canvas.NavigationMode', () => { + test('picking a preset never persists custom', async ({ comfyPage }) => { + const modeWrites: unknown[] = [] + comfyPage.page.on('request', (request) => { + if ( + request.method() === 'POST' && + request.url().endsWith('/api/settings/Comfy.Canvas.NavigationMode') + ) { + modeWrites.push(request.postDataJSON()) + } + }) + + await comfyPage.settings.setSetting( + 'Comfy.Canvas.NavigationMode', + 'standard' + ) + await comfyPage.workflow.reloadAndWaitForApp() + + // A preset also writes the two overrides it implies; those writes must + // not read back as the user hand-picking an override. + expect(modeWrites).not.toContain('custom') + expect( + await comfyPage.settings.getSetting('Comfy.Canvas.NavigationMode') + ).toBe('standard') + }) + + // A mode stored before the overrides shipped in 1.27.4 is the only value on + // record, so they load as their defaults — which describe a different mode. + test.describe('stored without the override settings', () => { + test.use({ + initialSettings: { 'Comfy.Canvas.NavigationMode': 'standard' } + }) + + test('keeps the stored preset through load', async ({ comfyPage }) => { + expect( + await comfyPage.settings.getSetting('Comfy.Canvas.NavigationMode') + ).toBe('standard') + }) + + test('applies the stored preset to the overrides', async ({ + comfyPage + }) => { + expect( + await comfyPage.settings.getSetting( + 'Comfy.Canvas.LeftMouseClickBehavior' + ) + ).toBe('select') + expect( + await comfyPage.settings.getSetting('Comfy.Canvas.MouseWheelScroll') + ).toBe('panning') + }) + }) + }) + test.describe('Comfy.Canvas.LeftMouseClickBehavior', () => { test('override to panning makes empty left-drag pan the canvas', async ({ comfyPage diff --git a/src/platform/settings/constants/coreSettings.ts b/src/platform/settings/constants/coreSettings.ts index 3bf106bbaab..74c0e4a6556 100644 --- a/src/platform/settings/constants/coreSettings.ts +++ b/src/platform/settings/constants/coreSettings.ts @@ -7,12 +7,24 @@ import { isCloud, isDesktop, isNightly } from '@/platform/distribution/types' import { TOUR_SEEN_SETTING } from '@/platform/onboarding/onboardingTours' import { useSettingStore } from '@/platform/settings/settingStore' import type { SettingParams } from '@/platform/settings/types' +import type { Settings } from '@/schemas/apiSchema' import type { ColorPalettes } from '@/schemas/colorPaletteSchema' import type { Keybinding } from '@/platform/keybindings/types' import { NodeBadgeMode } from '@/types/nodeSource' import { LinkReleaseTriggerAction } from '@/types/searchBoxTypes' import { breakpointsTailwind } from '@vueuse/core' +const CANVAS_NAVIGATION_PRESETS: Record> = { + standard: { + 'Comfy.Canvas.LeftMouseClickBehavior': 'select', + 'Comfy.Canvas.MouseWheelScroll': 'panning' + }, + legacy: { + 'Comfy.Canvas.LeftMouseClickBehavior': 'panning', + 'Comfy.Canvas.MouseWheelScroll': 'zoom' + } +} + /** * Core settings are essential configuration parameters required for ComfyUI's basic functionality. * These settings must be present in the settings store and cannot be omitted. @@ -188,22 +200,26 @@ export const CORE_SETTINGS: SettingParams[] = [ '1.25.0': 'legacy' }, onChange: async (val: unknown, old?: unknown) => { - const newValue = val as string - const oldValue = old as string | undefined - if (!oldValue) return + const preset = CANVAS_NAVIGATION_PRESETS[val as string] + if (!preset) return const settingStore = useSettingStore() - if (newValue === 'standard') { - await settingStore.setMany({ - 'Comfy.Canvas.LeftMouseClickBehavior': 'select', - 'Comfy.Canvas.MouseWheelScroll': 'panning' - }) - } else if (newValue === 'legacy') { - await settingStore.setMany({ - 'Comfy.Canvas.LeftMouseClickBehavior': 'panning', - 'Comfy.Canvas.MouseWheelScroll': 'zoom' - }) + if (old) { + await settingStore.setMany(preset) + return } + + // Registration replay. A preset stored before the overrides shipped in + // 1.27.4 is the only record of the choice, so it has to supply the ones + // still missing instead of being overruled by their defaults. + if (!settingStore.exists('Comfy.Canvas.NavigationMode')) return + + const unset = Object.fromEntries( + Object.entries(preset).filter( + ([id]) => !settingStore.exists(id as keyof Settings) + ) + ) + if (Object.keys(unset).length) await settingStore.setMany(unset) } }, { diff --git a/src/platform/settings/settingStore.test.ts b/src/platform/settings/settingStore.test.ts index d942f543ddf..27d0a9d003c 100644 --- a/src/platform/settings/settingStore.test.ts +++ b/src/platform/settings/settingStore.test.ts @@ -420,6 +420,21 @@ describe('useSettingStore', () => { ) }) + it('exposes the new value to onChange handlers', async () => { + const observed: unknown[] = [] + store.addSetting({ + id: 'test.setting', + name: 'test.setting', + type: 'text', + defaultValue: 'default', + onChange: () => observed.push(store.get('test.setting')) + }) + + await store.set('test.setting', 'newvalue') + + expect(observed).toEqual(['default', 'newvalue']) + }) + it('tracks visible settings with values by default', async () => { store.addSetting({ id: 'test.setting', diff --git a/src/platform/settings/settingStore.ts b/src/platform/settings/settingStore.ts index 72bac5e4b6b..0b406383aea 100644 --- a/src/platform/settings/settingStore.ts +++ b/src/platform/settings/settingStore.ts @@ -121,9 +121,13 @@ export const useSettingStore = defineStore('setting', () => { } /** - * Apply a setting value locally: clone, migrate, fire onChange, and - * update the in-memory store. Returns the migrated value, or - * `undefined` when the value is unchanged and was skipped. + * Apply a setting value locally: clone, migrate, update the in-memory + * store, and fire onChange. Returns the migrated value, or `undefined` + * when the value is unchanged and was skipped. + * + * The store is updated before `onChange` runs so that handlers reading + * this setting — including handlers of other settings this one cascades + * into — observe the new value rather than the one it replaced. */ function applySettingLocally( key: K, @@ -137,9 +141,9 @@ export const useSettingStore = defineStore('setting', () => { const oldValue = get(key) if (newValue === oldValue) return undefined - onChange(settingsById.value[key], newValue, oldValue) const typedNewValue = newValue as Settings[K] settingValues.value[key] = typedNewValue + onChange(settingsById.value[key], newValue, oldValue) return { previousValue: oldValue, newValue: typedNewValue From a5b95002d8cabf0b2de57da8056541e0ccf2fbf5 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Wed, 5 Aug 2026 05:04:28 +0000 Subject: [PATCH 2/6] refactor(settings): move the navigation override repair into load() Addresses review on #14716. Healing a pre-1.27.4 profile from the mode's own onChange registration replay had three problems the load() hook does not: the write was detached and unhandled because onChange() discarded the returned promise, it silently depended on CORE_SETTINGS registering the mode before the two overrides, and it wrote keys whose settingsById entries did not exist yet, so those writes skipped dispatchChange and telemetry. migrateCanvasNavigationOverrides() now runs from load() alongside the existing zoom-threshold migration, before any setting is registered, so onChange goes back to meaning "the user changed something". The preset pairs move to constants/canvasNavigation.ts so both call sites share one definition without a cycle. Also await the handler in onChange() so a cascading write completes before the caller writes its own key. The two were racing against the backend's non-atomic read-modify-write, which left the fix probabilistic; committing the value first is what makes awaiting safe, since the newValue === oldValue guard now compares against committed state. Tests: migration unit coverage for the stored-preset, partial-override, custom and unstored profiles; an invariant test that the override defaults describe whichever mode a fresh profile resolves to, so flipping that default trips a test instead of demoting every new install; and E2E cover for the already-demoted profile, the partial profile, the custom no-op, plus a reload so the override assertions test persistence. --- browser_tests/tests/canvasSettings.spec.ts | 73 ++++++++++++++++- .../constants/canvasNavigation.test.ts | 40 ++++++++++ .../settings/constants/canvasNavigation.ts | 22 ++++++ .../settings/constants/coreSettings.ts | 32 +------- src/platform/settings/settingStore.test.ts | 78 +++++++++++++++++++ src/platform/settings/settingStore.ts | 56 ++++++++++--- 6 files changed, 261 insertions(+), 40 deletions(-) create mode 100644 src/platform/settings/constants/canvasNavigation.test.ts create mode 100644 src/platform/settings/constants/canvasNavigation.ts diff --git a/browser_tests/tests/canvasSettings.spec.ts b/browser_tests/tests/canvasSettings.spec.ts index 16498f2e778..13f909a5130 100644 --- a/browser_tests/tests/canvasSettings.spec.ts +++ b/browser_tests/tests/canvasSettings.spec.ts @@ -208,12 +208,35 @@ test.describe('Canvas settings', { tag: '@canvas' }, () => { // A preset also writes the two overrides it implies; those writes must // not read back as the user hand-picking an override. + expect(modeWrites).toContain('standard') expect(modeWrites).not.toContain('custom') expect( await comfyPage.settings.getSetting('Comfy.Canvas.NavigationMode') ).toBe('standard') }) + test('picking custom leaves the overrides untouched', async ({ + comfyPage + }) => { + await comfyPage.settings.setSetting( + 'Comfy.Canvas.NavigationMode', + 'custom' + ) + await comfyPage.workflow.reloadAndWaitForApp() + + expect( + await comfyPage.settings.getSetting('Comfy.Canvas.NavigationMode') + ).toBe('custom') + expect( + await comfyPage.settings.getSetting( + 'Comfy.Canvas.LeftMouseClickBehavior' + ) + ).toBe('panning') + expect( + await comfyPage.settings.getSetting('Comfy.Canvas.MouseWheelScroll') + ).toBe('zoom') + }) + // A mode stored before the overrides shipped in 1.27.4 is the only value on // record, so they load as their defaults — which describe a different mode. test.describe('stored without the override settings', () => { @@ -227,9 +250,13 @@ test.describe('Canvas settings', { tag: '@canvas' }, () => { ).toBe('standard') }) - test('applies the stored preset to the overrides', async ({ + test('persists the stored preset to the overrides', async ({ comfyPage }) => { + // Reload first so this asserts what reached the server, not just what + // the migration put in the in-memory store. + await comfyPage.workflow.reloadAndWaitForApp() + expect( await comfyPage.settings.getSetting( 'Comfy.Canvas.LeftMouseClickBehavior' @@ -240,6 +267,50 @@ test.describe('Canvas settings', { tag: '@canvas' }, () => { ).toBe('panning') }) }) + + // Every profile that already loaded a 1.27.4+ build has the mode demoted to + // 'custom' with the overrides never written. The original choice is + // unrecoverable, so this pins the no-op as deliberate. + test.describe('already demoted to custom', () => { + test.use({ + initialSettings: { 'Comfy.Canvas.NavigationMode': 'custom' } + }) + + test('is left as custom', async ({ comfyPage }) => { + expect( + await comfyPage.settings.getSetting('Comfy.Canvas.NavigationMode') + ).toBe('custom') + }) + }) + + test.describe('stored with only one override', () => { + test.use({ + initialSettings: { + 'Comfy.Canvas.NavigationMode': 'standard', + 'Comfy.Canvas.MouseWheelScroll': 'zoom' + } + }) + + test('fills the gap without overwriting the stored override', async ({ + comfyPage + }) => { + expect( + await comfyPage.settings.getSetting( + 'Comfy.Canvas.LeftMouseClickBehavior' + ) + ).toBe('select') + expect( + await comfyPage.settings.getSetting('Comfy.Canvas.MouseWheelScroll') + ).toBe('zoom') + + // select + zoom is no preset, so demoting the mode is correct here. + // Overwriting the stored 'zoom' to match the mode instead would + // discard a real preference, which is the bug this all started as. + expect( + await comfyPage.settings.getSetting('Comfy.Canvas.NavigationMode') + ).toBe('custom') + }) + }) }) test.describe('Comfy.Canvas.LeftMouseClickBehavior', () => { diff --git a/src/platform/settings/constants/canvasNavigation.test.ts b/src/platform/settings/constants/canvasNavigation.test.ts new file mode 100644 index 00000000000..5a879f2b5a9 --- /dev/null +++ b/src/platform/settings/constants/canvasNavigation.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, it } from 'vitest' + +import { CANVAS_NAVIGATION_PRESETS } from '@/platform/settings/constants/canvasNavigation' +import { CORE_SETTINGS } from '@/platform/settings/constants/coreSettings' + +const NAV = 'Comfy.Canvas.NavigationMode' +const LEFT = 'Comfy.Canvas.LeftMouseClickBehavior' +const WHEEL = 'Comfy.Canvas.MouseWheelScroll' + +const settingById = (id: string) => CORE_SETTINGS.find((s) => s.id === id) + +const overrideDefaults = () => ({ + [LEFT]: settingById(LEFT)?.defaultValue, + [WHEEL]: settingById(WHEEL)?.defaultValue +}) + +describe('CANVAS_NAVIGATION_PRESETS', () => { + /** + * The override defaults have to describe whichever Navigation Mode a fresh + * profile resolves to. If they disagree, that profile loads with a mode no + * preset matches and the override handlers demote it to 'custom' on first + * load — the bug this pairing exists to prevent. Asserted as a relationship + * rather than against fixed values so changing a default is what trips it. + */ + it('agrees with the default Navigation Mode', () => { + const defaultMode = settingById(NAV)?.defaultValue as string + + expect(CANVAS_NAVIGATION_PRESETS[defaultMode]).toEqual(overrideDefaults()) + }) + + it('agrees with every install-versioned Navigation Mode default', () => { + const versioned = settingById(NAV)?.defaultsByInstallVersion ?? {} + + for (const mode of Object.values(versioned)) { + expect(CANVAS_NAVIGATION_PRESETS[mode as string]).toEqual( + overrideDefaults() + ) + } + }) +}) diff --git a/src/platform/settings/constants/canvasNavigation.ts b/src/platform/settings/constants/canvasNavigation.ts new file mode 100644 index 00000000000..b603a144d8f --- /dev/null +++ b/src/platform/settings/constants/canvasNavigation.ts @@ -0,0 +1,22 @@ +import type { Settings } from '@/schemas/apiSchema' + +/** + * The Left Mouse Click Behavior and Mouse Wheel Scroll values each Navigation + * Mode preset stands for. + * + * `custom` is deliberately absent: it means "the overrides are whatever the + * user set", so there is no pair to apply or to restore from it. + */ +export const CANVAS_NAVIGATION_PRESETS: Record< + string, + Partial | undefined +> = { + standard: { + 'Comfy.Canvas.LeftMouseClickBehavior': 'select', + 'Comfy.Canvas.MouseWheelScroll': 'panning' + }, + legacy: { + 'Comfy.Canvas.LeftMouseClickBehavior': 'panning', + 'Comfy.Canvas.MouseWheelScroll': 'zoom' + } +} diff --git a/src/platform/settings/constants/coreSettings.ts b/src/platform/settings/constants/coreSettings.ts index 74c0e4a6556..9f33d84e55f 100644 --- a/src/platform/settings/constants/coreSettings.ts +++ b/src/platform/settings/constants/coreSettings.ts @@ -5,26 +5,15 @@ import { } from '@/locales/localeConfig' import { isCloud, isDesktop, isNightly } from '@/platform/distribution/types' import { TOUR_SEEN_SETTING } from '@/platform/onboarding/onboardingTours' +import { CANVAS_NAVIGATION_PRESETS } from '@/platform/settings/constants/canvasNavigation' import { useSettingStore } from '@/platform/settings/settingStore' import type { SettingParams } from '@/platform/settings/types' -import type { Settings } from '@/schemas/apiSchema' import type { ColorPalettes } from '@/schemas/colorPaletteSchema' import type { Keybinding } from '@/platform/keybindings/types' import { NodeBadgeMode } from '@/types/nodeSource' import { LinkReleaseTriggerAction } from '@/types/searchBoxTypes' import { breakpointsTailwind } from '@vueuse/core' -const CANVAS_NAVIGATION_PRESETS: Record> = { - standard: { - 'Comfy.Canvas.LeftMouseClickBehavior': 'select', - 'Comfy.Canvas.MouseWheelScroll': 'panning' - }, - legacy: { - 'Comfy.Canvas.LeftMouseClickBehavior': 'panning', - 'Comfy.Canvas.MouseWheelScroll': 'zoom' - } -} - /** * Core settings are essential configuration parameters required for ComfyUI's basic functionality. * These settings must be present in the settings store and cannot be omitted. @@ -200,26 +189,11 @@ export const CORE_SETTINGS: SettingParams[] = [ '1.25.0': 'legacy' }, onChange: async (val: unknown, old?: unknown) => { + if (!old) return const preset = CANVAS_NAVIGATION_PRESETS[val as string] if (!preset) return - const settingStore = useSettingStore() - - if (old) { - await settingStore.setMany(preset) - return - } - - // Registration replay. A preset stored before the overrides shipped in - // 1.27.4 is the only record of the choice, so it has to supply the ones - // still missing instead of being overruled by their defaults. - if (!settingStore.exists('Comfy.Canvas.NavigationMode')) return - const unset = Object.fromEntries( - Object.entries(preset).filter( - ([id]) => !settingStore.exists(id as keyof Settings) - ) - ) - if (Object.keys(unset).length) await settingStore.setMany(unset) + await useSettingStore().setMany(preset) } }, { diff --git a/src/platform/settings/settingStore.test.ts b/src/platform/settings/settingStore.test.ts index 27d0a9d003c..602a1de68eb 100644 --- a/src/platform/settings/settingStore.test.ts +++ b/src/platform/settings/settingStore.test.ts @@ -68,6 +68,61 @@ describe('useSettingStore', () => { expect(api.getSettings).toHaveBeenCalled() }) + describe('Canvas Navigation override migration', () => { + const NAV = 'Comfy.Canvas.NavigationMode' + const LEFT = 'Comfy.Canvas.LeftMouseClickBehavior' + const WHEEL = 'Comfy.Canvas.MouseWheelScroll' + + const loadWith = async (persisted: Record) => { + vi.mocked(api.getSettings).mockResolvedValue(persisted as Settings) + await store.load() + } + + it('supplies both overrides for a stored preset', async () => { + await loadWith({ [NAV]: 'standard' }) + + expect(api.storeSettings).toHaveBeenCalledWith({ + [LEFT]: 'select', + [WHEEL]: 'panning' + }) + expect(store.settingValues).toMatchObject({ + [NAV]: 'standard', + [LEFT]: 'select', + [WHEEL]: 'panning' + }) + }) + + it('supplies only the override that is missing', async () => { + await loadWith({ [NAV]: 'standard', [WHEEL]: 'zoom' }) + + expect(api.storeSettings).toHaveBeenCalledWith({ [LEFT]: 'select' }) + expect(store.settingValues[WHEEL]).toBe('zoom') + }) + + it('leaves a stored custom mode alone', async () => { + await loadWith({ [NAV]: 'custom' }) + + expect(api.storeSettings).not.toHaveBeenCalled() + expect(store.settingValues[LEFT]).toBeUndefined() + }) + + it('leaves a profile with both overrides alone', async () => { + await loadWith({ + [NAV]: 'legacy', + [LEFT]: 'select', + [WHEEL]: 'panning' + }) + + expect(api.storeSettings).not.toHaveBeenCalled() + }) + + it('writes nothing for a profile with no stored mode', async () => { + await loadWith({}) + + expect(api.storeSettings).not.toHaveBeenCalled() + }) + }) + it('should set error if settings are loaded after registration', async () => { const setting: SettingParams = { id: 'test.setting', @@ -420,6 +475,29 @@ describe('useSettingStore', () => { ) }) + it('awaits an onChange handler before persisting the value', async () => { + const order: string[] = [] + vi.mocked(api.storeSetting).mockImplementation(async () => { + order.push('storeSetting') + return new Response() + }) + store.addSetting({ + id: 'test.setting', + name: 'test.setting', + type: 'text', + defaultValue: 'default', + onChange: async (_value, old) => { + if (!old) return + await Promise.resolve() + order.push('onChange') + } + }) + + await store.set('test.setting', 'newvalue') + + expect(order).toEqual(['onChange', 'storeSetting']) + }) + it('exposes the new value to onChange handlers', async () => { const observed: unknown[] = [] store.addSetting({ diff --git a/src/platform/settings/settingStore.ts b/src/platform/settings/settingStore.ts index 0b406383aea..9bd6d544f90 100644 --- a/src/platform/settings/settingStore.ts +++ b/src/platform/settings/settingStore.ts @@ -5,6 +5,7 @@ import { defineStore } from 'pinia' import { compare, valid } from 'semver' import { ref } from 'vue' +import { CANVAS_NAVIGATION_PRESETS } from '@/platform/settings/constants/canvasNavigation' import type { SettingParams } from '@/platform/settings/types' import { useTelemetry } from '@/platform/telemetry' import type { SettingChangedMetadata } from '@/platform/telemetry/types' @@ -37,19 +38,22 @@ function tryMigrateDeprecatedValue( return setting?.migrateDeprecatedValue?.(value) ?? value } -function onChange( +async function onChange( setting: SettingParams | undefined, newValue: unknown, oldValue: unknown ) { - if (setting?.onChange) { - setting.onChange(newValue, oldValue) - } + // Started before dispatchChange so extensions keep observing the change at + // the same point, but awaited afterwards: a handler that cascades into other + // settings must finish writing them before the caller writes this one, or + // the two requests race in the backend's read-modify-write. + const handled = setting?.onChange?.(newValue, oldValue) // Backward compatibility with old settings dialog. // Some extensions still listens event emitted by the old settings dialog. if (setting) { app.ui.settings.dispatchChange(setting.id, newValue, oldValue) } + await handled } function settingChangedEvent( @@ -95,6 +99,7 @@ export const useSettingStore = defineStore('setting', () => { delay: (attempt) => Math.min(1000 * Math.pow(2, attempt), 8000) }) await migrateZoomThresholdToFontSize() + await migrateCanvasNavigationOverrides() }, undefined, { immediate: false } @@ -129,10 +134,10 @@ export const useSettingStore = defineStore('setting', () => { * this setting — including handlers of other settings this one cascades * into — observe the new value rather than the one it replaced. */ - function applySettingLocally( + async function applySettingLocally( key: K, value: Settings[K] - ): AppliedSetting | undefined { + ): Promise | undefined> { const clonedValue = cloneDeep(value) const newValue = tryMigrateDeprecatedValue( settingsById.value[key], @@ -143,7 +148,7 @@ export const useSettingStore = defineStore('setting', () => { const typedNewValue = newValue as Settings[K] settingValues.value[key] = typedNewValue - onChange(settingsById.value[key], newValue, oldValue) + await onChange(settingsById.value[key], newValue, oldValue) return { previousValue: oldValue, newValue: typedNewValue @@ -156,7 +161,7 @@ export const useSettingStore = defineStore('setting', () => { * @param value - The value to set. */ async function set(key: K, value: Settings[K]) { - const applied = applySettingLocally(key, value) + const applied = await applySettingLocally(key, value) if (applied === undefined) return await api.storeSetting(key, applied.newValue) @@ -173,7 +178,7 @@ export const useSettingStore = defineStore('setting', () => { const telemetryEvents: SettingChangedMetadata[] = [] for (const key of Object.keys(settings) as (keyof Settings)[]) { - const applied = applySettingLocally( + const applied = await applySettingLocally( key, settings[key] as Settings[typeof key] ) @@ -302,7 +307,38 @@ export const useSettingStore = defineStore('setting', () => { settingValues.value[setting.id] ) } - onChange(setting, get(setting.id), undefined) + void onChange(setting, get(setting.id), undefined) + } + + /** + * A Navigation Mode preset stored before the Left Mouse Click Behavior and + * Mouse Wheel Scroll settings shipped in 1.27.4 is the only record of that + * choice. Materialise the overrides it implies before anything can read + * their defaults, which describe a different preset and would otherwise + * demote the stored mode to 'custom'. + * + * Runs from `load()` rather than the settings' own `onChange` so it is + * awaited, and so it does not depend on the order `CORE_SETTINGS` happens + * to register these three settings in. + */ + async function migrateCanvasNavigationOverrides() { + const storedMode = settingValues.value['Comfy.Canvas.NavigationMode'] + const preset = + typeof storedMode === 'string' + ? CANVAS_NAVIGATION_PRESETS[storedMode] + : undefined + if (!preset) return + + const unset: Partial = {} + for (const id of Object.keys(preset) as (keyof Settings)[]) { + if (settingValues.value[id] === undefined) { + Object.assign(unset, { [id]: preset[id] }) + } + } + if (!Object.keys(unset).length) return + + Object.assign(settingValues.value, unset) + await api.storeSettings(unset) } /** From 7cc222404ddbc6f2dd3163274eb3654b54fdcaf2 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Wed, 5 Aug 2026 05:15:19 +0000 Subject: [PATCH 3/6] fix(settings): declare onChange may return a promise Addresses review on #14716. The store awaits the handler now, but SettingParams.onChange still declared `void`. Async handlers only type-checked through void-return bivariance, so the contract did not say what the caller relies on. Declaring `void | Promise` immediately caught an implicit `number` return in the new settingStore test. Also start the custom-mode E2E case from the standard pair rather than the override defaults, so a handler that rewrote the overrides on the way to custom would fail the test instead of matching the defaults by coincidence. --- browser_tests/tests/canvasSettings.spec.ts | 11 +++++++++-- src/platform/settings/settingStore.test.ts | 4 +++- src/platform/settings/types.ts | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/browser_tests/tests/canvasSettings.spec.ts b/browser_tests/tests/canvasSettings.spec.ts index 13f909a5130..89abed332c7 100644 --- a/browser_tests/tests/canvasSettings.spec.ts +++ b/browser_tests/tests/canvasSettings.spec.ts @@ -218,6 +218,13 @@ test.describe('Canvas settings', { tag: '@canvas' }, () => { test('picking custom leaves the overrides untouched', async ({ comfyPage }) => { + // Arrive on the standard pair first, so both overrides differ from their + // defaults and a handler that rewrote them would be caught. + await comfyPage.settings.setSetting( + 'Comfy.Canvas.NavigationMode', + 'standard' + ) + await comfyPage.settings.setSetting( 'Comfy.Canvas.NavigationMode', 'custom' @@ -231,10 +238,10 @@ test.describe('Canvas settings', { tag: '@canvas' }, () => { await comfyPage.settings.getSetting( 'Comfy.Canvas.LeftMouseClickBehavior' ) - ).toBe('panning') + ).toBe('select') expect( await comfyPage.settings.getSetting('Comfy.Canvas.MouseWheelScroll') - ).toBe('zoom') + ).toBe('panning') }) // A mode stored before the overrides shipped in 1.27.4 is the only value on diff --git a/src/platform/settings/settingStore.test.ts b/src/platform/settings/settingStore.test.ts index 602a1de68eb..276c13784f9 100644 --- a/src/platform/settings/settingStore.test.ts +++ b/src/platform/settings/settingStore.test.ts @@ -505,7 +505,9 @@ describe('useSettingStore', () => { name: 'test.setting', type: 'text', defaultValue: 'default', - onChange: () => observed.push(store.get('test.setting')) + onChange: () => { + observed.push(store.get('test.setting')) + } }) await store.set('test.setting', 'newvalue') diff --git a/src/platform/settings/types.ts b/src/platform/settings/types.ts index c677acd98e4..bb5765fe513 100644 --- a/src/platform/settings/types.ts +++ b/src/platform/settings/types.ts @@ -40,7 +40,7 @@ export interface SettingParams extends FormItem { id: keyof Settings defaultValue: TValue | (() => TValue) defaultsByInstallVersion?: Record<`${number}.${number}.${number}`, TValue> - onChange?(newValue: TValue, oldValue?: TValue): void + onChange?(newValue: TValue, oldValue?: TValue): void | Promise telemetry?: SettingTelemetryOptions // By default category is id.split('.'). However, changing id to assign // new category has poor backward compatibility. Use this field to overwrite From 866a49ab412b205668e39ebddadccc0f8675365e Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Wed, 12 Aug 2026 22:30:33 +0000 Subject: [PATCH 4/6] refactor(settings): narrow navigation mode values instead of asserting Replace the 'as string' assertions on the unknown onChange value and on the Navigation Mode defaults with typeof narrowing, and resolve callable defaults the way the setting store does. --- .../constants/canvasNavigation.test.ts | 23 +++++++++++++------ .../settings/constants/coreSettings.ts | 4 ++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/platform/settings/constants/canvasNavigation.test.ts b/src/platform/settings/constants/canvasNavigation.test.ts index 5a879f2b5a9..8e52d2e11e2 100644 --- a/src/platform/settings/constants/canvasNavigation.test.ts +++ b/src/platform/settings/constants/canvasNavigation.test.ts @@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest' import { CANVAS_NAVIGATION_PRESETS } from '@/platform/settings/constants/canvasNavigation' import { CORE_SETTINGS } from '@/platform/settings/constants/coreSettings' +import type { SettingParams } from '@/platform/settings/types' const NAV = 'Comfy.Canvas.NavigationMode' const LEFT = 'Comfy.Canvas.LeftMouseClickBehavior' @@ -9,9 +10,19 @@ const WHEEL = 'Comfy.Canvas.MouseWheelScroll' const settingById = (id: string) => CORE_SETTINGS.find((s) => s.id === id) +const resolveDefaultValue = (setting: SettingParams | undefined): unknown => { + const { defaultValue } = setting ?? {} + return typeof defaultValue === 'function' + ? (defaultValue as () => unknown)() + : defaultValue +} + +const presetForMode = (mode: unknown) => + typeof mode === 'string' ? CANVAS_NAVIGATION_PRESETS[mode] : undefined + const overrideDefaults = () => ({ - [LEFT]: settingById(LEFT)?.defaultValue, - [WHEEL]: settingById(WHEEL)?.defaultValue + [LEFT]: resolveDefaultValue(settingById(LEFT)), + [WHEEL]: resolveDefaultValue(settingById(WHEEL)) }) describe('CANVAS_NAVIGATION_PRESETS', () => { @@ -23,18 +34,16 @@ describe('CANVAS_NAVIGATION_PRESETS', () => { * rather than against fixed values so changing a default is what trips it. */ it('agrees with the default Navigation Mode', () => { - const defaultMode = settingById(NAV)?.defaultValue as string + const defaultMode = resolveDefaultValue(settingById(NAV)) - expect(CANVAS_NAVIGATION_PRESETS[defaultMode]).toEqual(overrideDefaults()) + expect(presetForMode(defaultMode)).toEqual(overrideDefaults()) }) it('agrees with every install-versioned Navigation Mode default', () => { const versioned = settingById(NAV)?.defaultsByInstallVersion ?? {} for (const mode of Object.values(versioned)) { - expect(CANVAS_NAVIGATION_PRESETS[mode as string]).toEqual( - overrideDefaults() - ) + expect(presetForMode(mode)).toEqual(overrideDefaults()) } }) }) diff --git a/src/platform/settings/constants/coreSettings.ts b/src/platform/settings/constants/coreSettings.ts index 9f33d84e55f..1eed94c9648 100644 --- a/src/platform/settings/constants/coreSettings.ts +++ b/src/platform/settings/constants/coreSettings.ts @@ -189,8 +189,8 @@ export const CORE_SETTINGS: SettingParams[] = [ '1.25.0': 'legacy' }, onChange: async (val: unknown, old?: unknown) => { - if (!old) return - const preset = CANVAS_NAVIGATION_PRESETS[val as string] + if (!old || typeof val !== 'string') return + const preset = CANVAS_NAVIGATION_PRESETS[val] if (!preset) return await useSettingStore().setMany(preset) From 41477df06cdbd3b6fa747fa2f0df86d07917b39f Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Fri, 14 Aug 2026 01:33:37 +0000 Subject: [PATCH 5/6] fix: isolate settings migration and onChange failures from boot The canvas navigation override migration runs inside the boot-critical settings loader, so a rejected write surfaced as settingStore.error, which GraphCanvas rethrows before registering any core setting. A transient POST failure turned a cosmetic repair into an app that would not start, for every profile that picked a mode between 1.25.0 and 1.27.4. Both migrations now log and continue; the value is already applied in memory and the server still holds the un-migrated state, so the next load retries. Awaiting onChange also meant a failing handler aborted the caller's own write. onChange is extension-facing public API, so one custom node could stop the user's setting from ever being saved. Handler failures are now logged and isolated, covering synchronous throws as well as rejections. The persistence e2e test read the in-memory store, which the migration re-derives on every load, so it passed whether or not the write landed. It now reads the server through a new getPersistedSetting helper. --- .../fixtures/helpers/SettingsHelper.ts | 12 ++++ browser_tests/tests/canvasSettings.spec.ts | 12 ++-- src/platform/settings/settingStore.test.ts | 60 +++++++++++++++++++ src/platform/settings/settingStore.ts | 49 +++++++++++++-- 4 files changed, 123 insertions(+), 10 deletions(-) diff --git a/browser_tests/fixtures/helpers/SettingsHelper.ts b/browser_tests/fixtures/helpers/SettingsHelper.ts index 316ff43870d..7da6c3d00f0 100644 --- a/browser_tests/fixtures/helpers/SettingsHelper.ts +++ b/browser_tests/fixtures/helpers/SettingsHelper.ts @@ -20,4 +20,16 @@ export class SettingsHelper { return await window.app!.extensionManager.setting.get(id) }, settingId)) as T } + + /** + * Reads the value the server holds, which {@link getSetting} cannot: that + * reports the in-memory store, where a value may have been derived at load + * rather than persisted. Returns `undefined` for a setting never written. + */ + async getPersistedSetting(settingId: string): Promise { + return (await this.page.evaluate(async (id) => { + const persisted = await window.app!.api.getSettings() + return persisted[id as keyof typeof persisted] + }, settingId)) as T + } } diff --git a/browser_tests/tests/canvasSettings.spec.ts b/browser_tests/tests/canvasSettings.spec.ts index 89abed332c7..a6632f093a2 100644 --- a/browser_tests/tests/canvasSettings.spec.ts +++ b/browser_tests/tests/canvasSettings.spec.ts @@ -257,20 +257,20 @@ test.describe('Canvas settings', { tag: '@canvas' }, () => { ).toBe('standard') }) + // Reads the server, not the store: the migration is idempotent, so an + // in-memory read passes whether or not the write ever landed. test('persists the stored preset to the overrides', async ({ comfyPage }) => { - // Reload first so this asserts what reached the server, not just what - // the migration put in the in-memory store. - await comfyPage.workflow.reloadAndWaitForApp() - expect( - await comfyPage.settings.getSetting( + await comfyPage.settings.getPersistedSetting( 'Comfy.Canvas.LeftMouseClickBehavior' ) ).toBe('select') expect( - await comfyPage.settings.getSetting('Comfy.Canvas.MouseWheelScroll') + await comfyPage.settings.getPersistedSetting( + 'Comfy.Canvas.MouseWheelScroll' + ) ).toBe('panning') }) }) diff --git a/src/platform/settings/settingStore.test.ts b/src/platform/settings/settingStore.test.ts index 210549b9083..307bb9b0c1f 100644 --- a/src/platform/settings/settingStore.test.ts +++ b/src/platform/settings/settingStore.test.ts @@ -117,6 +117,33 @@ describe('useSettingStore', () => { expect(api.storeSettings).not.toHaveBeenCalled() }) + + // GraphCanvas rethrows `error` before registering any core setting, so a + // rejection here would leave the app unable to start. + it('leaves the store loadable when the write fails', async () => { + vi.spyOn(console, 'warn').mockImplementation(() => {}) + vi.mocked(api.storeSettings).mockRejectedValue(new Error('offline')) + + await loadWith({ [NAV]: 'standard' }) + + expect(store.error).toBeUndefined() + expect(store.isReady).toBe(true) + expect(store.settingValues[LEFT]).toBe('select') + }) + }) + + it('leaves the store loadable when the zoom threshold write fails', async () => { + vi.spyOn(console, 'warn').mockImplementation(() => {}) + vi.mocked(api.storeSetting).mockRejectedValue(new Error('offline')) + vi.mocked(api.getSettings).mockResolvedValue({ + 'LiteGraph.Canvas.LowQualityRenderingZoomThreshold': 0.6 + } as Partial as Settings) + + await store.load() + + expect(store.error).toBeUndefined() + expect(store.isReady).toBe(true) + expect(store.settingValues['LiteGraph.Canvas.MinFontSizeForLOD']).toBe(8) }) it('should set error if settings are loaded after registration', async () => { @@ -494,6 +521,39 @@ describe('useSettingStore', () => { expect(order).toEqual(['onChange', 'storeSetting']) }) + // onChange is extension-facing, and set() persists only after awaiting it, + // so an unisolated failure would discard the user's change unsaved. + it.for([ + { + label: 'rejects', + onChange: async () => { + throw new Error('extension blew up') + } + }, + { + label: 'throws synchronously', + onChange: () => { + throw new Error('extension blew up') + } + } + ])('persists the value when a handler $label', async ({ onChange }) => { + vi.spyOn(console, 'error').mockImplementation(() => {}) + store.addSetting({ + id: 'test.setting', + name: 'test.setting', + type: 'text', + defaultValue: 'default', + onChange + }) + + await expect( + store.set('test.setting', 'newvalue') + ).resolves.toBeUndefined() + + expect(api.storeSetting).toHaveBeenCalledWith('test.setting', 'newvalue') + expect(store.get('test.setting')).toBe('newvalue') + }) + it('exposes the new value to onChange handlers', async () => { const observed: unknown[] = [] store.addSetting({ diff --git a/src/platform/settings/settingStore.ts b/src/platform/settings/settingStore.ts index 9bd6d544f90..32ed38f81c0 100644 --- a/src/platform/settings/settingStore.ts +++ b/src/platform/settings/settingStore.ts @@ -38,6 +38,27 @@ function tryMigrateDeprecatedValue( return setting?.migrateDeprecatedValue?.(value) ?? value } +/** + * Runs the handler, absorbing both a synchronous throw and a rejected promise. + * `SettingParams.onChange` is extension-facing public API and its caller + * persists the setting only after awaiting it, so letting a third-party + * failure escape would discard the user's own change without saving it. + */ +async function callHandler( + setting: SettingParams | undefined, + newValue: unknown, + oldValue: unknown +) { + try { + await setting?.onChange?.(newValue, oldValue) + } catch (error) { + console.error( + `[settings] onChange handler for ${setting?.id} failed`, + error + ) + } +} + async function onChange( setting: SettingParams | undefined, newValue: unknown, @@ -47,7 +68,7 @@ async function onChange( // the same point, but awaited afterwards: a handler that cascades into other // settings must finish writing them before the caller writes this one, or // the two requests race in the backend's read-modify-write. - const handled = setting?.onChange?.(newValue, oldValue) + const handled = callHandler(setting, newValue, oldValue) // Backward compatibility with old settings dialog. // Some extensions still listens event emitted by the old settings dialog. if (setting) { @@ -56,6 +77,24 @@ async function onChange( await handled } +/** + * Migrations run inside the boot-critical settings loader, where a rejection + * becomes `settingStore.error` and GraphCanvas rethrows it before any core + * setting registers — turning a failed write into an app that will not start. + * The migrated value is already in memory and the server still holds the + * un-migrated state, so swallowing the failure leaves the next load to retry. + */ +async function persistMigration(write: () => Promise) { + try { + await write() + } catch (error) { + console.warn( + '[settings] Failed to persist migration; retrying on next load', + error + ) + } +} + function settingChangedEvent( setting: SettingParams | undefined, key: K, @@ -338,7 +377,7 @@ export const useSettingStore = defineStore('setting', () => { if (!Object.keys(unset).length) return Object.assign(settingValues.value, unset) - await api.storeSettings(unset) + await persistMigration(() => api.storeSettings(unset)) } /** @@ -375,8 +414,10 @@ export const useSettingStore = defineStore('setting', () => { delete settingValues.value[oldKey] // Store the migrated setting - await api.storeSetting(newKey, clampedFontSize) - await api.storeSetting(oldKey, undefined) + await persistMigration(async () => { + await api.storeSetting(newKey, clampedFontSize) + await api.storeSetting(oldKey, undefined) + }) } } From c969f53684e87cd6c10f920f853b546340b5eb46 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Fri, 14 Aug 2026 02:04:44 +0000 Subject: [PATCH 6/6] fix: drop settings writes a newer change has superseded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Awaiting onChange means a slow third-party handler lets a later change to the same key land first. The stalled call then resumed and persisted its own stale value, leaving the server disagreeing with the store and the setting reverting on reload — the failure this branch set out to fix. Each apply now takes a per-key ticket and skips its write and telemetry if a newer change claimed the key while its handler ran. Handler faults log at warn rather than error, matching wrapListener: RUM collects console.error, so reporting third-party faults there would relocate the noise the isolation exists to remove. --- .../fixtures/helpers/SettingsHelper.ts | 6 ++-- src/platform/settings/settingStore.test.ts | 32 ++++++++++++++++++- src/platform/settings/settingStore.ts | 17 +++++++--- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/browser_tests/fixtures/helpers/SettingsHelper.ts b/browser_tests/fixtures/helpers/SettingsHelper.ts index 7da6c3d00f0..5d9f629a17f 100644 --- a/browser_tests/fixtures/helpers/SettingsHelper.ts +++ b/browser_tests/fixtures/helpers/SettingsHelper.ts @@ -26,10 +26,12 @@ export class SettingsHelper { * reports the in-memory store, where a value may have been derived at load * rather than persisted. Returns `undefined` for a setting never written. */ - async getPersistedSetting(settingId: string): Promise { + async getPersistedSetting( + settingId: string + ): Promise { return (await this.page.evaluate(async (id) => { const persisted = await window.app!.api.getSettings() return persisted[id as keyof typeof persisted] - }, settingId)) as T + }, settingId)) as T | undefined } } diff --git a/src/platform/settings/settingStore.test.ts b/src/platform/settings/settingStore.test.ts index 307bb9b0c1f..651f546a21b 100644 --- a/src/platform/settings/settingStore.test.ts +++ b/src/platform/settings/settingStore.test.ts @@ -537,7 +537,7 @@ describe('useSettingStore', () => { } } ])('persists the value when a handler $label', async ({ onChange }) => { - vi.spyOn(console, 'error').mockImplementation(() => {}) + vi.spyOn(console, 'warn').mockImplementation(() => {}) store.addSetting({ id: 'test.setting', name: 'test.setting', @@ -554,6 +554,36 @@ describe('useSettingStore', () => { expect(store.get('test.setting')).toBe('newvalue') }) + it('does not persist a value a newer set() has superseded', async () => { + let releaseFirst = () => {} + const firstHandlerGate = new Promise((resolve) => { + releaseFirst = resolve + }) + let isFirstChange = true + store.addSetting({ + id: 'test.setting', + name: 'test.setting', + type: 'text', + defaultValue: 'default', + onChange: async (_value, old) => { + if (!old || !isFirstChange) return + isFirstChange = false + await firstHandlerGate + } + }) + + const stalled = store.set('test.setting', 'first') + await store.set('test.setting', 'second') + releaseFirst() + await stalled + + expect(store.get('test.setting')).toBe('second') + expect(api.storeSetting).toHaveBeenLastCalledWith( + 'test.setting', + 'second' + ) + }) + it('exposes the new value to onChange handlers', async () => { const observed: unknown[] = [] store.addSetting({ diff --git a/src/platform/settings/settingStore.ts b/src/platform/settings/settingStore.ts index 32ed38f81c0..9016e5ce9c8 100644 --- a/src/platform/settings/settingStore.ts +++ b/src/platform/settings/settingStore.ts @@ -43,6 +43,10 @@ function tryMigrateDeprecatedValue( * `SettingParams.onChange` is extension-facing public API and its caller * persists the setting only after awaiting it, so letting a third-party * failure escape would discard the user's own change without saving it. + * + * Logged at `warn` for the same reason {@link ComfyApi.wrapListener} is: RUM + * collects `console.error`, so reporting third-party faults there would just + * relocate the noise this guard exists to remove. */ async function callHandler( setting: SettingParams | undefined, @@ -52,10 +56,7 @@ async function callHandler( try { await setting?.onChange?.(newValue, oldValue) } catch (error) { - console.error( - `[settings] onChange handler for ${setting?.id} failed`, - error - ) + console.warn(`[settings] onChange handler for ${setting?.id} failed`, error) } } @@ -120,6 +121,7 @@ function settingChangedEvent( export const useSettingStore = defineStore('setting', () => { const settingValues = ref>({}) const settingsById = ref>({}) + const latestWrite = new Map() const { isReady, @@ -187,7 +189,14 @@ export const useSettingStore = defineStore('setting', () => { const typedNewValue = newValue as Settings[K] settingValues.value[key] = typedNewValue + const write = (latestWrite.get(key) ?? 0) + 1 + latestWrite.set(key, write) + await onChange(settingsById.value[key], newValue, oldValue) + + // Handlers are awaited, so a slow one lets a later change to this key land + // first. That change owns the value now; persisting ours would revert it. + if (latestWrite.get(key) !== write) return undefined return { previousValue: oldValue, newValue: typedNewValue