Closed rofenix2 closed 2 years ago
I haven't done a lot of testing with Server Side Rendering. Thanks for reporting the issue so I can try to reproduce it and find a solution.
For some reason I'm not able to reproduce it. Let's talk about your setup a bit more.
How is pre-rendering enabled? Is this a Blazor WebAssembly project or Razor components via ASP.NET Core MVC or Razor Pages?
Please see my sample for reference: https://github.com/EdCharbeneau/BlazorSizePrerendering
The project its a default Blazor Server App template from VS2022 (Razor pages). The pre rendering comes enabled by default in _Host.cshtml:
<component type="typeof(App)" render-mode="ServerPrerendered" />
Ive uploaded a default project with only the minimal changes to reproduce the bug. Also the link you provided doesnt work it throws me a 404 page not found.
Btw i believe Blazor documentation says: "Disposal can occur at any time, including during component initialization", so when the components get disposed in turn they will dispose the MediaQuery from the library and make a call to JS which will trigger a exception since its still in pre rendering phase.
Not sure if its relevant but i have on my IIS configuration the DefaultAppPool with a Shutdown Time Limit of 1 second, since i need to deploy a lot of times for testing and IIS will keep my files locked cause the browser keeps sending reconnection request so i lowered to 1 second in order to avoid this.
I finally got a break to check this out. This is a standard Blazor Server app. It should work as expected, there must be something in your configuration. I tested the zip file and everything works locally.
Hi, I've been using this great library, just one bug:
When i create two MediaQuery with the same Media breakpoint and the components get Disposed in pre rendering (Blazor Server) it will trigger the Dispose of MediaQuery.razor and in turn will try to eliminate the registered breakpoints calling JS which trigger a exception since JavaScript cant be used while pre rendering.
The method that causes the bug is the following in MediaQueryService.cs:
Maybe it needs to check if we are on pre rendering and avoid calling JS or delay it till we are. I tried the following patch:
But i could not test it since when i compile and run the project i get a weird Microsoft.JSInterop.JSException: error loading dynamically imported module. I believe i've read that annoying bug before here in the Issues section, but that's another topic.
How to reproduce:
<MediaQueryList>
to App.razorYou might be wondering why add two tags with the same breakpoint, but thats not how i originally got the bug, the reason is i use two different components (one after the another) and both check for the same breakpoints, this is just a easy way to recreate the bug.
Thanks.