themesberg / flowbite

Open-source UI component library and front-end development framework based on Tailwind CSS
https://flowbite.com
MIT License
7.3k stars 710 forks source link

Uncaught TypeError: Cannot read properties of null (reading 'render') Turbo-rails + Flowbite #839

Open honeypc opened 3 months ago

honeypc commented 3 months ago

Describe the bug The issue happened while I was using the custom render template Turbo.renderStreamMessage(HTML) at https://github.com/themesberg/flowbite/blob/main/src/index.turbo.ts#L22

Screenshots Screenshot 2024-03-24 191544

Expected behavior So we can handle the issue by updating like this


addEventListener('turbo:before-stream-render', (event: CustomEvent) => {
    if(event.detail) {
        const originalRender = event.detail.render;

        event.detail.render = function (streamElement: Element) {
            originalRender(streamElement);
            document.dispatchEvent(afterRenderEvent);
        };
    }
});