fix: ensure localStorage keys are properly checked before removal in proceedToNext function

This commit is contained in:
mrkad@rpi
2026-01-17 22:45:48 +07:00
parent 2891ed9620
commit a61fda7b0f

View File

@@ -150,11 +150,15 @@ const proceedToNext = () => {
const keysToRemove = [] const keysToRemove = []
for (let i = 0; i < localStorage.length; i++) { for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i) const key = localStorage.key(i)
if (key && key.startsWith('photobooth-1x4-') || key.startsWith('photobooth-2x2-')) { if (key && (key.startsWith('photobooth-1x4-') || key.startsWith('photobooth-2x2-'))) {
keysToRemove.push(key) keysToRemove.push(key)
} }
} }
keysToRemove.forEach(key => localStorage.removeItem(key)) keysToRemove.forEach(key => {
if (key !== null) {
localStorage.removeItem(key)
}
})
// เก็บรูปภาพไว้ใน localStorage // เก็บรูปภาพไว้ใน localStorage
localStorage.setItem('photobooth-photos', JSON.stringify(photos.value)) localStorage.setItem('photobooth-photos', JSON.stringify(photos.value))