Local Storage Key Stuck as Null After Deletion in Toddle
I ’m building a “recent items ” feature in Nordcraft that stores an array in local storage under the key kb -recent -items . The setup uses the formula Default to (Get from Local Storage ( "kb -recent -items " ) , [ ] ) to initialize the variable , so it should always be an array —even if the key is missing or deleted (Get from Local Storage ) . Initially , the feature worked without issue . However , for testing purposes , I opened up my browser 's dev tools and deleted the storage key . On page reload , the key is recreated but its value is null , and my workflow (which sets the variable and saves it back to local storage ) does not update it . I ’ve tried triggering the update both on load and on attribute change (Lifecycle section of the data panel ) , but the issue persists . The UI either shows null or [object ] instead of the expected array of recent items . What I ’ve Tried : -Initializing the variable with Default to (Get from Local Storage ( "kb -recent -items " ) , [ ] ) -Triggering the update workflow on both load and attribute change -Ensuring the workflow sets the variable and saves it to local storage Issue : After deleting the key , it comes back as null and will not update , even though the workflow should be setting and saving the array . Has anyone else run into this , or does anyone know what might be causing the key to get stuck as null and not update as expected ? Any advice or workarounds would be appreciated ! This will always be true and won ’t default to [ ] Reason is that local storage , cookies , etc only accept string values So if you want to save objects , do so with JSON strings Thank you so much @Lucas G for the tip ! It turns out you were 100 % correct . 👍 Assistant Context When you use local storage (or session storage ) , all values are stored as strings . If you save the value null directly , it will be stored as the string "null " , not as a true null value or an empty array . When you later retrieve this value , you get the string "null " , which will not be treated as a real null or an array by your formulas . This is why your defaultTo formula does not fall back to [ ] —because the value is not actually null , but the string "null " . Resolution The workflow tried to add an item to a non -existent array , causing the local storage key to be set with the string "null " . I expected the defaultTo function to fall back to an empty array since I used double brackets [ ] , but it didn ’t . After some troubleshooting , I discovered the brackets were being treated as the string " [ ] " rather than an actual empty array type . To fix this , I removed the brackets and connected an Array function instead , which completely resolved the issue . Thanks again LucasG as I wouldn 't have been able to figure this out without you pointing me in the right direction . ☺️ 👍1