From c5edbe588c7ff85c156f5b4af4d1f354626f77cb Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Tue, 1 Jul 2025 19:19:51 -0400 Subject: [PATCH] [refactor] Move setting migrations to settingStore Relocate runSettingMigrations() from GraphCanvas.vue to settingStore's loadSettingValues() method. This improves separation of concerns by keeping data migration logic within the store rather than coupling it to UI components. The migrations now run at the optimal time: after loading setting values from the server but before any settings are registered, ensuring proper initialization order and preventing potential race conditions. This change makes the architecture cleaner and more maintainable by centralizing all setting-related logic in the appropriate store. --- src/components/graph/GraphCanvas.vue | 4 ---- src/stores/settingStore.ts | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/graph/GraphCanvas.vue b/src/components/graph/GraphCanvas.vue index 0918acac9..4efe8b8e9 100644 --- a/src/components/graph/GraphCanvas.vue +++ b/src/components/graph/GraphCanvas.vue @@ -86,7 +86,6 @@ import { useSettingStore } from '@/stores/settingStore' import { useToastStore } from '@/stores/toastStore' import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore' import { useWorkspaceStore } from '@/stores/workspaceStore' -import { runSettingMigrations } from '@/utils/migration/settingsMigration' const emit = defineEmits<{ ready: [] @@ -299,9 +298,6 @@ onMounted(async () => { } } - // Run cross-setting migrations - await runSettingMigrations() - CORE_SETTINGS.forEach((setting) => { settingStore.addSetting(setting) }) diff --git a/src/stores/settingStore.ts b/src/stores/settingStore.ts index a7a4c9986..7337871ce 100644 --- a/src/stores/settingStore.ts +++ b/src/stores/settingStore.ts @@ -7,6 +7,7 @@ import { api } from '@/scripts/api' import { app } from '@/scripts/app' import type { SettingParams } from '@/types/settingTypes' import type { TreeNode } from '@/types/treeExplorerTypes' +import { runSettingMigrations } from '@/utils/migration/settingsMigration' export const getSettingInfo = (setting: SettingParams) => { const parts = setting.category || setting.id.split('.') @@ -109,6 +110,9 @@ export const useSettingStore = defineStore('setting', () => { ) } settingValues.value = await api.getSettings() + + // Run migrations after loading values but before settings are registered + await runSettingMigrations() } return {