hperrin / svelte-material-ui

Svelte Material UI Components
https://sveltematerialui.com/
Apache License 2.0
3.27k stars 287 forks source link

notifyClose does not check element's type #653

Open PierreTurnbull opened 2 months ago

PierreTurnbull commented 2 months ago

Describe the bug When notifyClose is called after open has been set to false, it dispatches "SMUIMenuSurface:closed". However element's type is not checked, which can lead to some uncatched error (note element's type is any). When the component is unmounted and the event is dispatched, it causes the following error: Tried to dipatch event without element..

To Reproduce To reproduce the problem, start this project locally : https://github.com/PierreTurnbull/smui-bug-select-demo Open the console. Open the select, then close the dialog. Notice the error in the console.

Expected behavior The component should not emit events after being unmounted.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context The dialog that I used is from the Flowbite library and the Select is from the SMUI library. I did so in a personal sandbox where I test diverse libraries and tools. I would not usually mix 2 distinct component libraries as it's usually simpler and more coherent to have 1. That being said it should be possible to use both. I tried reproducing the problem with only SMUI components (SMUI dialog and SMUI select) but I could not reproduce the bug, as SMUI's dialog does not unmount its children, it only hides the dialog. I wonder if SMUI follows some philosophy of never unmounting and instead always hiding on close. If that was the case then it would not be a bug but a misuse from my part. I have not found anything indicating this tho. If that is not the case then I think components should handle being unmounted.