Skip to content
4 changes: 2 additions & 2 deletions src/nav/__tests__/navReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NULL_OBJECT } from '../../nullObjects';

describe('navReducer', () => {
describe('LOGIN_SUCCESS', () => {
test('replaces the existing route stack with "main" on sign in', () => {
test('replaces the existing route stack with "loading" on sign in', () => {
const prevState = deepFreeze({
index: 2,
routes: [{ key: 'one' }, { key: 'two' }, { key: 'password' }],
Expand All @@ -18,7 +18,7 @@ describe('navReducer', () => {

const expectedState = {
index: 0,
routes: [{ routeName: 'main' }],
routes: [{ routeName: 'loading' }],
};

const newState = navReducer(prevState, action);
Expand Down
4 changes: 1 addition & 3 deletions src/nav/navReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ export default (state: NavigationState = initialState, action: Action): Navigati
return rehydrate(state, action);

case ACCOUNT_SWITCH:
return getStateForRoute('loading');

case LOGIN_SUCCESS:
return getStateForRoute('main');
return getStateForRoute('loading');

case INITIAL_FETCH_COMPLETE:
return state.routes[0].routeName === 'main' ? state : getStateForRoute('main');
Expand Down
6 changes: 3 additions & 3 deletions src/realm/__tests__/realmReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { NULL_OBJECT } from '../../nullObjects';

describe('realmReducer', () => {
describe('ACCOUNT_SWITCH', () => {
test('resets state to blank state', () => {
test('resets state', () => {
const initialState = NULL_OBJECT;

const action = deepFreeze({
Expand All @@ -21,8 +21,8 @@ describe('realmReducer', () => {
const expectedState = {
canCreateStreams: true,
crossRealmBots: [],
email: '',
user_id: 0,
email: undefined,
user_id: undefined,
isAdmin: false,
twentyFourHourTime: false,
emoji: {},
Expand Down
22 changes: 1 addition & 21 deletions src/realm/realmReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
} from '../actionConstants';
import { objectFromEntries } from '../jsBackport';

// Initial state
const initialState = {
canCreateStreams: true,
crossRealmBots: [],
Expand All @@ -24,24 +23,6 @@ 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: '',
user_id: 0,
};

const convertRealmEmoji = (data): RealmEmojiById =>
objectFromEntries(Object.keys(data).map(id => [id, { ...data[id], code: id.toString() }]));

Expand All @@ -50,11 +31,10 @@ export default (state: RealmState = initialState, action: Action): RealmState =>
case LOGOUT:
case LOGIN_SUCCESS:
case ACCOUNT_SWITCH:
return fakeBlankState;
return initialState;

case REALM_INIT: {
return {
...state,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this involves spreading a value and type-checking in a reducer, I was vaguely reminded of this Flow bug.

I verified empirically that it isn't in play after this commit. (Making a property undefined trips Flow.) The next commit helps verify that everything's working as expected by reading the code. So in this case it wasn't necessary to go re-digest what exactly that Flow bug is.

@chrisbobbe chrisbobbe Apr 30, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On re-scanning the Flow issue Ray linked to, it sounds plausible that maybe the bug was happening before this commit? Anyway, the important thing is that it's not happening after it. 😆

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks good to me, but Ray may have more to say.

canCreateStreams: action.data.can_create_streams,
crossRealmBots: action.data.cross_realm_bots,
email: action.data.email,
Expand Down