razor
razor copied to clipboard
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
