EdCharbeneau / BlazorSize

Blazor browser size interop for matchMedia and browser window size at runtime.
336 stars 39 forks source link

Found a bug #55

Closed ehinolakingsley closed 2 years ago

ehinolakingsley commented 3 years ago

The latest nuget is broken. My app won't run. I had to downgrade to 3.2.1 to resolve the issue

EdCharbeneau commented 3 years ago

Can you elaborate? What's "broken"? An exception? If so, what is it?

Which version of .NET are you using?

ehinolakingsley commented 3 years ago

I am using .Net 5 and what was broken is this! But when i downgraded to 3.2.1 i don't get this error. image

image

EdCharbeneau commented 3 years ago

Thank you. Is there any way you can provide an isolated demo of this happening?

I'm not catching it in my tests, and cannot reproduce it. I've seen this reported before and would like to fix it, but I can't seem to find an example of it happening.

ehinolakingsley commented 3 years ago

I am sorry for my late response. I know right. I tried replicating it with a sample project but i can't also. I will find a way to.

I have to say this. God bless you for creating this library. It's very beautiful and made life very easy for me. Keep up this great work sir.

ehinolakingsley commented 3 years ago

image image

ehinolakingsley commented 3 years ago

I noticed services.AddMediaQueryService(); was missing in the service. So i added it and i got the error above. But on 3.2.1 I didn't include it and it's still worked.

What i can do is if possible, we could schedule a meeting and debug together. Thanks

kenneymyers commented 3 years ago

For what it is worth I am also seeing this and I have services.AddMediaQueryService(); in my startup. It's really problematic. I'm not so sure it isn't a side effect of the circuit getting disconnected. It's very strange. If you were able to resolve it for others I would love to find out how it got resolved.

kenneymyers commented 3 years ago

This is what I am seeing and it causes the blazor server to terminate the connection which is highly problematic.

22T17:05:48.090Z] Error: Microsoft.JSInterop.JSException: dotnet reference was not found in the collection of media query lists Error: dotnet reference was not found in the collection of media query lists at BlazorSizeMedia.getMediaQueryListById (https://localhost:44351/_content/BlazorPro.BlazorSize/blazorSizeMedia.js:15:23) at BlazorSizeMedia.addMediaQueryToList (https://localhost:44351/_content/BlazorPro.BlazorSize/blazorSizeMedia.js:26:35) at Module.addMediaQueryToList (https://localhost:44351/_content/BlazorPro.BlazorSize/blazorSizeMediaModule.js:17:21) at https://localhost:44351/_framework/blazor.server.js:1:70045 at new Promise () at e.beginInvokeJSFromDotNet (https://localhost:44351/_framework/blazor.server.js:1:70011) at https://localhost:44351/_framework/blazor.server.js:1:26293 at Array.forEach () at e.invokeClientMethod (https://localhost:44351/_framework/blazor.server.js:1:26263) at e.processIncomingData (https://localhost:44351/_framework/blazor.server.js:1:24201) at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args) at BlazorPro.BlazorSize.MediaQueryService.Initialize(MediaQuery mediaQuery) at BlazorPro.BlazorSize.MediaQueryList.Initialize(MediaQuery mediaQuery) at BlazorPro.BlazorSize.MediaQuery.OnAfterRenderAsync(Boolean firstRender) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

kenneymyers commented 3 years ago

I have a simple example project that I can send to @EdCharbeneau that at least demonstrates a pretty major issue for me that I think would shed some light.

EdCharbeneau commented 3 years ago

I'm currently out of the office, but if you can email me at ed.charbeneau@gmail.com I can take a look Tuesday.

EdCharbeneau commented 3 years ago

Were you able to send me the project? If so, please let me know what email you sent it from as it may have gotten filtered.

kenneymyers commented 3 years ago

I rewrote the project to use the listener instead of the MediaQueryList. It seemed like a problem that is a lower level issue with the dotnet reference object possibly to do with the changes to support javascript isolation, not sure. The listener solved all of my problems so I just ran with that. I can readily reproduce the problem though by just creating an MVC project with .NET 5, add blazor server, create a component that uses the MediaQueryList and load that sucker up. That will do it.

EdCharbeneau commented 3 years ago

@longhornleads I Just created an MVC Project with .NET 6 and added BlazorSize. I was unable to reproduce the error.

Index.cshtml
@(await Html.RenderComponentAsync<Component>(RenderMode.ServerPrerendered))
Component.razor
<MediaQueryList>
    <MediaQuery Media="@Breakpoints.SmallDown">
        <Matched>
            <h3>Small</h3>
        </Matched>
        <Unmatched>
            <h3>Large</h3>
        </Unmatched>
    </MediaQuery>
</MediaQueryList>