Allow developers to properly rename razor components in the editor
Description
Several different rename scenarios for razor components do not work reliably today in a solution that contains a razor component.
We are currently faced with some limitations on how we handle renames for razor components. The goal for this issue is to allow developers to properly rename razor components in the editor.
Examples
Use case 1: Simply rename component in a razor file
Arrange
- Create or open a Blazor Server App.
- Add a razor component into another razor document by drag/dropping one of the razor files (e.g.
Counter.razorintoIndex.razorfile). That should add a line<Counter\>toIndex.razorfile.
Act (rename)
- Rename the component by right-clicking over
<Counter/>on theIndex.razorfile.

Assert
:white_check_mark: This will successfully rename the Counter.razor filename accordingly.
Use case 2: Rename in a razor file, while there's references to it in other files (both in/out @{ } block)

Problems found:
-
:x: Renaming on a razor file only renames the component references outside the
@{ }block.
-
:x: The same rename action only renames the component references in the same file. It won't properly rename any component or C# references in the other razor files (regardless of them being opened or unopened files):

Use case 3: Rename the razor file from solution explorer back to Counter.razor
Problem found:
- :x: Does not update any razor component references, regardless if in or outside
@{ }block.
Use case 4: Rename one of the razor component references from inside a C# context

Problem found:

- :white_check_mark: All of the C# references get updated even in other files
- :x: But no component references outside of the
@{ }get updated - :x: Also, the razor file name itself does not get updated which means this action does not trigger component rename (which explains the squiggly under all the renamed items).
Use case 5: Rename a component that is defined as a partial class
Problems found:
- :x: Renaming via solution explorer (similar to use case 3), only renames the file itself, nothing else gets triggered
- :x: Renaming a component from outside
@{ }context (similar to use case 2), changes nothing. - :x: Renaming a component from inside
@{ }context, won't update any file names, and it won't update any component references outside the@{ }code block. The only thing it does it rename all C# references and the user-specified partial class definition will get updated, but nothing razor specific gets triggered.
Use case 6: Renaming a component from inside its own razor file just simply renames the files
(Reported in https://github.com/dotnet/razor/issues/4458 - I was only able to reproduce this with razor files under the shared folder not under the pages folder)
- [x] (Fixed in #8954)

Problems found:
-
:x: The files get renamed but the component reference in the file does not get renamed:

-
:x: If on line 5 we don't manually apply the rename before undoing name back to original name the error list below does not get cleared (not even with rebuild), unless we close and reopen VS entirely

This is a super fundamental and essential feature. I wonder why it does not have more resonance. Does no one renames components in their early stage? Are you not super annoyed when components are already referenced across code base and you simply cannot rename a component reliable? Do we also have to wait two years for this rename bug too similiar to https://github.com/dotnet/roslyn/issues/63181?
I would consider the Blazor coder base not small and when using Visual Studio Enterprise, I would expect that there is more incentive to not having a partial working product out there.
@teneko this is kind of a meta bug tracking multiple issues. I understand that rename is important. To help us prioritize, what specific issues are you hitting?
Related to https://github.com/dotnet/roslyn/issues/63181 I'm not sure what you mean by waiting for 2 years. While it has been a few years since I did the fix it looks like it was within a reasonable time.
I hit this constantly. I wonder if it's the same or worse between Visual Studio 2022 & VS Code. I thought maybe there's a "proper" way to rename a blazor component that doesn't miss instances.
I guess we'll still be using search & replace for the foreseeable future.