twenty
twenty copied to clipboard
fix: RightDrawer doesn't save context values when clickedOutside
Description
- This PR fixes the issue #7728
Changes
https://github.com/user-attachments/assets/1e66cab3-9009-4c01-9ac6-22651b0ff5e7
Hello @harshit078, thank you for contributing :) Even if your solution works, I'm not sure that it is the right approach.
The bug happens because closeRightDrawer is a recoilCallback and is thus executed outside of the flow of react. I asked @lucasbordeau why it was that way and apparently it was needed for the email threads. I think the right solution is to rename closeRightDrawer to closeRightDrawerRecoilCallback inside useRightDrawer and to export closeRightDrawer like this:
const setIsRightDrawerOpen = useSetRecoilState(isRightDrawerOpenState);
const setIsRightDrawerMinimized = useSetRecoilState(
isRightDrawerMinimizedState,
);
const closeRightDrawer = () => {
setIsRightDrawerOpen(false);
setIsRightDrawerMinimized(false);
};
I'll let @charlesBochet and @lucasbordeau confirm though.
/award 200
Awarding harshit078: 200 points 🕹️ Well done! Check out your new contribution on oss.gg/harshit078
@harshit078 We want to avoid debouncing as it is non deterministic.
Could you try with useListenRightDrawerClose ? Maybe in the drawer title component ?
@harshit078 When we need to debounce, it's generally a code smell because it means the underlying logic is too complex, we'll work on that to refactor this part, so the logic to persist a field can be deterministically and easily called before closing the right drawer.
Follow-up issues : https://github.com/twentyhq/core-team-issues/issues/192 and https://github.com/twentyhq/core-team-issues/issues/160
Thanks @harshit078 for your contribution! This marks your 36th PR on the repo. You're top 1% of all our contributors 🎉 See contributor page - Share on LinkedIn - Share on Twitter

Sentry Issue: TWENTY-FRONT-2TZ