Skip to content

Commit 5854376

Browse files
authored
refactor(storage): remove legacy storage key after migration (#3037)
1 parent 0ed6858 commit 5854376

2 files changed

Lines changed: 8 additions & 31 deletions

File tree

src/renderer/utils/core/storage.test.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('renderer/utils/core/storage.ts', () => {
2020
expect(localStorage.getItem(Constants.STORAGE.LEGACY)).toBeNull();
2121
});
2222

23-
it('migrates legacy auth and settings into the stores and marks the key as migrated', () => {
23+
it('migrates legacy auth and settings into the stores and removes the legacy key', () => {
2424
localStorage.setItem(
2525
Constants.STORAGE.LEGACY,
2626
JSON.stringify({
@@ -36,9 +36,7 @@ describe('renderer/utils/core/storage.ts', () => {
3636
expect(useSettingsStore.getState().theme).toBe(Theme.DARK);
3737
expect(useSettingsStore.getState().playSound).toBe(false);
3838

39-
const marker = JSON.parse(localStorage.getItem(Constants.STORAGE.LEGACY)!);
40-
expect(marker.migrated).toBe(true);
41-
expect(marker.migratedAt).toBeDefined();
39+
expect(localStorage.getItem(Constants.STORAGE.LEGACY)).toBeNull();
4240
});
4341

4442
it('drops legacy accounts with invalid hostnames during migration', () => {
@@ -68,17 +66,13 @@ describe('renderer/utils/core/storage.ts', () => {
6866
expect(useAccountsStore.getState().accounts).toHaveLength(1);
6967
});
7068

71-
it('skips migration when already migrated', () => {
72-
localStorage.setItem(
73-
Constants.STORAGE.LEGACY,
74-
JSON.stringify({ migrated: true, migratedAt: '2026-01-01T00:00:00Z' }),
75-
);
69+
it('removes a legacy key with no migratable data', () => {
70+
localStorage.setItem(Constants.STORAGE.LEGACY, JSON.stringify({}));
7671

7772
migrateLegacyStoreToZustand();
7873

7974
expect(useAccountsStore.getState().accounts).toEqual([]);
80-
const marker = JSON.parse(localStorage.getItem(Constants.STORAGE.LEGACY)!);
81-
expect(marker.migratedAt).toBe('2026-01-01T00:00:00Z');
75+
expect(localStorage.getItem(Constants.STORAGE.LEGACY)).toBeNull();
8276
});
8377

8478
it('logs an error and leaves stores untouched on malformed legacy data', () => {

src/renderer/utils/core/storage.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,7 @@ export function migrateLegacyStoreToZustand() {
2222
}
2323

2424
try {
25-
const parsed = JSON.parse(existing);
26-
27-
// Skip if already migrated
28-
if (parsed.migrated) {
29-
rendererLogInfo(
30-
'migrateLegacyStoreToZustand',
31-
`Storage already migrated on ${parsed.migratedAt}`,
32-
);
33-
return;
34-
}
35-
36-
const { auth, settings } = parsed;
25+
const { auth, settings } = JSON.parse(existing);
3726

3827
// Migrate auth to AccountsStore if it exists and store is empty
3928
if (auth?.accounts && useAccountsStore.getState().accounts.length === 0) {
@@ -49,14 +38,8 @@ export function migrateLegacyStoreToZustand() {
4938
useSettingsStore.setState(knownSettings);
5039
}
5140

52-
// Mark old storage key as migrated instead of removing it
53-
localStorage.setItem(
54-
Constants.STORAGE.LEGACY,
55-
JSON.stringify({
56-
migrated: true,
57-
migratedAt: new Date().toISOString(),
58-
}),
59-
);
41+
// Remove the legacy key so subsequent launches skip migration entirely
42+
localStorage.removeItem(Constants.STORAGE.LEGACY);
6043

6144
rendererLogInfo(
6245
'migrateLegacyStoreToZustand',

0 commit comments

Comments
 (0)