Skip to content

Commit 87f74b6

Browse files
committed
add beforeunload listener only when undoable is true
1 parent eaf18ce commit 87f74b6

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

packages/ra-ui-materialui/src/layout/Notification.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ export const Notification = (props: NotificationProps) => {
4444

4545
useEffect(() => {
4646
const beforeunload = (e: BeforeUnloadEvent) => {
47-
if (messageInfo?.notificationOptions?.undoable) {
48-
e.preventDefault();
49-
}
47+
e.preventDefault();
5048
};
5149

52-
window.addEventListener('beforeunload', beforeunload);
50+
if (messageInfo?.notificationOptions?.undoable) {
51+
window.addEventListener('beforeunload', beforeunload);
52+
}
5353

5454
if (notifications.length && !messageInfo) {
5555
// Set a new snack when we don't have an active one

0 commit comments

Comments
 (0)