-
-
Notifications
You must be signed in to change notification settings - Fork 622
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(utils): subscribe method of createJSONStorage should only run in the client #2585
Merged
dai-shi
merged 12 commits into
pmndrs:main
from
mhsattarian:fix/createJSONStorage-subscribe
Jun 3, 2024
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a1b1998
fix: prevent calling storage subscribe unless in client
mhsattarian 71d2fa0
test: add test for getStringStorage method from createJSONStorage to …
mhsattarian 6ca781f
use try-catch
dai-shi 2838849
Revert "test: add test for getStringStorage method from createJSONSto…
mhsattarian f38edf1
test: checking localStorage/sessionStorage access with createJSONStor…
mhsattarian 4abe2b5
test: improve checking localStorage/sessionStorage access with create…
mhsattarian 56d186a
test: use defineProperty for checking localStorage/sessionStorage acc…
mhsattarian f181938
fix: ts error in new test
mhsattarian a864f5d
improve detecting browser storage access in client
mhsattarian 63be079
Update src/vanilla/utils/atomWithStorage.ts
dai-shi 5728158
patch console.warn for atomWithStorage (in non-browser environment) test
mhsattarian 982fd7c
Merge branch 'main' into fix/createJSONStorage-subscribe
dai-shi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we should check is not only createJSONStorage, but also atomWithStorage.
You want to confirm if the test works as expected by removing the try-catch we added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested with the try/catch removed and it did throw an error:
should we add a new test or modify this one in you opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks. that's my oversight. yeah, the current test seems good. no need to add new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I think what we need to test, if possible, is
createJSONStorage()
. Do you have any idea?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean instead of
createJSONStorage(() => window.localStorage)
we should testcreateJSONStorage()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if possible, we want to test both. Otherwise, it's fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simply added another expect to check for it, but I have a feeling you mean something else.
there is also a
console.warn
happening here due to the checking we have increateJSONStorage
. is it ok?here is a screenshot:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
except(() => createJSONStorage()).not.toThrow()
seems good. (It fails if we remove the fix, right?)As for the console.warn, let's mock it for this test and hide the warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
Also, I added
console.warn
patching in the last commit, please check it.