From a025209602ad973b04c2b1151de7bbb095135e6e Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Thu, 5 Mar 2026 20:38:42 +0900 Subject: [PATCH] =?UTF-8?q?fix(frontend):=20=E6=84=8F=E5=9B=B3=E3=81=9B?= =?UTF-8?q?=E3=81=9A=E5=8F=82=E7=85=A7=E6=B8=A1=E3=81=97=E3=81=AB=E3=81=AA?= =?UTF-8?q?=E3=82=8A=E5=BE=97=E3=82=8B=E7=AE=87=E6=89=80=E3=82=92deepClone?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=20(#17207)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 現状は(おそらく)問題は起きていないが今後問題が発現するシチュエーションが出てくる可能性がある --- packages/frontend/src/lib/pizzax.ts | 18 ++++++++++++------ packages/frontend/src/preferences/manager.ts | 4 +++- 2 files changed, 15 insertions(+), 7 deletions(-) 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); } }