Fix keyboard shortcuts snackbar text showing stale values#3165
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). nusmods-website – ./website🔍 Inspect: https://vercel.com/nusmodifications/nusmods-website/pn5cgya4f nusmods-export – ./export🔍 Inspect: https://vercel.com/nusmodifications/nusmods-export/gs6edg29b |
Codecov Report
@@ Coverage Diff @@
## master #3165 +/- ##
==========================================
- Coverage 55.44% 55.43% -0.02%
==========================================
Files 253 253
Lines 5312 5313 +1
Branches 1226 1226
==========================================
Hits 2945 2945
- Misses 2367 2368 +1
Continue to review full report at Codecov.
|
|
Deployment preview for |
|
|
||
| const mode = useSelector(({ settings }: State) => settings.mode); | ||
| const themeId = useSelector(({ theme }: State) => theme.id); | ||
| const store = useStore(); |
There was a problem hiding this comment.
Is it possible to use this instead so that we don't have to keep casting the store type?
| const store = useStore(); | |
| const store = useStore<State>(); |
There was a problem hiding this comment.
Woops, forgot that this exists. Fixed in c282a2d.
In #3007 there was a regression when we functionalized
KeyboardShortcuts. Whenever we press x to toggle light/dark mode or z/c to cycle themes, the snackbar that pops out will always show the old value. This can be repro-ed in prod.This is due to our useSelector hook always capturing the old stale value when displaying the notification snackbar, due to the rendering lifecycle of functional components.
To fix this, we directly access the redux store when we want to display the notification snackbars, to get the most current values.