dotnet / dotnet/roslyn

Tag Helper Rewriting is brittle

Open
#85,534 4 comments 1 reaction 0 assignees View on GitHub
Area-Razor Area-Razor-Compiler
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

As demonstrated in https://github.com/dotnet/razor/issues/10186 (numerous examples) and https://github.com/dotnet/razor/issues/10426, the tag helper attribute value rewriting portion of the razor compiler is very brittle. This is actually a long-standing issue that was more broadly spotlighted by our changes to runtime code generation to make it more specific; there are several examples of attribute values that have been broken for many years. This is due to how tag helper attribute value parsing works: the attributes are interpreted as HTML at first. Then, if the tag is determined to be a tag helper, rather than a pure HTML tag, and if the attribute is mapped to a property of that tag helper, we reinterpret the provided attribute value as if it was implicit C# expression. Unfortunately, this is not really possible to do without reparsing the _entire_ rest of the document, which the Razor compiler does not do; further, it would be a major performance regression if we attempted to do so. Here are a few examples of where this has been broken for several major versions:

```razor
am I a string value?"' />

```

The main purpose of this issue is try and figure out how far we want to go in fixing these bugs, vs simply documenting them as errata and leaving them unfixed. The last of these examples seems like it will be fixable without much trouble, but the first two would require major rework of the rewriter and downstream processing stages to work. Thoughts and opinions are welcome.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.