Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keyboard shortcuts snackbar text showing stale values #3165

Merged
merged 3 commits into from
Jan 16, 2021

Conversation

chrisgzf
Copy link
Member

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.

@vercel
Copy link

vercel bot commented Jan 16, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

nusmods-website – ./website

🔍 Inspect: https://vercel.com/nusmodifications/nusmods-website/pn5cgya4f
✅ Preview: https://nusmods-website-git-fork-chrisgzf-fix-nightmode-toggle-text.nusmodifications.vercel.app

nusmods-export – ./export

🔍 Inspect: https://vercel.com/nusmodifications/nusmods-export/gs6edg29b
✅ Preview: https://nusmods-export-git-fork-chrisgzf-fix-nightmode-toggle-text.nusmodifications.vercel.app

@codecov
Copy link

codecov bot commented Jan 16, 2021

Codecov Report

Merging #3165 (a7c7814) into master (b539cc3) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
website/src/views/components/KeyboardShortcuts.tsx 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b539cc3...a7c7814. Read the comment docs.

@nusmods-deploy-bot
Copy link

nusmods-deploy-bot bot commented Jan 16, 2021

Copy link
Member

@taneliang taneliang left a comment

Choose a reason for hiding this comment

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

Thanks @chrisgzf for fixing a bug I caused 😆

@@ -33,8 +33,7 @@ const KeyboardShortcuts: React.FC = () => {
const [helpShown, setHelpShown] = useState(false);
const closeModal = useCallback(() => setHelpShown(false), []);

const mode = useSelector(({ settings }: State) => settings.mode);
const themeId = useSelector(({ theme }: State) => theme.id);
const store = useStore();
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to use this instead so that we don't have to keep casting the store type?

Suggested change
const store = useStore();
const store = useStore<State>();

Copy link
Member Author

Choose a reason for hiding this comment

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

Woops, forgot that this exists. Fixed in c282a2d.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants