Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle SecurityError exception if localStorage is unavailable #3775

Merged
merged 3 commits into from
Oct 18, 2023

Conversation

ShaunDychko
Copy link
Contributor

If an exception is thrown when trying to assign storage = localStorage, the persist plugin currently fails with an unhandled exception. In Sentry logs I'm seeing this occur occasionally (about once per day) with Safari 16.x on iOS, and the issue renders the application unusable for these users. Using custom storage with $persist(0).using(customStorage) doesn't solve the issue since the exception will still be thrown.

This pull request suggests using a variable object on window for temporary storage as an alternative to persistent storage when localStorage is unavailable. A message is logged to the JS console to indicate that the value is being stored only temporarily. This alternative handles the exception and makes the application usable, even though the value will not be persisted between page loads.

@ShaunDychko
Copy link
Contributor Author

#3451

packages/persist/src/index.js Outdated Show resolved Hide resolved
ShaunDychko and others added 2 commits September 20, 2023 11:43
Co-authored-by: Eric Kwoka <43540491+ekwoka@users.noreply.github.com>
@calebporzio
Copy link
Collaborator

Looks good to me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants