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

[LIVE-12968][LLM] QueuedDrawer: if onClose changes, drawer shouldn't auto close #7068

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shy-pots-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

Fix QueuedDrawer component so that onClose prop value can change without triggering an auto close of the drawer.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const MainTestScreen = () => {
const [drawer3RequestingToBeOpened, setDrawer3RequestingToBeOpened] = useState(false);
const [drawer4ForcingToBeOpened, setDrawer4ForcingToBeOpened] = useState(false);

const handleDrawer1Close = useCallback(() => setDrawer1RequestingToBeOpened(false), []);
const handleDrawer1Close = () => setDrawer1RequestingToBeOpened(false); // purposely not using useCallback to check if drawer behaves well when onClose prop changes
const handleDrawer2Close = useCallback(() => setDrawer2RequestingToBeOpened(false), []);
const handleDrawer3Close = useCallback(() => setDrawer3RequestingToBeOpened(false), []);
const handleDrawer4Close = useCallback(() => setDrawer4ForcingToBeOpened(false), []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,17 @@ const QueuedDrawer = ({
setIsDisplayed(true);
}, []);

const onCloseRef = useRef(onClose);
onCloseRef.current = onClose;

const triggerClose = useCallback(() => {
setIsDisplayed(false);
if (drawerInQueueRef.current?.getPositionInQueue() !== 0) {
drawerInQueueRef.current?.removeDrawerFromQueue();
drawerInQueueRef.current = undefined;
}
onClose && onClose();
}, [onClose]);
onCloseRef.current && onCloseRef.current(); // hack to avoid triggering the useEffect below if the parent changes the onClose prop
}, []);
Comment on lines +93 to +94
Copy link
Contributor

Choose a reason for hiding this comment

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

No problem with the hack here, just pointing out that they recently talked about useEvent for this kind of scenario
https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md
facebook/react#14099

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aaah interesting !


useEffect(() => {
if (!isFocused && (isRequestingToBeOpened || isForcingToBeOpened)) {
Expand Down
Loading