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

Component inheritance seems to be broken #48447

Closed
bfonde opened this issue May 26, 2023 · 4 comments
Closed

Component inheritance seems to be broken #48447

bfonde opened this issue May 26, 2023 · 4 comments
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue Status: No Recent Activity

Comments

@bfonde
Copy link

bfonde commented May 26, 2023

I am having problems with component inheritance after the latest VS update (17.6.1). For example:

Foo.razor:

@inherits Bar

<div id="fooDiv">
    <button id="@Id" class="@Class" type="submit">Submit</button>
</div>

Bar.razor:

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

The above doesn't actually render the component. It renders as:
<foo id="foo" class="btn btn-secondary"></foo>

When I take away the inheritance and put everything in Foo.razor it renders properly.

The inheritance also did not work when deployed to Windows Server 2019, but it did work in the local dev environment prior to the latest VS update.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label May 26, 2023
@javiercn javiercn added the Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue label May 26, 2023
@ghost
Copy link

ghost commented May 26, 2023

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimalistic repro project that illustrates the problem.

@ghost ghost added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label May 26, 2023
@Flachdachs
Copy link

I can reproduce the problem. Just create a project from standard template, e.g. blazorserver. Add the two files with the content from the opening posting to the Shared folder. Add <Foo Id="x" Class="y"/> to the file Pages/Index.razor. Build the project/solution. This gives you already a warning:

Index.razor(11, 1): [RZ10012] Found markup element with unexpected name 'Foo'.
If this is intended to be a component, add a @using directive for its namespace.

There is a @using directive for Shared in the global _Imports.razor. Adding a new one (to Index or Foo) creates another warning that it already exists. Foo is rendered as it is written in the Index.razor, not as the content of the component.


Add a Qux.cs with a content like so:

using Microsoft.AspNetCore.Components;
namespace BlazorApp1.Shared;
public class Qux : ComponentBase {
    [Parameter] public string? Id { get; set; }
    [Parameter] public string? Class { get; set; }
}

... and let Foo inherit from Qux, everything works fine.

@ScarletKuro
Copy link

I am having problems with component inheritance after the latest VS update (17.6.1). For example:
When I take away the inheritance and put everything in Foo.razor it renders properly.

The issues you referred to, along with the accompanying code snippet, point to the problem described here: #48281

Currently there is a regression in the new SDK version 7.0.302 that is documented here dotnet/razor#8718

To address the problems, it's recommended to pin the SDK version to 7.0.203 using the global.json file.

You can also find this information in the Visual Studio 17.6.1 release notes: https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes#17.6.1 in section "Known Issues"

@ghost
Copy link

ghost commented Jun 1, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Jun 5, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 5, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue Status: No Recent Activity
Projects
None yet
Development

No branches or pull requests

5 participants
@javiercn @ScarletKuro @bfonde @Flachdachs and others