Skip to content

Commit 627165e

Browse files
authored
Release (#379)
2 parents 226e4be + f2a11d0 commit 627165e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/react/StorageConflictModal.tsx

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

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

19+
const clampText = (text: string) => {
20+
if (typeof text !== "string") text = JSON.stringify(text)
21+
return text.length > 30 ? text.slice(0, 30) + '...' : text
22+
}
23+
1924
const conflictText = conflicts.map(conflict => {
2025
const localTime = formatTimestamp(conflict.localStorageTimestamp)
2126
const cookieTime = formatTimestamp(conflict.cookieTimestamp)
22-
return `${conflict.key}: LocalStorage (${localTime}) vs Cookie (${cookieTime})`
27+
return `${conflict.key}: LocalStorage (${localTime}, ${clampText(conflict.localStorageValue)}) vs Cookie (${cookieTime}, ${clampText(conflict.cookieValue)})`
2328
}).join('\n')
2429

2530
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)