MudBlazor / TryMudBlazor

A playground for trying out and testing MudBlazor components entirely in the browser.
https://try.mudblazor.com/
GNU General Public License v2.0
75 stars 37 forks source link

Session crashes when running a snippet containing only a component definition #103

Closed npalmer-zs closed 1 year ago

npalmer-zs commented 1 year ago

When the following snippet is pasted into the initial razor file, the session crashes. Restarting the application resolves the issue, clearing browser cache & data resolves the issue.

@typeparam T
@inherits MudSelectItem<T>

<MudSelectItem @onmouseenter="ShowButtons" @onmouseleave="HideButtons" T="@T"
               Class="@Class"
               Value="@Value"
               Command="@Command"
               Disabled="@Disabled"
               Href="@Href"
               Style="@Style"
               Tag="@Tag"
               CommandParameter="@CommandParameter"
               DisableRipple="@DisableRipple"
               ForceLoad="@ForceLoad"
               OnClick="@OnClick">
    <MudContainer Class="d-inline-flex ma-0 pa-0">
        <MudText Class="d-inline-flex flex-shrink-0">@(Text ?? Value.ToString())</MudText>
        <MudContainer Class="d-inline-flex flex-grow-1"/>
        @if (_showButtons)
        {
            <MudIconButton Class="d-inline-flex z-10" Size="Size.Small" Title="@EditTitle" Icon="@EditIcon" Color="@EditColor" OnClick="@(async () => await OnEdit(Value))"/>
            <MudDivider Class="mx-2" Vertical="true" FlexItem="true" />
            <MudIconButton Class="d-inline-flex z-10" Size="Size.Small" Title="@DeleteTitle" Icon="@DeleteIcon" Color="@DeleteColor" OnClick="@(async () => OnDelete(Value))"/>
        }
    </MudContainer>
</MudSelectItem>

@code {
    [Parameter]
    public string? Text { get; set; }

    [Parameter]
    public Func<T, Task> OnEdit { get; set; }

    [Parameter]
    public Func<T, Task> OnDelete { get; set; }

    [Parameter]
    public string? EditTitle { get; set; } = "Edit";

    [Parameter]
    public string? DeleteTitle { get; set; } = "Delete";

    [Parameter]
    public string? EditIcon { get; set; } = Icons.Material.Outlined.Edit;

    [Parameter]
    public string? DeleteIcon { get; set; } = Icons.Material.Outlined.Delete;

    [Parameter]
    public Color EditColor { get; set; } = Color.Info;

    [Parameter]
    public Color DeleteColor { get; set; } = Color.Error;

    private bool _showButtons { get; set; }

    private async Task HideButtons(MouseEventArgs args)
    {
        _showButtons = false;
        InvokeAsync(StateHasChanged);
    }

    private void ShowButtons(MouseEventArgs args)
    {
        _showButtons = true;
        InvokeAsync(StateHasChanged);
    }

    private async void InvokeEdit()
    {
        await OnEdit(Value);
    }

    private async void InvokeDelete()
    {
        await OnDelete(Value);
    }
}
npalmer-zs commented 1 year ago

The error received in the browser dev console is:

System.AggregateException: One or more errors occurred. (Could not resolve type with token 0100006f from typeref (expected class 'Try.UserComponents.__Main' in assembly 'Try.UserComponents, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'))
 ---> System.TypeLoadException: Could not resolve type with token 0100006f from typeref (expected class 'Try.UserComponents.__Main' in assembly 'Try.UserComponents, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null')
   at TryMudBlazor.Client.Program.Main(String[] args)
   --- End of inner exception stack trace ---
npalmer-zs commented 1 year ago

On the main website I was having issues where the site was unavailable on multiple devices after triggering this issue in a session, but I am unable to reproduce the issue when running on my local network and don't want to try again on the public site.

Appears that this issue only affects a single session, I'll update the issue description accordingly.

henon commented 1 year ago

I simplified the snippet to find out what is the core issue:

@typeparam T

<MudText Typo="Typo.h6">Typeparams are not supported!</MudText>

TryMudBlazor does not support typeparams at the moment.

npalmer-zs commented 1 year ago

Would you mind if I attempted to add a check for type params with a user facing notification in a pull request?

henon commented 1 year ago

that would be awesome, thank you!

henon commented 1 year ago

I guess the restriction only applies to the main component, right?

npalmer-zs commented 1 year ago

Yes, the way I encountered the issue was accidentally replacing the main component from code copied out of my IDE instead of a second file I had previously created and was using without any issues.

henon commented 1 year ago

right. this is also proof: https://try.mudblazor.com/snippet/GuGnkFmLUxSdggSW

henon commented 1 year ago

by the way, the session un-breaks once the typparam is removed from the main component

npalmer-zs commented 1 year ago

Do you think it'd be better to check when initially receiving the stream from the browser, or when going to compile to assembly?

henon commented 1 year ago

Not sure what is the best approach. Here are a few ideas:

I am sure you'll find out what is best

npalmer-zs commented 1 year ago

There is already some pre-compile validation being done on the front-end that I was able to tack another check onto. Created pull request https://github.com/MudBlazor/TryMudBlazor/pull/104