diff --git a/packages/frontend/src/lib/pizzax.ts b/packages/frontend/src/lib/pizzax.ts index 0dd8a82957..51e3daae9f 100644 --- a/packages/frontend/src/lib/pizzax.ts +++ b/packages/frontend/src/lib/pizzax.ts @@ -82,8 +82,10 @@ export class Pizzax { this.r = {} as ReactiveState; for (const [k, v] of Object.entries(def) as [keyof T, T[keyof T]['default']][]) { - this.s[k] = v.default; - this.r[k] = ref(v.default); + // 参照渡しになるのを防ぐためclone + const defaultValue = deepClone(v.default); + this.s[k] = defaultValue; + this.r[k] = ref(defaultValue); } this.ready = this.init(); @@ -120,7 +122,8 @@ export class Pizzax { } else if (v.where === 'deviceAccount' && Object.prototype.hasOwnProperty.call(deviceAccountState, k)) { this.r[k].value = this.s[k] = this.mergeState(deviceAccountState[k], v.default); } else { - this.r[k].value = this.s[k] = v.default; + // 参照渡しになるのを防ぐためclone + this.r[k].value = this.s[k] = deepClone(v.default); } } @@ -148,7 +151,8 @@ export class Pizzax { this.r[k].value = this.s[k] = (kvs as Partial)[k]; cache[k] = (kvs as Partial)[k]; } else { - this.r[k].value = this.s[k] = v.default; + // 参照渡しになるのを防ぐためclone + this.r[k].value = this.s[k] = deepClone(v.default); } } } @@ -218,8 +222,10 @@ export class Pizzax { } public reset(key: keyof T) { - this.set(key, this.def[key].default); - return this.def[key].default; + // 参照渡しになるのを防ぐためclone + const defaultValue = deepClone(this.def[key].default); + this.set(key, defaultValue); + return defaultValue; } /** diff --git a/packages/frontend/src/preferences/manager.ts b/packages/frontend/src/preferences/manager.ts index 7f3949f81b..9a2056271f 100644 --- a/packages/frontend/src/preferences/manager.ts +++ b/packages/frontend/src/preferences/manager.ts @@ -14,6 +14,7 @@ import { copyToClipboard } from '@/utility/copy-to-clipboard.js'; import { i18n } from '@/i18n.js'; import * as os from '@/os.js'; import { deepEqual } from '@/utility/deep-equal.js'; +import { deepClone } from '@/utility/clone.js'; // NOTE: 明示的な設定値のひとつとして null もあり得るため、設定が存在しないかどうかを判定する目的で null で比較したり ?? を使ってはいけない @@ -122,7 +123,8 @@ export function getInitialPrefValue(k: K): ValueOf { if (typeof _default === 'function') { // factory return _default() as ValueOf; } else { - return _default as unknown as ValueOf; + // 参照渡しになるのを防ぐためclone + return deepClone(_default as unknown as ValueOf); } }