You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When Onyx.clear() is called the storage is cleared and then Onyx is initialized with the defaultKeyStates provided by the application. In NewDot transition flows, when a user is signing into a different account, Onyx is cleared to sign out the old user and then the new user is immediately signed in, setting a new authToken on the session. By the time initializeWithDefaultKeyStates is called, the new user has been signed in.
In the method, the defaultKeyStates are merged into the key states existing in storage, which are all null after clearing the storage. Then keyChanged is called for each (key, value) pair from the defaultKeyStates. The default key state for session is {loading: false, shouldShowComposeInput: true}, and therefore the subscribers are notified that the session has been updated to this value, and the user is signed out.
Here you can see how the currentValue from the cache contains the full, merged, session information, but the val from defaultKeyStates only contains limited information for initializing.
Solution
Notify the subscribers with merged cache data when initializing with default key states.
The text was updated successfully, but these errors were encountered:
I would actually expect a call to Onyx.clear() to be blocking in that if we attempted to set any new data to Onyx while we were clearing it would throw these updates away to prevent cache pollution and cause the conflicts we are describing here.
If you need to set data after storage and cache is cleared then the obvious answer is to just wait for the storage and cache to clear then add the new data.
The problem with the solution and linked PR is that we are making assumptions about the data we are setting when Onyx.clear() is running. Is it something that should be in the store after Onyx.clear() finishes or not? Was it from the previous user session or meant for the next?
After a lot of discussion in Slack we agreed on a solution where we set the default key states while clearing the cache, and remove the call to initializeWithDefaultKeyStates.
Problem
When Onyx.clear() is called the storage is cleared and then Onyx is initialized with the defaultKeyStates provided by the application. In NewDot transition flows, when a user is signing into a different account, Onyx is cleared to sign out the old user and then the new user is immediately signed in, setting a new authToken on the session. By the time initializeWithDefaultKeyStates is called, the new user has been signed in.
In the method, the defaultKeyStates are merged into the key states existing in storage, which are all null after clearing the storage. Then keyChanged is called for each (key, value) pair from the defaultKeyStates. The default key state for session is
{loading: false, shouldShowComposeInput: true}
, and therefore the subscribers are notified that the session has been updated to this value, and the user is signed out.Here you can see how the currentValue from the cache contains the full, merged, session information, but the val from defaultKeyStates only contains limited information for initializing.
Solution
Notify the subscribers with merged cache data when initializing with default key states.
The text was updated successfully, but these errors were encountered: