Skip to content

Commit 6eae713

Browse files
committed
fix storage conflict modal
1 parent 34eecc1 commit 6eae713

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/react/StorageConflictModal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ export default () => {
1616

1717
if (!isModalActive/* || conflicts.length === 0 */) return null
1818

19+
const clampText = (text: string) => {
20+
return text.length > 30 ? text.slice(0, 30) + '...' : text
21+
}
22+
1923
const conflictText = conflicts.map(conflict => {
2024
const localTime = formatTimestamp(conflict.localStorageTimestamp)
2125
const cookieTime = formatTimestamp(conflict.cookieTimestamp)
22-
return `${conflict.key}: LocalStorage (${localTime}) vs Cookie (${cookieTime})`
26+
return `${conflict.key}: LocalStorage (${localTime}, ${clampText(conflict.localStorageValue)}) vs Cookie (${cookieTime}, ${clampText(conflict.cookieValue)})`
2327
}).join('\n')
2428

2529
return (

src/react/appStorageProvider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,14 @@ const detectStorageConflicts = (): StorageConflict[] => {
134134
delete localData.timestamp
135135
delete cookieData.timestamp
136136

137-
if (JSON.stringify(localData) !== JSON.stringify(cookieData)) {
137+
const isDataEmpty = (data: any) => {
138+
if (typeof data === 'object' && data !== null) {
139+
return Object.keys(data).length === 0
140+
}
141+
return !data && data !== 0 && data !== false
142+
}
143+
144+
if (JSON.stringify(localData) !== JSON.stringify(cookieData) && !isDataEmpty(localData) && !isDataEmpty(cookieData)) {
138145
conflicts.push({
139146
key,
140147
localStorageValue: localData,

0 commit comments

Comments
 (0)