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

Consider only checking for persistency once? #31

Closed
IanVS opened this issue Jun 7, 2024 · 2 comments · Fixed by #32
Closed

Consider only checking for persistency once? #31

IanVS opened this issue Jun 7, 2024 · 2 comments · Fixed by #32

Comments

@IanVS
Copy link
Contributor

IanVS commented Jun 7, 2024

Hi, I've just started trying out MSW recently, and it's mostly going great. But I do have one small annoyance. In one of my tests I'm checking for calls to a local storage mock, and I am seeing roughly 90 checks from MSW for MSW_COOKIE_STORE_test. I wonder if instead of checking for supportsLocalStorage() in every hydrate() and persist() (which I guess can happen a lot?), maybe it can be done once (maybe in the constructor) and the result cached? I'm not very familiar with the architecture here so maybe that's a bad suggestion, but I thought I'd at least bring it up.

Thanks!

@kettanaito
Copy link
Member

Hi, @IanVS 👋 I think that's a fantastic idea. I'm not sure why we are checking it on each hydrate/persist. The availability of the storage isn't expected to change between those calls.

We are better off checking it on the root of store.ts (once you import the module) as the store availability is dictated by the environment where you import the module from.

Please, would you be interested in opening a pull request to help us fix this?

@kettanaito
Copy link
Member

Released: v1.1.1 🎉

This has been released in v1.1.1!

Make sure to always update to the latest version (npm i @mswjs/cookies@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

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 a pull request may close this issue.

2 participants