Skip to content

Commit

Permalink
navReducer: Better decide if we have server data in rehydrate.
Browse files Browse the repository at this point in the history
As hinted by the comment above this edit, even an empty array is
incomplete server data: "Valid server data must have a user: the
self user, at a minimum.".

But the initial state of `users` (`initialState` in
src/users/usersReducer.js) is an empty array. LOGOUT, LOGIN_SUCCESS,
and ACCOUNT_SWITCH all set `users` to that initial state.

Those three actions are handled in `navReducer` by navigating to
routes that don't depend on complete server data: 'loading' or
'account'.

But if we quit the app with `users` having this initial state (e.g.,
giving up in frustration while trying to connect to a realm for a
long time), we should be sure that, on reopening it and rehydrating,
we don't try to go to 'main' before that initial state has been
replaced with a complete state. Otherwise, we see "No server data
found" errors and a white screen.

See also discussion [1].

[1]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/.23M4166.20Time.20out.20initial.20fetch/near/912017
  • Loading branch information
chrisbobbe committed Jun 23, 2020
1 parent 7209221 commit a647c8e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/nav/navReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const rehydrate = (state, action) => {
// will have set `needsInitialFetch`, too, so we really will be loading.
//
// (Valid server data must have a user: the self user, at a minimum.)
if (rehydratedState.users === undefined) {
if (rehydratedState.users === undefined || rehydratedState.users.length === 0) {
return getStateForRoute('loading');
}

Expand Down

0 comments on commit a647c8e

Please sign in to comment.