You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently building an application using Blazor SSR and HTMX. Within one of my pages, I have a delete button that triggers the replacement of a placeholder div and then opens the parent modal.
<ModalId="delete-confirm-modal" Title="Delete"><divid="delete-ingredient-confirm" class="p⁻4 flex items-center justify-center"><!-- placeholder to be replaced --></div></Modal>
(Modal is a simple Blazor component that encapsulates the functionality)
The div #delete-confirm-modal works perfectly. The X to dismiss the modal works, as it is not part of the content loaded via HTMX. But in my dynamic content, there's a button that allows me to answer: « No, cancel », which triggers the modal to close, and it doesn't fire, given it has been loaded following the initialization. Alright, I say, let's reinitialize flowbite whenever I load new content:
htmx.onLoad(function(content){initFlowbite()})
Thing is, now a second instance of my modal appears on top of the first one. And weirdly enough, the backdrop disappears until I click on it again.
Before dismissing
After dimissing
Notice the backdrop difference?
Here's the (beautified) inspect when I have the layered components:
Strangely enough, my inspect only shows the modal being rendered once. If I omit (re-)initializing flowbite on HTMX load events, this strange behaviour doesn't happen.
EDIT: Inspecting the instances
Here we can see that, despite the modal being shown, it thinks it's hidden.
Here we can see that once the duplicated modal is closed, it shows the proper state.
Potential Fix/Feature Request
A good way to solve this type of issues would be to have a proper re-initialization function that omits instances that are already initialized. Like so:
htmx.onLoad(function(content){reinitFlowbite()// or initUnitializedFlowbite(), or initFlowbite({uninitializedOnly: true})})
Or to simply ignore already initialized instances with the base function.
The text was updated successfully, but these errors were encountered:
samld
changed the title
[HTMX/Flowbite.js] initModals() causes an open modal to display twice
[HTMX/Flowbite.js] initFlowbite() causes an open modal to display twice
Feb 28, 2024
The issue
I'm currently building an application using Blazor SSR and HTMX. Within one of my pages, I have a delete button that triggers the replacement of a placeholder div and then opens the parent modal.
(Modal is a simple Blazor component that encapsulates the functionality)
The div
#delete-confirm-modal
works perfectly. TheX
to dismiss the modal works, as it is not part of the content loaded via HTMX. But in my dynamic content, there's a button that allows me to answer: « No, cancel », which triggers the modal to close, and it doesn't fire, given it has been loaded following the initialization. Alright, I say, let's reinitialize flowbite whenever I load new content:Thing is, now a second instance of my modal appears on top of the first one. And weirdly enough, the backdrop disappears until I click on it again.
Before dismissing
![image](https://private-user-images.githubusercontent.com/20801877/308667633-856d5cc2-792d-409f-bd38-125c3ca13bad.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgzMjQ3MDAsIm5iZiI6MTcxODMyNDQwMCwicGF0aCI6Ii8yMDgwMTg3Ny8zMDg2Njc2MzMtODU2ZDVjYzItNzkyZC00MDlmLWJkMzgtMTI1YzNjYTEzYmFkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjE0VDAwMjAwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNmYzk1M2FhOWY3OGRjMTIzOWMxODgzODU0M2JhOTNiODNkOThmZjNkYjgzNTAxYmUyNGU4Y2EyNGJmNzQwYjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.yR8LV4I_qxbdUa2BxTlqFl7yLvN2fO4ddZoYrPeajgc)
![image](https://private-user-images.githubusercontent.com/20801877/308667843-2721023b-801d-4b7e-8e89-a07e6aab16fa.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgzMjQ3MDAsIm5iZiI6MTcxODMyNDQwMCwicGF0aCI6Ii8yMDgwMTg3Ny8zMDg2Njc4NDMtMjcyMTAyM2ItODAxZC00YjdlLThlODktYTA3ZTZhYWIxNmZhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjE0VDAwMjAwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYwODk5NTE3ODJiNjExYzhjNDdjNzU5ZmE3YzIyNjZiMDkxM2I4OTFiYzU0OGM1MzlkMDcyYzUxNWViY2EwMGQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.qHiqnKBaCtbCaF7-XWvAXnEfhqpbH2gV5pPCzhIeJHE)
After dimissing
Notice the backdrop difference?
Here's the (beautified) inspect when I have the layered components:
Strangely enough, my inspect only shows the modal being rendered once. If I omit (re-)initializing flowbite on HTMX load events, this strange behaviour doesn't happen.
EDIT: Inspecting the instances
Here we can see that, despite the modal being shown, it thinks it's hidden.
![image](https://private-user-images.githubusercontent.com/20801877/308717960-a51d695c-a6fd-47fa-9e85-e9ad15666fe0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgzMjQ3MDAsIm5iZiI6MTcxODMyNDQwMCwicGF0aCI6Ii8yMDgwMTg3Ny8zMDg3MTc5NjAtYTUxZDY5NWMtYTZmZC00N2ZhLTllODUtZTlhZDE1NjY2ZmUwLnBuZz9YLUFtei1BbG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yMjIzOTYzMWNlM2E1YjgyZDEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.HOqfziMoTtS50olmLwh1--RVPh1DqLie062DCycs18c)
Here we can see that once the duplicated modal is closed, it shows the proper state.
![image](https://private-user-images.githubusercontent.com/20801877/308718384-aa692e14-bdeb-43f2-b797-770556de2697.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgzMjQ3MDAsIm5iZiI6MTcxODMyNDQwMCwicGF0aCI6Ii8yMDgwMTg3Ny8zMDg3MTgzODQtYWE2OTJlMTQtYmRlYi00M2YyLWI3OTctNzcwNTU2ZGUyNjk3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjE0VDAwMjAwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc0YmY5ZjU0Y2UwMTQxOWI1MzUxZjZlYzhhOTQwNjRmZGI0MzhhNGY1YTQ3N2E2YjQwMTU3ZWUwZTJjN2M2OTEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.U5Qjp-XHASmkoLNhfdPjvWj0-olewZy_U65kbDOWSWQ)
![image](https://private-user-images.githubusercontent.com/20801877/308718609-6b4d06bb-66e4-47ad-bf17-e66219cb2f79.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgzMjQ3MDAsIm5iZiI6MTcxODMyNDQwMCwicGF0aCI6Ii8yMDgwMTg3Ny8zMDg3MTg2MDktNmI0ZDA2YmItNjZlNC00N2FkLWJmMTctZTY2MjE5Y2IyZjc5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjE0VDAwMjAwMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNjY2NjZWY3Y2U4Zjg4ZWY3Y2RjNzhiY2ZhZjE2NzgwNGNlZjgxZGNmMjEzMmY1MDA0YTdhNzk3MWU5ZTc1NjYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.F88Fyj9XqvvT8f6nVmoQZ8W9HPPe7a2eH8VBSt-HcGU)
Potential Fix/Feature Request
A good way to solve this type of issues would be to have a proper re-initialization function that omits instances that are already initialized. Like so:
Or to simply ignore already initialized instances with the base function.
The text was updated successfully, but these errors were encountered: