-
Notifications
You must be signed in to change notification settings - Fork 191
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
Make duplicate attribute names an error #604
Conversation
/cc @SteveSandersonMS @danroth27 any objections? |
This looks great to me. Following the conversation on #10357, could we go further and treat explicit duplicates as errors on components and non-markup elements too? |
I think that's probably the direction we're headed in. I can also do something SUPER DOPE and make it so that |
527601a
to
684e8ac
Compare
@ajaybhargavb @NTaylorMullen - can you take a look? |
src/Razor/src/Microsoft.AspNetCore.Razor.Language/Components/ComponentDiagnosticFactory.cs
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.Language/Components/ComponentDiagnosticFactory.cs
Show resolved
Hide resolved
This came up in the context of disucssion around #5071. Browsers use a 'first attribute wins' rule for evaluating attributes and building the DOM - though duplicate attributes are considered to be a spec violation. Blazor wants to use 'last attribute wins' rules because that's most sensible when you consider evaluation order and splatting. This means that we have to have the markup block pass do the same thing as the Blazor runtime when duplicates appear. However, since this is a spec violation I'm proposing that we just make it an error (like we do for malformed tags). There's no useful purpose for duplicate attributes since browsers ignore it. Since we're not going to allow this for elements. Let's go all of the way and block it for components as well. And while we're here, lets block some of the invalid cases where users try to mix onchange and bind. These don't work today, so we should make them an error. If we decide to add support for this case to the runtime that would require compiler work anyway.
684e8ac
to
bfaffaf
Compare
.../Microsoft.AspNetCore.Razor.Language/Components/ComponentDuplicateAttributeDiagnosticPass.cs
Outdated
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.Language/Components/ComponentDiagnosticFactory.cs
Show resolved
Hide resolved
src/Razor/src/Microsoft.AspNetCore.Razor.Language/Components/ComponentBindLoweringPass.cs
Outdated
Show resolved
Hide resolved
src/Razor/test/RazorLanguage.Test/Components/ComponentDuplicateAttributeDiagnosticPassTest.cs
Show resolved
Hide resolved
No, I'm referring to the <MyComponent Message="" /> This error message is explaining that both |
@aspnet/build - this guy looks like the PR validation is stuck. |
@natemcmaster - want to hit the like button on this PR for me? |
Thanks 👍 |
This came up in the context of discussion around aspnet/AspNetCoredotnet/aspnetcore-tooling#5071. Browsers use a 'first attribute wins' rule for evaluating attributes and building the DOM - though duplicate attributes are considered to be a spec violation. Blazor wants to use 'last attribute wins' rules because that's most sensible when you consider evaluation order and splatting. This means that we have to have the markup block pass do the same thing as the Blazor runtime when duplicates appear. However, since this is a spec violation I'm proposing that we just make it an error (like we do for malformed tags). There's no useful purpose for duplicate attributes since browsers ignore it. Since we're not going to allow this for elements. Let's go all of the way and block it for components as well. And while we're here, lets block some of the invalid cases where users try to mix onchange and bind. These don't work today, so we should make them an error. If we decide to add support for this case to the runtime that would require compiler work anyway. \n\nCommit migrated from dotnet/razor@0c59ca5
This came up in the context of discussion around aspnet/AspNetCoredotnet/aspnetcore-tooling#5071. Browsers use a 'first attribute wins' rule for evaluating attributes and building the DOM - though duplicate attributes are considered to be a spec violation. Blazor wants to use 'last attribute wins' rules because that's most sensible when you consider evaluation order and splatting. This means that we have to have the markup block pass do the same thing as the Blazor runtime when duplicates appear. However, since this is a spec violation I'm proposing that we just make it an error (like we do for malformed tags). There's no useful purpose for duplicate attributes since browsers ignore it. Since we're not going to allow this for elements. Let's go all of the way and block it for components as well. And while we're here, lets block some of the invalid cases where users try to mix onchange and bind. These don't work today, so we should make them an error. If we decide to add support for this case to the runtime that would require compiler work anyway. \n\nCommit migrated from dotnet/razor@0c59ca5 Commit migrated from dotnet/aspnetcore@95bb698c5a5d
This came up in the context of discussion around #dotnet/aspnetcore#5071.
Browsers use a 'first attribute wins' rule for evaluating attributes and
building the DOM - though duplicate attributes are considered to be a
spec violation.
Blazor wants to use 'last attribute wins' rules when dynamically building the attribute list because that's most sensible when you consider evaluation order and splatting.
This means that we have to have the markup block pass do the same thing
as the Blazor runtime when duplicates appear statically.............. OR since this is a
spec violation I'm proposing that we just make it an error (like we do
for malformed tags). There's no useful purpose for duplicate attributes
since browsers ignore it.