-
-
Notifications
You must be signed in to change notification settings - Fork 635
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/atomWithStorage): defaultStorage with disabled local storage crashes on mount #2354
fix(utils/atomWithStorage): defaultStorage with disabled local storage crashes on mount #2354
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 76afd16:
|
6b2b122
to
545e64e
Compare
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.
Hi! This looks like a nice improvement!
Please check comments.
On Chrome, it's the same with slightly different message: |
@benediktschlager hi, are you still around? |
545e64e
to
007c47f
Compare
src/vanilla/utils/atomWithStorage.ts
Outdated
return window.localStorage | ||
} catch (e) { | ||
// Window could be undefined or local storage could be disabled | ||
if (e instanceof TypeError || e instanceof DOMException) { |
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.
Hmm, this is what I tried in Node.js:
> try { window.localStorage } catch (e) { console.log(e instanceof TypeError) }
false
undefined
> try { window.localStorage } catch (e) { console.log(e instanceof ReferenceError) }
true
undefined
Maybe, it's not stable. On the other hand, when is the case we want to throw e
?
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, it seems on node the window instance is not even defined.
I'm wondering under which circumstances the window instance is not defined, but this library is used?
As far as I understand, Jotai only works alongside React?
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.
SSR=Server Side Rendering.
Hi @dai-shi, I included your feedback. |
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
oops, can you run prettier please? |
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 for your contribution!
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [jotai](https://github.com/pmndrs/jotai) | [`^2.6.0` -> `^2.6.4`](https://renovatebot.com/diffs/npm/jotai/2.6.0/2.6.4) | [![age](https://developer.mend.io/api/mc/badges/age/npm/jotai/2.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/jotai/2.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/jotai/2.6.0/2.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/jotai/2.6.0/2.6.4?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>pmndrs/jotai (jotai)</summary> ### [`v2.6.4`](https://github.com/pmndrs/jotai/releases/tag/v2.6.4) [Compare Source](https://github.com/pmndrs/jotai/compare/v2.6.3...v2.6.4) Performance improvement! Check it out! ##### What's Changed - refactor: refactoring store and options type by [@​ssi02014](https://github.com/ssi02014) in [https://github.com/pmndrs/jotai/pull/2360](https://github.com/pmndrs/jotai/pull/2360) - refactor: modified Args type by [@​ssi02014](https://github.com/ssi02014) in [https://github.com/pmndrs/jotai/pull/2367](https://github.com/pmndrs/jotai/pull/2367) - Improve performance of recomputeDependents by [@​samkline](https://github.com/samkline) in [https://github.com/pmndrs/jotai/pull/2363](https://github.com/pmndrs/jotai/pull/2363) - fix(vanilla): fix unexpected cache in jotai-scope by [@​yf-yang](https://github.com/yf-yang) in [https://github.com/pmndrs/jotai/pull/2371](https://github.com/pmndrs/jotai/pull/2371) ##### New Contributors - [@​ssi02014](https://github.com/ssi02014) made their first contribution in [https://github.com/pmndrs/jotai/pull/2360](https://github.com/pmndrs/jotai/pull/2360) - [@​samkline](https://github.com/samkline) made their first contribution in [https://github.com/pmndrs/jotai/pull/2363](https://github.com/pmndrs/jotai/pull/2363) - [@​yf-yang](https://github.com/yf-yang) made their first contribution in [https://github.com/pmndrs/jotai/pull/2371](https://github.com/pmndrs/jotai/pull/2371) **Full Changelog**: pmndrs/jotai@v2.6.3...v2.6.4 ### [`v2.6.3`](https://github.com/pmndrs/jotai/releases/tag/v2.6.3) [Compare Source](https://github.com/pmndrs/jotai/compare/v2.6.2...v2.6.3) Some improvements in core and utils 👏 #### What's Changed - fix: atoms should not remount on recalculations (with async dependencies) by [@​dmaskasky](https://github.com/dmaskasky) in [https://github.com/pmndrs/jotai/pull/2347](https://github.com/pmndrs/jotai/pull/2347) - fix(utils): atomWithReducer for jotai-scope by [@​dai-shi](https://github.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/2351](https://github.com/pmndrs/jotai/pull/2351) - fix(utils/atomWithStorage): defaultStorage with disabled local storage crashes on mount by [@​benediktschlager](https://github.com/benediktschlager) in [https://github.com/pmndrs/jotai/pull/2354](https://github.com/pmndrs/jotai/pull/2354) - feat(vanilla): customizable atom.unstable_is by [@​dai-shi](https://github.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/2356](https://github.com/pmndrs/jotai/pull/2356) #### New Contributors - [@​SpringHgui](https://github.com/SpringHgui) made their first contribution in [https://github.com/pmndrs/jotai/pull/2320](https://github.com/pmndrs/jotai/pull/2320) - [@​sakurawen](https://github.com/sakurawen) made their first contribution in [https://github.com/pmndrs/jotai/pull/2358](https://github.com/pmndrs/jotai/pull/2358) - [@​JoltCode](https://github.com/JoltCode) made their first contribution in [https://github.com/pmndrs/jotai/pull/2357](https://github.com/pmndrs/jotai/pull/2357) - [@​benediktschlager](https://github.com/benediktschlager) made their first contribution in [https://github.com/pmndrs/jotai/pull/2354](https://github.com/pmndrs/jotai/pull/2354) **Full Changelog**: pmndrs/jotai@v2.6.2...v2.6.3 ### [`v2.6.2`](https://github.com/pmndrs/jotai/releases/tag/v2.6.2) [Compare Source](https://github.com/pmndrs/jotai/compare/v2.6.1...v2.6.2) Some improvements for atomWithStorage. Feedback is welcome. #### What's Changed - fix(vanilla): should mount once with atom creator atom by [@​nogaten](https://github.com/nogaten) in [https://github.com/pmndrs/jotai/pull/2319](https://github.com/pmndrs/jotai/pull/2319) - feat(utils): createJSONStrage options by [@​dai-shi](https://github.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/2324](https://github.com/pmndrs/jotai/pull/2324) - feat(utils): add withStorageValidator by [@​dai-shi](https://github.com/dai-shi) in [https://github.com/pmndrs/jotai/pull/2336](https://github.com/pmndrs/jotai/pull/2336) #### New Contributors - [@​L-Qun](https://github.com/L-Qun) made their first contribution in [https://github.com/pmndrs/jotai/pull/2318](https://github.com/pmndrs/jotai/pull/2318) - [@​ahme-dev](https://github.com/ahme-dev) made their first contribution in [https://github.com/pmndrs/jotai/pull/2332](https://github.com/pmndrs/jotai/pull/2332) - [@​nogaten](https://github.com/nogaten) made their first contribution in [https://github.com/pmndrs/jotai/pull/2319](https://github.com/pmndrs/jotai/pull/2319) **Full Changelog**: pmndrs/jotai@v2.6.1...v2.6.2 ### [`v2.6.1`](https://github.com/pmndrs/jotai/releases/tag/v2.6.1) [Compare Source](https://github.com/pmndrs/jotai/compare/v2.6.0...v2.6.1) This version has two minor improvements for library authors. It's wonderful to see Jotai ecosystem growing. No major bugs have been reported lately. It's fairly okay to say the current version is pretty stable. #### What's Changed - fix(utils): add init property to the return type of atomWithReset by [@​jaesoekjjang](https://github.com/jaesoekjjang) in [https://github.com/pmndrs/jotai/pull/2304](https://github.com/pmndrs/jotai/pull/2304) - fix(utils): add description for the RESET symbol. by [@​MiroslavPetrik](https://github.com/MiroslavPetrik) in [https://github.com/pmndrs/jotai/pull/2307](https://github.com/pmndrs/jotai/pull/2307) #### New Contributors - [@​wherehows](https://github.com/wherehows) made their first contribution in [https://github.com/pmndrs/jotai/pull/2270](https://github.com/pmndrs/jotai/pull/2270) - [@​benson00077](https://github.com/benson00077) made their first contribution in [https://github.com/pmndrs/jotai/pull/2284](https://github.com/pmndrs/jotai/pull/2284) - [@​ioExpander](https://github.com/ioExpander) made their first contribution in [https://github.com/pmndrs/jotai/pull/2280](https://github.com/pmndrs/jotai/pull/2280) - [@​jaesoekjjang](https://github.com/jaesoekjjang) made their first contribution in [https://github.com/pmndrs/jotai/pull/2304](https://github.com/pmndrs/jotai/pull/2304) **Full Changelog**: pmndrs/jotai@v2.6.0...v2.6.1 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/likec4/likec4). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xNzMuMCIsInVwZGF0ZWRJblZlciI6IjM3LjE3My4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Related Issues or Discussions
Fixes downstream issue for https://ui.shadcn.com/
It crashes when cookies are disabled with this exception:
Summary
On Firefox accessing the property localStorage of window results in a
DOMException: The operation is insecure.
This PR will handle this case gracefully and fall back to providing no storage implementation. This should be fine as we cannot store anything in a cookie-free browser.
Check List
yarn run prettier
for formatting code and docs