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

fix: only listen for the 'storage' event if using 'local' storage #159

Merged
merged 5 commits into from
Dec 6, 2024

Conversation

webJose
Copy link
Contributor

@webJose webJose commented Dec 3, 2024

Fixes #150.

Notes

jsdom doesn't raise the 'storage' event because this event only fires when values change in a different window, which is something we don't have (we only have one window). So to unit-test, one must dispatch the event manually.

Also: The event handler uses getValueFromStorage to obtain the value, but the event.newValue property already has this value. This seems like an unnecessary performance hit, and may be best to simply deserialize event.newValue.

New Situation/Issue

I noticed that there is no deletion. I think that whenever this.#current becomes undefined, the value in storage should be deleted.

Copy link

changeset-bot bot commented Dec 3, 2024

🦋 Changeset detected

Latest commit: f06f259

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
runed Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@webJose
Copy link
Contributor Author

webJose commented Dec 3, 2024

Two more things: Unsure if there's anything else required, so I made this a draft PR. The second is that I added the delay() function to the testing helpers so as to not continuously drag the timeout thing in a new promise every time one must await for effects to run.

@webJose
Copy link
Contributor Author

webJose commented Dec 5, 2024

Done. Let me know if there are any more pendings. If not, I'll add a changeset and take the PR out of Draft status.

@huntabyte
Copy link
Member

Feel free to move it out of draft @webJose !

@huntabyte
Copy link
Member

Thank you!

Copy link
Contributor

github-actions bot commented Dec 6, 2024

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
runed ✅ Ready (View Log) Visit Preview f06f259

@huntabyte huntabyte marked this pull request as ready for review December 6, 2024 22:12
@huntabyte huntabyte merged commit f932fbf into svecosystem:main Dec 6, 2024
4 checks passed
@webJose
Copy link
Contributor Author

webJose commented Dec 6, 2024

Ha, you were in a hurry. I came but the branch was merged already.

@webJose webJose deleted the JP/PersistedState_StorageEvent branch December 11, 2024 05:09
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.

PersistedState: Adds storage event listener without regards of the type of storage
2 participants