EdCharbeneau / BlazorSize

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

blazorSize.js not found #72

Closed DrTekno closed 2 years ago

DrTekno commented 2 years ago

Environment:

WASM and .NET6. Debugging : updated Chrome and VSCode.

Problem

I have MediaQueryList always null so i have added <script src="_content/BlazorPro.BlazorSize/blazorSize.js"></script> to my '.cshtml' file but still the file cant be found.

image

My question is : Should the file be generated in the bin when build the application? Because is not my case and i've seen is hard coded here: https://github.com/EdCharbeneau/BlazorSize/blob/net6/BlazorSize/MediaQuery/MediaQueryService.cs#L16

Thanks

EdCharbeneau commented 2 years ago

If you're on the latest version of BlazorSize you don't need the script tag. The latest version imports the script using modual imports.

Does this error occur normally? Is that why you're adding the script?

EdCharbeneau commented 2 years ago

Please make sure you have the service added to DI, and a MediaQueryList component at the root level.

DrTekno commented 2 years ago

Yes i've added '.AddMediaQueryService()' to DI, and 'MediaQueryList' component at the root level but without the script tag i've this error

image

I've also add using BlazorPro.BlazorSize to _Import.razor and i'm testing like this

 @if (IsSmall)
        {
            <p>YES IS SMALL</p>
        }
        else
        {
            <p>NOT SMALL</p>
        }
<MediaQuery Media="@Breakpoints.SmallDown" @bind-Matches="IsSmall" />

@code {
    bool IsSmall = false;
}

to check if is working

EdCharbeneau commented 2 years ago

Any chance you can share a complete project or sample that has this issue?

DrTekno commented 2 years ago

The project is quite complex and i have finally found another solution but aniway thank you for your suggestions.

juangallostra commented 2 years ago

@EdCharbeneau I'm currently facing the same issue when trying to use BlazorSize. I have some other custom packages that are also raising this type of error after migrating to .NET 6.0.

Haven't solved the issue myself yet, but here is some useful info I've found so far:

image

EdCharbeneau commented 2 years ago

What I can't figure out is when this happens to a very specific minority of users. If you download the .nupkg file and rename it to .zip, you'll see that the required JavaScript assets are included where they belong.

EdCharbeneau commented 2 years ago

Maybe related to: https://github.com/EdCharbeneau/BlazorSize/issues/71#issuecomment-1029222043

dennisrahmen commented 2 years ago

@EdCharbeneau for me it's working fine while debugging. But after publishing I get the same error as @juangallostra.

juangallostra commented 2 years ago

@EdCharbeneau release 6.1.2 fixed the problem for me. I was testing locally on windows (had no problems) but deploying from a Docker Image running Linux (related to #73).

EdCharbeneau commented 2 years ago

@juangallostra thanks for following up

sholman commented 2 years ago

I've installed 6.1.2 and am getting this error. I can see the staticwebfiles in the nuget package but they're not being deployed on publish

EdCharbeneau commented 2 years ago

Can you double check this in your server's build process please? https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-6.0#serve-files-in-web-root

sholman commented 2 years ago

Can you double check this in your server's build process please? https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-6.0#serve-files-in-web-root

Yes, this is definitely included

The only difference with this app is that it's a .NET 5 app upgraded to a .NET 6 app but still has separate Startup and Program files.

EdCharbeneau commented 2 years ago

This issue was originally caused by Linux systems because they are case sensitive. One of the JavaScript files used an uppercase character in the file, but lower case in the C# codebase. The issue was fixed in 6.1.2.

Is there any way you're caching an old version? or the server is on a different version?

Is the server Linux?

sholman commented 2 years ago

This issue was originally caused by Linux systems because they are case sensitive. One of the JavaScript files used an uppercase character in the file, but lower case in the C# codebase. The issue was fixed in 6.1.2.

Is there any way you're caching an old version? or the server is on a different version?

Is the server Linux?

Hi Ed, no, running on Windows. Same issue occurs on live app service and staging deployment slot.