mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	fix(react/dialogs): listener leak in modal
This commit is contained in:
		@@ -28,14 +28,23 @@ export default function Modal({ children, className, size, title, footer, onShow
 | 
				
			|||||||
    if (onShown || onHidden) {
 | 
					    if (onShown || onHidden) {
 | 
				
			||||||
        useEffect(() => {
 | 
					        useEffect(() => {
 | 
				
			||||||
            const modalElement = modalRef.current;
 | 
					            const modalElement = modalRef.current;
 | 
				
			||||||
            if (modalElement) {
 | 
					            if (!modalElement) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            if (onShown) {
 | 
					            if (onShown) {
 | 
				
			||||||
                modalElement.addEventListener("shown.bs.modal", onShown);
 | 
					                modalElement.addEventListener("shown.bs.modal", onShown);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (onHidden) {
 | 
					            if (onHidden) {
 | 
				
			||||||
                modalElement.addEventListener("hidden.bs.modal", onHidden);
 | 
					                modalElement.addEventListener("hidden.bs.modal", onHidden);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            return () => {
 | 
				
			||||||
 | 
					                if (onShown) {
 | 
				
			||||||
 | 
					                    modalElement.removeEventListener("shown.bs.modal", onShown);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                if (onHidden) {
 | 
				
			||||||
 | 
					                    modalElement.removeEventListener("hidden.bs.modal", onHidden);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }    
 | 
					    }    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user