Best practice around checking for localStorage access while using the persist plugin #3451
Unanswered
treyhunner
asked this question in
1. Help
Replies: 1 comment 2 replies
-
🤔 I would suspect that localStorage being disabled would really be down to that user using some kind of privacy browser, or it's traffic from a non-browser environment that hasn't added the full browser APIs. All major browsers since like 2009 support localstorage. I don't know if it's work having Alpine do it's own check and just silently passing through? or maybe warning? But for now you can shim it. It just needs window.localStorage = window.localStorage ?? {
getItem() { return undefined },
setItem() { }
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In my Sentry logs I see that accessing
localStorage
raises an exception in some browsers. In that caselet storage=localStorage
raises an error:And I also see that sometimes
localStorage
isnull
. In that case accessingstorage.getItem
in thestorageHas
function raises an error:What's the best practice for falling back to either non-persistent storage or no storage (it doesn't much matter for my use case)?
And should the persist plugin be modified to work without raising an error by default even if/when
localStorage
is non-functional?Beta Was this translation helpful? Give feedback.
All reactions