Skip to content
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

Nested Editor<T> crashing because of bug in HtmlFieldPrefix.Combine method #53956

Open
1 task done
sal-versij opened this issue Feb 12, 2024 · 3 comments · May be fixed by #58888
Open
1 task done

Nested Editor<T> crashing because of bug in HtmlFieldPrefix.Combine method #53956

sal-versij opened this issue Feb 12, 2024 · 3 comments · May be fixed by #58888
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug.
Milestone

Comments

@sal-versij
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Nesting more than 2 Editor leads to an exception

Expected Behavior

It should work properly and not throw any exception

Steps To Reproduce

https://github.com/sal-versij/NestedEditorTCrash

Just visit the home

Exceptions (if any)

Unhandled exception rendering component: Object reference not set to an instance of an object.
    System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.AspNetCore.Components.Forms.ExpressionFormatter.FormatLambda(LambdaExpression expression, String prefix)
       at Microsoft.AspNetCore.Components.Forms.HtmlFieldPrefix.GetFieldName(LambdaExpression expression)
       at Microsoft.AspNetCore.Components.Forms.InputBase`1.get_NameAttributeValue()
       at Microsoft.AspNetCore.Components.Forms.InputNumber`1.BuildRenderTree(RenderTreeBuilder builder)
       at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

.NET Version

8.0.100

Anything else?

After searching why this happens, I've found that in HtmlFieldPrefix.cs:23 the loop is not actually looping through the whole _rest because it uses restLength - 1 instead of length - 1 or restLength itself, thus it's ignoring the last element of _rest that is left as the default value in expressions: null, this is propagated to the inputs inside the innermost editor that, when executing GetFieldName(...) throws because _rest of the input contains a null value passed to ExpressionFormatter.FormatLambda that throws NullReferenceException at ExpressionFormatter.cs:41

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Feb 12, 2024
@javiercn javiercn added this to the 8.0.x milestone Feb 12, 2024
@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label Mar 25, 2024
@sal-versij
Copy link
Author

Is there any update on the state for a fix of this issue?

@sgarnovsky
Copy link

Got stuck with the same issue.
Feel like it is like a feature (to limit using Editor w/o nesting), but there is no other way to handle it as all related to HtmlFieldPrefix code is internal.

See, a misprint is still here: https://github.com/dotnet/aspnetcore/blame/de68d4212113859604d9e57cf7d674b167a8a317/src/Components/Web/src/Forms/HtmlFieldPrefix.cs#L23

public HtmlFieldPrefix Combine(LambdaExpression other)
    {
        var restLength = _rest?.Length ?? 0;
        var length = restLength + 1;
        var expressions = new LambdaExpression[length];
        //for (var i = 0; i < restLength - 1; i++)
        for (var i = 0; i < **length** - 1; i++)
        {
            expressions[i] = _rest![i];
        }

        expressions[length - 1] = other;

        return new HtmlFieldPrefix(initial, expressions);
    }

A fix should be pretty easy, just use a "length - 1" in a for loop above.

How we can make to speed up applying a fix for this issue?

@sgarnovsky
Copy link

sgarnovsky commented Oct 25, 2024

.Net 9 RC still has this bug...
https://github.com/dotnet/aspnetcore/blob/v9.0.0-rc.2.24474.3/src/Components/Web/src/Forms/HtmlFieldPrefix.cs

This is frustrating... So a powerful feature but can't be used fully due to this simple issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug.
Projects
Status: 8.0.x
5 participants