-
Notifications
You must be signed in to change notification settings - Fork 225
Dedupe metadata in tag helpers #8782
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, and tooling side looks good.
Would be interesting to see how many PropertyName metadata items share the same names, in a real app. I suspect there would be a lot of common attribute descriptors (Value, Items, Title etc.), it might be worth using a dictionary to share KVP instances.
It might be useful to intern the strings, but KVPs are structs, so they can't exactly be shared. FWIW, the biggest offenders were the many RequiredAttributeDescriptors with identical "IsDirectiveAttribute" metadata. |
6bef35d to
280c6a1
Compare
chsienki
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @333fred Have we decided if we're doing API review for Razor too?
src/Compiler/Microsoft.AspNetCore.Razor.Language/src/CommonMetadata.cs
Outdated
Show resolved
Hide resolved
I don't want to put words in his mouth, but @333fred and I chatted about this the other day, and I believe the conclusion was that we have to review the whole thing eventually. However, we don't need to do that yet. He'll correct me if I got that wrong. FWIW, I made these public to avoid having to add InternalsVisibleTo for the MVC Extensions projects, which I think we don't want. |
jaredpar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got most of the way through the change. Reviewed the core implementation changes and probably half the test cases. Had a few Qs. Will pick up rest of the review later today
src/Compiler/Microsoft.AspNetCore.Razor.Language/src/BoundAttributeDescriptorBuilder.cs
Outdated
Show resolved
Hide resolved
...Compiler/Microsoft.AspNetCore.Razor.Language/src/BoundAttributeParameterDescriptorBuilder.cs
Outdated
Show resolved
Hide resolved
| internal static class TagHelperBoundAttributeDescriptorExtensions | ||
| { | ||
| private static bool IsTrue(this BoundAttributeDescriptor attribute, string key) | ||
| => attribute.Metadata.TryGetValue(key, out var value) && value == bool.TrueString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR effectively repeats a number of helpers between BoundAttributeDescriptor and BoundAttributeDescriptorBuilder. Did you consider using an interface for these common methods so we could have a single IsTrue, SetMetadata, etc ... methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't consider that, no. There are loads of these helper extension methods (mostly public) all over the place, so I decided to just follow that pattern. When we can finally change the public surface area of tag helper descriptors, I want to revisit all of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, providing an interface wouldn't give us a single copy of the methods. We would have to copy the implementations to each builder type because there's no hierarchy relationship between them.
src/Compiler/Microsoft.AspNetCore.Razor.Language/src/MetadataCollection.Enumerator.cs
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/src/RequiredAttributeDescriptorBuilder.cs
Outdated
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/src/TagHelperDescriptorBuilder.cs
Outdated
Show resolved
Hide resolved
...r/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/Completion/TagHelperServiceTestBase.cs
Show resolved
Hide resolved
...e.Razor.LanguageServer.Test/DocumentPresentation/TextDocumentUriPresentationEndpointTests.cs
Outdated
Show resolved
Hide resolved
...pNetCore.Mvc.Razor.Extensions.Version1_X/test/ViewComponentTagHelperDescriptorFactoryTest.cs
Show resolved
Hide resolved
|
Nope, you're right. I do owe you a review on this that I've started, and will try to get through the rest of today. |
src/Compiler/Microsoft.AspNetCore.Razor.Language/test/BoundAttributeDescriptorExtensionsTest.cs
Outdated
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/test/BoundAttributeDescriptorExtensionsTest.cs
Outdated
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/test/BoundAttributeDescriptorExtensionsTest.cs
Outdated
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/test/BoundAttributeDescriptorExtensionsTest.cs
Outdated
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/test/BoundAttributeDescriptorExtensionsTest.cs
Outdated
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/test/BoundAttributeDescriptorExtensionsTest.cs
Outdated
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/test/BoundAttributeDescriptorExtensionsTest.cs
Outdated
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/test/BoundAttributeDescriptorExtensionsTest.cs
Outdated
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/test/BoundAttributeDescriptorExtensionsTest.cs
Outdated
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/test/BoundAttributeDescriptorExtensionsTest.cs
Outdated
Show resolved
Hide resolved
333fred
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finished review of the compiler layer. Overall looking good, just a few minor questions.
src/Compiler/Microsoft.AspNetCore.Razor.Language/src/TagHelperDescriptorBuilderExtensions.cs
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/src/Resources.resx
Outdated
Show resolved
Hide resolved
...iler/Microsoft.AspNetCore.Razor.Language/src/RequiredAttributeDescriptorBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/src/MetadataHolder.cs
Outdated
Show resolved
Hide resolved
src/Compiler/Microsoft.AspNetCore.Razor.Language/src/DefaultTagHelperDescriptorBuilder.cs
Show resolved
Hide resolved
280c6a1 to
a8c6fe3
Compare
This change provides an alternative API to add metadata to tag helper builder objects. The existing API allows key/value pairs to be added to an
IDictionary<string, string?>, which is then converted to aMetadataCollection. The new API simply takes aMetadataCollectiondirectly, which allows common instances to be shared across tag helpers.A couple of notes: