Page MenuHomePhabricator

[native] Alert staff/developers if `REHYDRATE` action payload isn't as expected
ClosedPublic

Authored by atul on Nov 8 2022, 2:27 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 24, 6:38 PM
Unknown Object (File)
Sun, Nov 24, 6:14 PM
Unknown Object (File)
Sun, Nov 24, 6:09 PM
Unknown Object (File)
Sun, Nov 24, 6:04 PM
Unknown Object (File)
Sun, Nov 24, 5:25 PM
Unknown Object (File)
Sun, Nov 24, 3:23 PM
Unknown Object (File)
Sun, Nov 24, 6:31 AM
Unknown Object (File)
Sun, Nov 24, 6:31 AM
Subscribers

Details

Summary

Context: https://linear.app/comm/issue/ENG-2127/

We want to make sure that the payload we get from the REHYDRATE action has all the keys that we expect.

In this diff we add a check to redux-setup:reducer(...) for staff/developers that pulls the keys out of the REHYDRATE payload and makes sure that it matches what we expect (keys in defaultState MINUS those in persistConfig.blacklist)

Test Plan

Ensured that the alerts displayed as expected by modifying logic. Also logged values and checked that they were as expected.

Diff Detail

Repository
rCOMM Comm
Branch
master
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

atul published this revision for review.Nov 8 2022, 2:29 PM
atul edited the summary of this revision. (Show Details)
native/redux/redux-setup.js
142–146

We should probably factor this out... do we have a task to track?

Also, realizing my idea of storing the state of "has the user ever been logged in?" in a React context is a bad idea if we ever want to use it in a reducer... probably should just keep it in Redux somewhere

156

Hmmmmm this worries me. Is there some rehydrate-failed state where action.payload isn't set? Would rather pull the user up to the login screen than eg. put the app in a crash loop or something

177–181

Do both OSs handle double-Alerts gracefully?

native/redux/redux-setup.js
142–146

We use the useStaffCanSee(...) hook elsewhere, but I don't think we can use that here?

156

Could I instead do Object.keys(action.payload ?? {});?

I'll take a look through the codebase

177–181

Works fine on iOS, I'll flip conditions so they both alway trigger and check on Android Emulator

native/redux/redux-setup.js
142–146

If we kept it in Redux we wouldn't need a hook

native/redux/redux-setup.js
142–146

I can create a task to move staffUserHasBeenLoggedIn from a React.Context to Redux, but is there anything actionable for this diff?

native/redux/redux-setup.js
142–146

No, just the task would be great. Let's mention:

  1. We should move the state from React Context to Redux
  2. We should update the hook to check from Redux
  3. We should update this location and any others that couldn't previously use the hook to use the new state in Redux
ashoat requested changes to this revision.Nov 8 2022, 3:13 PM

Back to you

This revision now requires changes to proceed.Nov 8 2022, 3:13 PM

remove invariant... about to test multiple alerts on Android

Looks good pending testing

This revision is now accepted and ready to land.Nov 9 2022, 8:13 AM
In D5571#165428, @atul wrote:

remove invariant... about to test multiple alerts on Android

an hour and 26 minutes later, can confirm that things work as expected on Android:

isStaffRelease export in staff-utils