ni / nimble

The NI Nimble Design System
https://nimble.ni.dev
MIT License
32 stars 8 forks source link

Blazor EventCallbacks are not invoked with apps using .NET 8 template #2355

Open epetersoni opened 2 months ago

epetersoni commented 2 months ago

πŸ› Bug Report

Our app was initially created with the Blazor Server App .NET 7 template in VisualStudio. We recently followed the guide to update it to the .NET 8 Blazor Web App template.

It looks like at least some Nimble EventCallbacks are now not getting invoked. Two examples are the NimbleBanner OpenChanged, and the NimbleMenuButton Toggle.

πŸ’» Repro or Code Sample

πŸ€” Expected Behavior

The EventCallback should get invoked.

😯 Current Behavior

The EventCallback is not invoked.

πŸ’ Possible Solution

Official Nimble .NET 8 support. I'm not sure exactly what difference is causing the behavior change.

πŸ”¦ Context

Since updating our app to use the .NET 8 template, a few pieces of functionality that were relying on callbacks are now not working.

We didn't have a specific reason for updating to the .NET 8 template, so we'll need to evaluate what all the callback-related bugs are and whether we should revert the update and / or wait for fixes to this bug.

🌍 Your Environment

jattasNI commented 2 months ago

@epetersoni could you attach a zip of the the .NET 8 you used to reproduce this?

I added this issue as acceptance criteria under #1667 so we'll plan to tackle it as part of that (presumably before .NET 6 goes out of support).

epetersoni commented 2 months ago

@jattasNI net8_no_nimble_callback.zip

msmithNI commented 1 month ago

@epetersoni It looks like this is due to the changes to the Blazor startup process and JS initializers for .NET 8.

NimbleBlazor relies on the afterStarted callback which is now a "classic"/deprecated initializer, which is not called by default.
Blazor provides a way to opt back into the classic initialization behavior, and that looks like a workaround to this issue:

    <script src="_framework/blazor.web.js" autostart="false"></script>
    <script src="_content/NimbleBlazor/nimble-components/all-components-bundle.min.js"></script>
    <script>
        Blazor.start({ enableClassicInitializers: true });
    </script>

However, that Microsoft page states "However, legacy initializer execution is unpredictable."

BlazorEventCallbacks.zip

Once we update Nimble Blazor to target .NET 8, we'll update our JS initialization code to use the new methods, so it's probably best to wait for that. (HLD for that work)