Having multiple Providers stops an atomWithStorage from syncing changes within the same tab #3166
-
Bug DescriptionWhen using This works for cross-tab synchronization, but not same-tab if the atoms are used under different Providers. I would expect it to synchronize via storage also within the same tab, even if the atoms are used with different jotai stores Looking for similar issues I found: #2881 which seem to support my interpretation Reproduction Link |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Thanks for reporting. Your sandbox uses the default storage, which uses 'storage' event. Maybe storage event doesn't fire in the same window. Our general suggestion is not to rely on it for the same window, because there should be a better way within the same memory. All that said, there might be a bug in atomWithStorage lib code. Feel free to dig into it. |
Beta Was this translation helpful? Give feedback.
I updated my example to use
createJSONStoragebut that shouldn't do much since that is the default storage. What did clue me in to what is happening was addingAnd it showed me that the events were only raised in the other browser windows/tabs not in the one I clicked the checkboxes in, this is true for both atoms both the ones using the same store and the ones that doesn't.
A quick look at MDN shows me that what I expected to happen was never going to be: