flowbite icon indicating copy to clipboard operation
flowbite copied to clipboard

Blazor SSR Flowbite not initializing after navigation

Open vukasinpetrovic opened this issue 1 year ago • 1 comments

Describe the bug I just setup Blazor Server app with Flowbite and added dropdown, basically everything as it's in the documentation. It displays it and dropdown opens. Problem occurs when I navigate to another page, and come back to homepage where dropdown is. Now it is not working. I realized it's happening because Blazor changes only part of the HTML (even in SSR) and Flowbite JS is not called again to initialize component. After manually hard refreshing the page, it loads again. This is not dropdown related, but any component that requires JS Flowbite to interact.

How can we solve this?

It's also mentioned here: https://github.com/themesberg/tailwind-blazor-starter/issues/8

vukasinpetrovic avatar Mar 27 '24 15:03 vukasinpetrovic

I have same issue! did you figure it out? @vukasinpetrovic

sardar97 avatar May 15 '24 19:05 sardar97

Yeah, I'm getting this too, exact same issue and component as @vukasinpetrovic. Any pointers?

paulpitchford avatar May 25 '24 17:05 paulpitchford

Yeah, I'm getting this too, exact same issue and component as @vukasinpetrovic. Any pointers?

I fixed it by adding this codes to my App.razor <script> Blazor.addEventListener('enhancedload', () => { // https://flowbite.com/docs/getting-started/javascript/ initFlowbite(); }); </script>

sardar97 avatar May 26 '24 09:05 sardar97

@paulpitchford Sorry for the delayed answer. I solved it the same way as @sardar97 using that event listener. It is called whenever some navigation happens while using enhanced navigation, so we call initFlowbite() function again, which in turn reinitializes all found components in view.

<script src="_framework/blazor.web.js"></script>
<script>
  Blazor.addEventListener('enhancedload', function () {
    initFlowbite();
  });
</script>

vukasinpetrovic avatar May 28 '24 07:05 vukasinpetrovic