Skip to content

Commit 5ca8582

Browse files
xingrzclaude
andcommitted
Add prefix to localStorage keys to avoid collisions
Use 'rdt-editor:' prefix for all localStorage keys. The getItem helper falls back to reading unprefixed keys for seamless migration of existing users' saved data. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 200c138 commit 5ca8582

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/stores/editor.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ import { debounce } from 'radash';
44

55
import type ISelection from '@/types/selection';
66

7-
const debouncedSetItem = debounce({ delay: 200 }, localStorage.setItem.bind(localStorage));
7+
const PREFIX = 'rdt-editor:';
8+
9+
function getItem(key: string): string | null {
10+
return localStorage.getItem(PREFIX + key) ?? localStorage.getItem(key);
11+
}
12+
13+
function setItem(key: string, value: string): void {
14+
localStorage.setItem(PREFIX + key, value);
15+
}
16+
17+
const debouncedSetItem = debounce({ delay: 200 }, setItem);
818

919
const EXAMPLE = `KBHFa~~Redmond
1020
STR
@@ -23,9 +33,9 @@ STR
2333
KBHFe~~Angle Lake`;
2434

2535
export const useEditorStore = defineStore('editor', () => {
26-
const size = ref(parseInt(localStorage.getItem('size') || '') || 20);
27-
const width = ref(parseInt(localStorage.getItem('width') || '') || 200);
28-
const content = ref(localStorage.getItem('content') ?? EXAMPLE);
36+
const size = ref(parseInt(getItem('size') || '') || 20);
37+
const width = ref(parseInt(getItem('width') || '') || 200);
38+
const content = ref(getItem('content') ?? EXAMPLE);
2939
const scroll = ref(0);
3040
const selection = ref<ISelection>();
3141

0 commit comments

Comments
 (0)