Skip to content

Missing Stylesheet after navigating in .NET 8 #2642

@UweKeim

Description

@UweKeim

Issue

After navigating away and back to a page, a call to Swal.FireAsync() shows an alert that has CSS missing.

Steps

I've created a new Blazor Web App with these configuration settings:

image

I then added

<PackageReference Include="CurrieTechnologies.Razor.SweetAlert2" Version="5.5.0" />

to my project's CSPROJ file, added

<script src="_content/CurrieTechnologies.Razor.SweetAlert2/sweetAlert2.min.js"></script>

right to the end before the </body> tag:

image

and added this to my "Program.cs":

builder.Services.AddSweetAlert2(options =>
{
	options.Theme = SweetAlertTheme.Dark;
	options.SetThemeForColorSchemePreference(ColorScheme.Light, SweetAlertTheme.Default);
	options.SetThemeForColorSchemePreference(ColorScheme.Dark, SweetAlertTheme.Dark);
});

Next, I created a simple button in "Home.razor":

<button @onclick="@(async ()=>await Swal.FireAsync("Test!"))">Test, klick!</button>

I've also changed @rendermode InteractiveServer on that page. The full source code of the page looks like this:

@page "/"
@rendermode InteractiveServer
@inject SweetAlertService Swal

<PageTitle>Home</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

<button @onclick="@(async ()=>await Swal.FireAsync("Test!"))">Test, klick!</button>

This results in this:

image

When I click the button, it shows this alert:

image

I can do this multiple times successfully.

Next, I navigate to another page:

image

And then I navigate back to the home page:

image

When I then click the button, the alert appears, but it seems to have no styling:

image

It is shown that the bottom left of the page.

It seems to work correctly (i.e. I can click the OK button to close the alert), but it looks wrong.

Expected behavior

I would expect that Razor.SweetAlert2 works every time, not just when I do not navigate.

Desktop

  • OS: Windows 11 German, 64 bit
  • Browser: Google Chrome Version 120.0.6099.71 (Offizieller Build) (64-Bit)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions