question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make component binding case-sensitive

See original GitHub issue

Summary

We’ve going to change component binding to be case-sensitive and add warnings for cases where you made an obvious mistake. We’ve treated all of these issues as conventions or recommendations thus far, but having components fail to bind usually results is really vexing compiler errors from C#

  • Make compiler bind components case-sensitively
  • Make completion of components and attributes case-sensitive (not the case today when an attribute has the same name a known HTML thing)
  • Add a diagnostic for components attempting to use lower case
  • Add a diagnostic for elements that start with a capital letter but don’t match a component

The problem

Suppose that you rename a component without renaming all of the usages (or suppose you change the namespace). If you were using event handlers with that component:

<MyButton OnClick="Clicked" Message="So enticing, you know you want to click!"/>
@code {
    void Clicked() {
        ...
    }
}

You now get a compile error that says something like Cannot convert method group Clicked to type System.Object.. This is because method-group-to-delegate-conversion doesn’t support object, but it’s fairly common with components.

You now miss the forest for the trees. You’re distracted from the root cause, which is that the MyButton tag didn’t resolve to a component.

Solution

We’ve had on the roadmap for a while to make binding case-sensitive. So this is not really a surprise.

The additional goal is to detect and warn in the case where a developer tries to reference a component, but no such component is found. Currently the behavior is to treat it as an HTML element, which is potentially very confusing.

To fix this, we want to turn the PascalCasing of component names into a stronger, built-in convention:

  1. If you try to compile a component whose name starts with a lowercase character in a-z, fail the compilation with an error (Component names cannot start with lowercase characters).

    • I don’t think we can do this as a suppressible warning, because where would you put the suppression?
    • I think this rule is correct internationally. We’re not stopping you from starting a component name with some non-Roman character, since that’s not ambiguous.
  2. Each time something in your .razor source resolves as an element (not a component), check that its name starts with a lowercase character in a-z. If we find an element whose first char isn’t in a-z case sensitively, emit a warning (Found markup element with unexpected name '{0}'. If this is intended to be a component, add a @using directive for its namespace.).

    • Again, I think this is right internationally, because all standard HTML element names do start with a character in a-z (case-insensitively), and will do probably forever.
  3. Allow the warning from (2) to be suppressed. See https://github.com/aspnet/AspNetCore/issues/9786#issuecomment-487223538

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
SteveSandersonMScommented, Jun 5, 2019

Does this also imply that a <Button> component won’t collide with HTML’s <button>?

Yes

4reactions
chuckercommented, May 26, 2019

To fix this, we want to turn the PascalCasing of component names into a stronger, built-in convention:

Does this also imply that a <Button> component won’t collide with HTML’s <button>?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make component binding case-sensitive · Issue #9860
Summary We've going to change component binding to be case-sensitive and add warnings for cases where you made an obvious mistake.
Read more >
ASP.NET Core Binding case sensitivity
You want to configure the serializer to use PropertyNameCaseInsensitive = false in order to be case-sensitive. You can configure the options in ...
Read more >
ASP.NET Core Blazor data binding
Learn about data binding features for Razor components and DOM elements in Blazor apps. ... Razor attribute binding is case-sensitive:.
Read more >
Session.CaseSensitive Property | eXpress Persistent Objects
The CaseSensitive property is in effect when evaluating string comparisons in: Sorting conditions specified for the XPCollection and XPView components (see ...
Read more >
Using case sensitivity with .NET objects
NET languages are generally case sensitive with respect to all names and identifiers used in the language. However, because ABL is generally not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found