Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load theme JavaScript module earlier from HTML #4888

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Aspire.Dashboard/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@
<Routes @rendermode="@(new InteractiveServerRenderMode(prerender: false))" />
<script src="_framework/blazor.web.js"></script>
<script src="js/app.js"></script>

@*
Directly reference theme and dependencies from HTML so they load quickly.
It's much faster to load them here than wait for module load from Blazor interop.
Load time is important here because the theme should be applied ASAP.
*@
<script src="js/app-theme.js" type="module"></script>
<script src="_content/Microsoft.FluentUI.AspNetCore.Components/Microsoft.FluentUI.AspNetCore.Components.lib.module.js" type="module"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
_jsModule = await JS.InvokeAsync<IJSObjectReference>("import", "/js/theme.js");
_jsModule = await JS.InvokeAsync<IJSObjectReference>("import", "/js/app-theme.js");
_currentSetting = await _jsModule.InvokeAsync<string>("getThemeCookieValue");
StateHasChanged();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Components/Layout/MainLayout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
_jsModule = await JS.InvokeAsync<IJSObjectReference>("import", "/js/theme.js");
_jsModule = await JS.InvokeAsync<IJSObjectReference>("import", "/js/app-theme.js");
_shortcutManagerReference = DotNetObjectReference.Create(ShortcutManager);
_keyboardHandlers = await JS.InvokeAsync<IJSObjectReference>("window.registerGlobalKeydownListener", _shortcutManagerReference);
ShortcutManager.AddGlobalKeydownListener(this);
Expand Down
Loading