Not properly re-initializing Flowbite after turbo stream render
cyu opened this issue · comments
Describe the bug
With the most recent changes to flowbite.turbo.js, the turbo:after-stream-render
is fired on the document, but the event listener is attached to the window. Therefore, initFlowbite
is never called when after stream render.
To Reproduce
Steps to reproduce the behavior:
- Render an Accordion component from a turbo stream render
- The Accordion will not be initialized and will not respond to events
Expected behavior
When initFlowbite
is called properly after turbo stream render, the Accordion component is initialized and will respond to click events
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Mac OSX
- Browser: Safari
- Version: 17.4
Smartphone (please complete the following information):
- Device: N/A
- OS: N/A
- Browser: N/A
- Version: N/A
Additional context
Here are the relevant code that is causing this issue:
This is where we're dispatching the custom turbo:after-stream-render
event (note that it fires the event from document
):
Line 26 in aee4853
This is how we're binding to the that custom event to call initFlowbite
:
Line 39 in aee4853
Unfortunately, this Events
class binds to window
and not document
:
Line 13 in aee4853
A workaround is to create your own listener that listens to the document instead:
document.addEventListener("turbo:after-stream-render", () => {
window.initFlowbite()
})