BerserkerDotNet/CaptureRenderTagHelper

no-duplicate does not work in ASP.NET Core 7 app

Closed this issue · 3 comments

dhymik commented

no-duplicates does not work for me in a .Net Core 7 ASP.ENT app. The reason is that the GroupBy clause which removes the duplicates works on the attribute value, which is . This will give a seperate group for each attribute, even if the string value of the attribute value is the same.

Casting the attribute values to string inside of the group clauses fixes the problem. See pull request.

Note: The tests contained in the original solution all pass, but in my ASP.NET Core 7 app, the problem shows up.

#7

HI @dhymik , thank you for submitting the issue and sorry you run into the bug :(
I was trying to repro the issue by re-targeting existing samples to .NET 7 app, but de-duplication works fine in that case. Can you attach a sample repo project or at least share the capture/render code snippets? Looking at what actual values you have in the attributes might help me repo it.

dhymik commented

Hi @BerserkerDotNet, thank you for getting back to me, and for this very useful package!

I attached a screenshot from a debugging session which shows the actual values and types of the Attributes collection. May be this helps. As you can see, the attribute value comes as object (HtmlString). GroupBy by this type will result in no-duplicates not working. Casting it to string prior to GroupBy works.

CaptureRenderTagHelper_01

I tested various attribute values in code, this makes no difference to the result. I set it like this:

<style capture="MySectionName" id="Test">@backgroundImageMarkupData.BackgroundPositionStyleRule</style>

and render it like this:

<style render="MySectionName" auto-merge="true" no-duplicates="true" no-duplicate-source="id">
</style>

Thank you for the more detailed repro steps. Using them I was able to figure out what's wrong. You are right, attribute value is an HtmlString object. HtmlString is a class and does not provide custom equality implementation, therefore it is compare by reference. In my tests and sample, I was using a constant strings which would also yield compare correctly. I've changed the tests to use HtmlString and the testcases for duplicates immediately failed. I've accepted your change as it should be good enough to convert the value to a string.

I've published version 1.0.1 with the fix. Let me know if the issue is gone.