yairEO / tagify

🔖 lightweight, efficient Tags input component in Vanilla JS / React / Angular / Vue
https://yaireo.github.io/tagify/
Other
3.55k stars 436 forks source link

Add an id check in getPersistedData (like in setPersistedData ) #1374

Closed semkaway closed 4 weeks ago

semkaway commented 2 months ago

Hello!

I sometimes have issues like null is not an object (evaluating 'localStorage.getItem') when initializing the Tagify object on my page, and, based on the stacktrace, it is caused by this logic: {snip} |{},this.getPersistedData=(s=e.id,function(t){var e,i="/"+t;if(1==localStorage.getItem(j+s+"/v",1))try{e=JSON.parse(localStorage[j+s+i])}cat {snip}

I see in your code in setPersistedData that you check if id is passed, and if it doesn't exist, return: if( !id ) return () => {}; I would assume, it would be useful to have the same logic in getPersistedData as well, and not try to access localStorage if the id is not passed. Is there a reason why this check is absent in getPersistedData? Would it be possible to add it?

I don't pass the ids in my code and don't need the persisted data functionality, it's just that sometimes my users' devices don't give permission to access localStorage, and I would like to avoid getting errors.

Thanks!