-
Notifications
You must be signed in to change notification settings - Fork 18
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
Missing Stylesheet after navigating in .NET 8 #2642
Comments
Any workaround? Same problem here... |
It seems, that all my favorite Blazor library developers have shifted priorities away from .NET 8 Blazor 😭. |
I have the same problem. |
I found a workaround. This is because of the new Blazor SSR, it changes the way that JS is rendered. You need to use PageScript: https://github.com/MackinnonBuck/blazor-page-script Import the SweetAlert2 Script in the MainLayout like this: Set a RenderMode for HeadOutlet like this: With this trick everything should be working just fine. This trick solved issues with all JS-based libraries I've imported. |
In case anyone wonders: The NuGet package of PageScript is named " And you have to add this to "_Imports.razor":
|
@Pvxtotal When doing your steps, I get an error:
Could you please share some more code of your solution? |
@UweKeim in your case use HeadOutlet like this: <HeadOutlet @rendermode="new InteractiveServerRenderMode(prerender: false)" /> |
Thanks, @Pvxtotal, I've already tried that, too, without success. I've changed the <HeadOutlet @rendermode="new InteractiveServerRenderMode(prerender: false)" /> I removed this from the "App.razor": <script src="_content/CurrieTechnologies.Razor.SweetAlert2/sweetAlert2.min.js"></script> And then I've added this to "MainLayout.razor": <HeadContent>
<PageScript Src="_content/CurrieTechnologies.Razor.SweetAlert2/sweetAlert2.min.js" />
</HeadContent> When clicking the button to show a SweetAlert2 dialog, I get this error:
With this call stack:
Probably I'm missing something but can't figure out what. |
./ at the start |
Thanks again, @Pvxtotal, I've also tried this without success. |
It seems that I solved it by not placing the <PageScript Src="/_content/CurrieTechnologies.Razor.SweetAlert2/sweetAlert2.min.js" /> I still have to have this in the "App.razor": <HeadOutlet @rendermode="new InteractiveServerRenderMode(prerender: false)" /> But all after all, it seems to work. |
Sorry for my absence. I'll be looking into this, but .NET 8 runtime support has been added. That may aleviate this issue, but if there is a breaking change in .NET 8 I'll need to work out a fix. |
@Basaingeal This is related to how Blazor SSR load scripts when enhanced navigation is on. If you disable enhanced navigation everything works fine. I still don't know any workaround besides disabling enhanced navigation or turning the entire app into Interactive. Source: dotnet/aspnetcore#52273 |
Work for me adding only this line @rendermode="@RenderMode.InteractiveServer" on app.razor in HeadOutlet and Routes also works fine with @rendermode="@(new InteractiveServerRenderMode(false))"
|
Hi muadyb, your solution worked fine for me, Thanks four you help :)! |
Hi muadyb, your solution worked fine for me, Thanks four you help :)! |
|
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:
I then added
to my project's CSPROJ file, added
right to the end before the
</body>
tag:and added this to my "Program.cs":
Next, I created a simple button in "Home.razor":
I've also changed
@rendermode InteractiveServer
on that page. The full source code of the page looks like this:This results in this:
When I click the button, it shows this alert:
I can do this multiple times successfully.
Next, I navigate to another page:
And then I navigate back to the home page:
When I then click the button, the alert appears, but it seems to have no styling:
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
The text was updated successfully, but these errors were encountered: