You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MAUI Project can not import web-components script automatically #404
changed the title [-]MAUI Project can not import web-components script.automatically[/-][+]MAUI Project can not import web-components script automatically[/+]on May 23, 2023
Build generates [AppName].modules.json file (bin[Configuration][FW][Platform]\AppX\wwwroot[AppName].modules.json) and populates it with found initilizers, but blazor.webview.js doesn't use this file.
It loads initializers from '_framework/blazor.modules.json' instead. blazor.modules.json contains an empty array, it's embeded as resource in Microsoft.AspNetCore.Components.WebView and provided to blazor.webview.js by WebViewManager as is - array of initializers is always empty.
As sort of PoC, replaced '_framework/blazor.modules.json' with 'MauiApp1.modules.json', rebuilt Microsoft.AspNetCore.Components.WebView and copied new version into bin folder:
Microsoft.Fast.Components.FluentUI.lib.module.js was loaded and controls initialized properly
There's a simpler workaround: intercept '_framework/blazor.modules.json' and provide proper JS initializers file (created by build). You can drop this initializersLoader.windows.js into wwwroot folder of app and add script tag for it to index.html right before '_framework/blazor.webview.js' tag:
'app-name' attribute needs to match app's assembly name - initializersLoader uses 'app-name' to resolve name of the file with initializers.
initializersLoader replaces 'fetch' function with another one which provides the right file instead of empty blazor.modules.json. 'fetch' is restored to its original state once '_framework/blazor.modules.json' request is intercepted.
When original issue is resolved, all that need to be done is to remove the tag and the script.
There's a simpler workaround: intercept '_framework/blazor.modules.json' and provide proper JS initializers file (created by build). You can drop this initializersLoader.windows.js into wwwroot folder of app and add script tag for it to index.html right before '_framework/blazor.webview.js' tag:
'app-name' attribute needs to match app's assembly name - initializersLoader uses 'app-name' to resolve name of the file with initializers. initializersLoader replaces 'fetch' function with another one which provides the right file instead of empty blazor.modules.json. 'fetch' is restored to its original state once '_framework/blazor.modules.json' request is intercepted.
When original issue is resolved, all that need to be done is to remove the tag and the script.
Doesn't work for me. I am running it on android emulator and all I get is [chromium] [INFO:CONSOLE(1)] "Uncaught (in promise) SyntaxError: Unexpected token ?", source: https://0.0.0.0/_content/Microsoft.FluentUI.AspNetCore.Components/Microsoft.FluentUI.AspNetCore.Components.lib.module.js (1) . App is then frozen at startup. I am using one of Geralds projects in MAUI blazor hybrid workshop.
Activity
[-]MAUI Project can not import web-components script.automatically[/-][+]MAUI Project can not import web-components script automatically[/+]LuohuaRain commentedon May 31, 2023
In
v2.3.4, this issue can still be reproduced. And same with(WPF) Blazor appandreisaperski commentedon May 31, 2023
Looks like the root cause for this issue is the same as for #327.
Microsoft.Fast.Components.FluentUI package has an initializer Microsoft.Fast.Components.FluentUI.lib.module.js which loads web-components.js, but this initializer is ignored by Blazor Hybrid.
Build generates [AppName].modules.json file (bin[Configuration][FW][Platform]\AppX\wwwroot[AppName].modules.json) and populates it with found initilizers, but blazor.webview.js doesn't use this file.
It loads initializers from '_framework/blazor.modules.json' instead. blazor.modules.json contains an empty array, it's embeded as resource in Microsoft.AspNetCore.Components.WebView and provided to blazor.webview.js by WebViewManager as is - array of initializers is always empty.
As sort of PoC, replaced '_framework/blazor.modules.json' with 'MauiApp1.modules.json', rebuilt Microsoft.AspNetCore.Components.WebView and copied new version into bin folder:
Microsoft.Fast.Components.FluentUI.lib.module.js was loaded and controls initialized properly
vnbaaij commentedon May 31, 2023
Andrei Saperski (@andreisaperski) Can you test if custom web component events (like accordion change event) work with this setup as well?
andreisaperski commentedon May 31, 2023
Copied content of AccordionDefault.razor into Index.razor of MAUI App, initial state:
After click on 'Panel two':

Handler for @onaccordionchange was called and Accordion raised OnAccordionItemChange
vnbaaij commentedon May 31, 2023
So if people want to use the library in MAUI, we just need to tell them to compile their own WebView and everything works! 🤣🤣
andreisaperski commentedon May 31, 2023
There's another option )

vnbaaij commentedon Jun 2, 2023
Andrei Saperski (@andreisaperski) please chime in on the issue in the aspnetcore repo I linked to above
andreisaperski commentedon Jun 2, 2023
Vincent Baaij (@vnbaaij) not sure if i can add anything there, the comment you linked there, reflects all i have
andreisaperski commentedon Jun 8, 2023
There's a simpler workaround: intercept '_framework/blazor.modules.json' and provide proper JS initializers file (created by build). You can drop this initializersLoader.windows.js into wwwroot folder of app and add script tag for it to index.html right before '_framework/blazor.webview.js' tag:
'app-name' attribute needs to match app's assembly name - initializersLoader uses 'app-name' to resolve name of the file with initializers.
initializersLoader replaces 'fetch' function with another one which provides the right file instead of empty blazor.modules.json. 'fetch' is restored to its original state once '_framework/blazor.modules.json' request is intercepted.
When original issue is resolved, all that need to be done is to remove the tag and the script.
vnbaaij commentedon Jun 9, 2023
Adding these instructions to the Blazor Hybrid section in the readme!!
vnbaaij commentedon Jun 10, 2023
Closing this as we now have a workaround. See https://github.com/microsoft/fluentui-blazor#tempory-workaround-for-maui-issues for the details
Kalyxt commentedon Sep 11, 2024
Doesn't work for me. I am running it on android emulator and all I get is
[chromium] [INFO:CONSOLE(1)] "Uncaught (in promise) SyntaxError: Unexpected token ?", source: https://0.0.0.0/_content/Microsoft.FluentUI.AspNetCore.Components/Microsoft.FluentUI.AspNetCore.Components.lib.module.js (1). App is then frozen at startup. I am using one of Geralds projects in MAUI blazor hybrid workshop.vnbaaij commentedon Sep 11, 2024
Kalyxt is this on .NET 8 or 9?
Kalyxt commentedon Sep 12, 2024
Vincent Baaij (@vnbaaij) .NET 8
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.9.3" /><PackageReference Include="Microsoft.Maui.Controls" Version="8.0.82" /><PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.82" /><PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.82" />