themesberg/flowbite

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

honeypc opened this issue · 0 comments

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);
        };
    }
});