experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(tag-actions): use schema-canonical 'pairs' key with one-time migration from buggy 'data' key

+22 -11
+22 -11
features/tag-actions/home.js
··· 66 66 // ==================== Settings ==================== 67 67 68 68 const loadSettings = async () => { 69 - const result = await api.settings.get('data'); 70 - if (result.success && result.data) { 71 - // Support new pairs format 72 - if (Array.isArray(result.data.pairs)) { 73 - currentPairs = result.data.pairs; 74 - } 75 - // Migration: convert old actions format to pairs 76 - else if (Array.isArray(result.data.actions) && result.data.actions.length > 0) { 77 - currentPairs = migrateActionsToToPairs(result.data.actions); 69 + // Canonical storage is the schema-declared 'pairs' key (array of pair objects). 70 + // Prior versions wrote a combined object under 'data' ({ pairs: [...] } 71 + // or legacy { actions: [...] }). When both rows exist, 'data' is the 72 + // authoritative source — it's where the buggy code persisted the user's 73 + // most recent state — so migrate from 'data' first if present, then 74 + // re-save under 'pairs'. The stale 'data' row is left in place 75 + // (harmless; no foreign reads). 76 + const legacy = await api.settings.get('data'); 77 + if (legacy.success && legacy.data) { 78 + if (Array.isArray(legacy.data.pairs)) { 79 + currentPairs = legacy.data.pairs; 80 + } else if (Array.isArray(legacy.data.actions) && legacy.data.actions.length > 0) { 81 + currentPairs = migrateActionsToToPairs(legacy.data.actions); 78 82 } else { 79 83 currentPairs = []; 80 84 } 85 + // Persist under the canonical key so subsequent loads skip the legacy branch. 86 + await api.settings.set('pairs', currentPairs); 87 + // Mark the legacy row as migrated so we never read it again. 88 + await api.settings.set('data', null); 81 89 } else { 82 - currentPairs = []; 90 + const pairsResult = await api.settings.get('pairs'); 91 + currentPairs = (pairsResult.success && Array.isArray(pairsResult.data)) 92 + ? pairsResult.data 93 + : []; 83 94 } 84 95 85 96 // Derive action rules from pairs ··· 88 99 }; 89 100 90 101 const saveSettings = async () => { 91 - const result = await api.settings.set('data', { pairs: currentPairs }); 102 + const result = await api.settings.set('pairs', currentPairs); 92 103 if (!result.success) { 93 104 console.error('[tag-actions] Failed to save settings:', result.error); 94 105 }