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

Prevent unwanted persistence of 'undefined' in storage #4128

Closed
wants to merge 1 commit into from

Conversation

JackWH
Copy link

@JackWH JackWH commented Apr 4, 2024

I noticed an issue in Filament which caused Alpine to crash due to a component inadvertently setting undefined as a value with $persist. Whilst debugging I found a recent PR #4091, which attempts to prevent a similar issue when retrieving an undefined value from storage.

However it seems users can still unintentionally persist an undefined value, which confusingly gets stringified to remain undefined before then being saved as a string regardless by localStorage setItem.

This PR prevents committing undefined to storage by swapping it out with null, which is valid JSON and can therefore be stringified. Future checks with storageHas will return false (as expected), falling back to the initial value. It might be worth raising a warning but I'll take any feedback on this approach first. Thanks!

@calebporzio
Copy link
Collaborator

Thanks @JackWH - can you provide a simple code snippet to demonstrate this problem? or better include a test for this?

@calebporzio
Copy link
Collaborator

Closing because of lack of response. Please re-submit if new info is presented. 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.

2 participants