Skip to content

Commit

Permalink
fix: fix portal cleanup (fix #209)
Browse files Browse the repository at this point in the history
  • Loading branch information
igordanchenko committed Nov 27, 2023
1 parent 443ba5f commit 02d8f49
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/modules/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ export function Portal({ children, animation, styles, className, on, portal, clo
};
}, []);

const handleCleanup = useEventCallback(() => {
cleanup.current.forEach((clean) => clean());
cleanup.current = [];
});

const handleClose = useEventCallback(() => {
setVisible(false);

cleanup.current.forEach((clean) => clean());
cleanup.current = [];
handleCleanup();

on.exiting?.();

Expand Down Expand Up @@ -97,9 +101,11 @@ export function Portal({ children, animation, styles, className, on, portal, clo
(node: HTMLDivElement | null) => {
if (node) {
handleEnter(node);
} else {
handleCleanup();
}
},
[handleEnter],
[handleEnter, handleCleanup],
);

return mounted
Expand Down

0 comments on commit 02d8f49

Please sign in to comment.