diff --git a/src/realm/__tests__/realmReducer-test.js b/src/realm/__tests__/realmReducer-test.js index d40510d17cf..fdcf692b941 100644 --- a/src/realm/__tests__/realmReducer-test.js +++ b/src/realm/__tests__/realmReducer-test.js @@ -11,7 +11,7 @@ import { NULL_OBJECT } from '../../nullObjects'; describe('realmReducer', () => { describe('ACCOUNT_SWITCH', () => { - test('resets state to initial state', () => { + test('resets state to blank state', () => { const initialState = NULL_OBJECT; const action = deepFreeze({ @@ -21,6 +21,7 @@ describe('realmReducer', () => { const expectedState = { canCreateStreams: true, crossRealmBots: [], + email: '', isAdmin: false, twentyFourHourTime: false, emoji: {}, diff --git a/src/realm/realmReducer.js b/src/realm/realmReducer.js index 006db46b41a..682530928b1 100644 --- a/src/realm/realmReducer.js +++ b/src/realm/realmReducer.js @@ -22,6 +22,23 @@ const initialState = { nonActiveUsers: [], }; +/** + * A version of `initialState` with some made-up blank data. + * + * On `LOGIN_SUCCESS`, we go straight to showing the main app UI (see + * `navReducer`) even though we're still loading the actual data from the + * server. So we need some fake data that the UI code will swallow. + * TODO: Probably stop doing that. + * + * Also: On `ACCOUNT_SWITCH`, during the transition animation, some old + * components can still be mounted from the UI for the previous account that + * make no sense without server data. Probably ditto `LOGOUT`. + */ +const fakeBlankState = { + ...initialState, + email: '', +}; + const convertRealmEmoji = (data): RealmEmojiById => { const emojis = {}; Object.keys(data).forEach(id => { @@ -35,7 +52,7 @@ export default (state: RealmState = initialState, action: Action): RealmState => case LOGOUT: case LOGIN_SUCCESS: case ACCOUNT_SWITCH: - return initialState; + return fakeBlankState; case REALM_INIT: { return {