vikramlearning / blazorbootstrap

An Enterprise-class Blazor Bootstrap Component library built on the Blazor and Bootstrap CSS frameworks.
https://docs.blazorbootstrap.com/
Apache License 2.0
748 stars 38 forks source link

After updating to 1.10.2 Sidebar stopped working #515

Closed Kirillbzp closed 9 months ago

Kirillbzp commented 9 months ago

Describe the bug After updating to 1.10.2 Sidebar stopped working. Immediately when the application is launched and Sidebar is rendered, an exception with the text "Could not find 'window.blazorBootstrap.sidebar.initialize' ('sidebar' was undefined)." is thrown. All versions after 1.10.2 have this bug. After downgrading to 1.10.1 the error disappears

Screenshots image

Versions (please complete the following information):

Sample code

@inherits LayoutComponentBase

<div class="bb-page">

    <Sidebar @ref="sidebar"
             IconName="IconName.Git"
             Title="Title"
             DataProvider="SidebarDataProvider" />

    <main>
        <div class="bb-top-row px-4 d-flex justify-content-end">

        </div>

        <article class="content px-4">
            <div class="py-2">
                @Body
            </div>
        </article>
    </main>

</div>

@code {
    private Sidebar sidebar = default!;
    private IEnumerable<NavItem> navItems = default!;

    private async Task<SidebarDataProviderResult> SidebarDataProvider(SidebarDataProviderRequest request)
    {
        if (navItems is null)
            navItems = GetNavItems();

        return await Task.FromResult(request.ApplyTo(navItems));
    }

    private IEnumerable<NavItem> GetNavItems()
    {
        navItems = new List<NavItem>
        {
            new NavItem { Id = "1", Href = "/", IconName = IconName.HouseDoorFill, Text = "Home", Match=NavLinkMatch.All},
            new NavItem { Id = "2", Href = "/dashboard", IconName = IconName.Database, Text = "Dashboard"},
            new NavItem { Id = "3", Href = "/projects", IconName = IconName.Database, Text = "Projects"},
            new NavItem { Id = "4", Href = "/profile", IconName = IconName.PersonFillGear, Text = "Settings"},
            new NavItem { Id = "5", Href = "/logout", IconName = IconName.BoxArrowRight, Text = "Logout"},
        };

        return navItems;
    }
}

Desktop (please complete the following information):

MarvinKlein1508 commented 9 months ago

I would assume this is related to caching. v.1.10.2 added a new feature to clase the navigation on mobile devices which added new sidebar specific functions to blazor.bootstrap.js

https://github.com/vikramlearning/blazorbootstrap/commit/75c4b816d1b2b9239ead291f7a3b507b414beb89

Try clearing your cache after upgrading.

gvreddy04 commented 9 months ago

@Kirillbzp Please upgrade to the latest version. If you still encounter the issue, let us know or create a new issue.

powertec-dan commented 9 months ago

I have a similar, but not identical problem with one project.

Could not find 'window.blazorBootstrap.sidebar.windowSize' ('blazorBootstrap' was undefined).

I've tried this from version 1.10.1 through to 1.11.1. It works fine on 1.10.1 but not on any of the others. I think the change in 1.10.2 is also contributing here.

Marvin mentioned clearing a cache after upgrading, which cache was he referring to?

Also worth noting is that this is only happening on one project, I have at least five others that are behaving correctly, so I think it is an environmental issue, not anything else. If you can give me any pointers as to what I can look for in my environment to correct, I would be grateful.

Cheers, Dan

MarvinKlein1508 commented 9 months ago

@powertec-dan

Check in your browser dev tools the blazor.bootstrap.js file. It should look like this: grafik

If it does not contain this segment. Try clearing the cache of the website within the dev tools. Or depending on your browser you can open https://your_address/_content/Blazor.Bootstrap/blazor.bootstrap.js and press CTRL+SHIFT+R at the same time.

powertec-dan commented 9 months ago

Ok, excellent. Thank you for the advice.

If anyone else is struggling with this, my problem was because during the migration of code from one project to another, the launchSettings.json file was omitted. This in turn meant that the _content folder was not published.

Apologise for taking your time with such a fundamental issue, but hopefully leaving this here might help someone in the future.