Toolbelt.Blazor.HotKeys2 icon indicating copy to clipboard operation
Toolbelt.Blazor.HotKeys2 copied to clipboard

Hotkeys2 and MAUI Blazor Hybrid compatibility

Open tnglemongrass opened this issue 1 year ago • 5 comments

I try to use the Hotkeys2 library in a MAUI Blazor Hybrid App with .NET 8, following the instructions from the Hotkeys2 README.

Maybe there is just something missing in the README instructions?

Description:

When using the HotKeys2 library in a Maui Blazor Hybrid App, an error/warning is displayed on startup. However, the app runs fine and hotkeys work as expected.

Steps to Reproduce:

  • Create a new ".NET MAUI Blazor Hybrid App" with .NET 8.0 in Visual Studio 2022.
  • Follow the instructions on https://github.com/jsakamoto/Toolbelt.Blazor.HotKeys2 to set up the HotKeys2 library.
  • Run the app and observe the error/warning message in the console.

Expected Behavior:

There should be no errors or warnings on startup.

Actual Behavior:

The following error message is displayed on startup:

Toolbelt.Blazor.HotKeys2.HotKeys: Error: Could not find 'Toolbelt.Blazor.getProperty' ('Toolbelt' was undefined).
Error: Could not find 'Toolbelt.Blazor.getProperty' ('Toolbelt' was undefined).

Additional Information:

The app runs fine and hotkeys work as expected, despite the error message.

A minimal reproducible example is here: https://github.com/tnglemongrass/ToolbeltHotkeys2Demo/

tnglemongrass avatar Mar 13 '24 09:03 tnglemongrass

@tnglemongrass Thank you for letting me know about the problem. I must have overlooked the Blazor Hybrid scenario. As a workaround for a while, could you try to add one <script> tag in the wwwroot/index.html for the content, "_content/Toolbelt.Blazor.GetProperty.Script/Toolbelt.Blazor.GetProperty.Script.lib.module.js", like the following pull request?

https://github.com/tnglemongrass/ToolbeltHotkeys2Demo/pull/1

Actually, I've never tried that workaround on my side yet because I've been a bit busy these weeks. I'm sorry for that. Anyway, I hope the workaround above works well. (And I'd like to fix this problem someday.)

jsakamoto avatar Mar 16 '24 00:03 jsakamoto

@jsakamoto Yes, including that script tag fixes it. Thanks for looking into it and thanks a lot for that workaround!

tnglemongrass avatar Mar 16 '24 12:03 tnglemongrass

@jsakamoto I was also having the same issue when trying to run ilovedotnet blazor wasm project via blazor hybrid project... Adding the script as mentioned solves the exception.

You can use https://github.com/ILoveDotNet/ilovedotnet/tree/main/MAUI to test.

fingers10 avatar Mar 23 '24 12:03 fingers10

[FYI] This problem is a bug in the .NET SDK.

See also: https://github.com/dotnet/maui/issues/15234

Fortunately, I've verified the problem went away on the .NET 9 SDK Preview 5. So, please take the workaround of explicitly adding a script loading as below until the release of the .NET 9 SDK.

<!-- wwwroot/index.html -->
<!-- 👇 Add this script tag before the script tag, which loads the "blazor.webview.js" JavaScript file. -->
<script src="_content/Toolbelt.Blazor.GetProperty.Script/Toolbelt.Blazor.GetProperty.Script.lib.module.js" type="module"></script>

jsakamoto avatar Jun 27 '24 23:06 jsakamoto