Procházet zdrojové kódy

Fixed persist crash when the stored value is undefined (#4091)

* Fixed persist crash when the stored value is undefined

Fixed persist crash when the stored value is undefined.
This bug crashes Alpine

* refactor

---------

Co-authored-by: Caleb Porzio <calebporzio@gmail.com>
Alwahibi před 1 rokem
rodič
revize
c38a45f3b6
1 změnil soubory, kde provedl 5 přidání a 1 odebrání
  1. 5 1
      packages/persist/src/index.js

+ 5 - 1
packages/persist/src/index.js

@@ -65,7 +65,11 @@ function storageHas(key, storage) {
 }
 
 function storageGet(key, storage) {
-    return JSON.parse(storage.getItem(key, storage))
+    let value = storage.getItem(key, storage)
+
+    if (value === undefined) return
+
+    return JSON.parse(value)
 }
 
 function storageSet(key, value, storage) {