Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a couple of Razor project issues #11645

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

DustinCampbell
Copy link
Member

@DustinCampbell DustinCampbell commented Mar 19, 2025

I was debugging through ProjectSnapshotManager and noticed a couple of issues:

  1. Documents won't be cleared from ProjectSnapshotManager's open documents on solution close.
  2. The algorithm to request tag helpers from OOP has some undesirable behavior. Essentially, any tag helpers that it had to fetch from OOP using checksums will be added to the end of the result. That can result in cases when the ProjectWorkspaceState is updated for a project with exactly the same tag helpers in a different order. This results in SequenceEquals(...) returning false when comparing old and new ProjectWorkspaceState and all of the documents being invalidated.

CI Build: https://dev.azure.com/dnceng/internal/_build/results?buildId=2668365&view=results
Test Insertion: https://dev.azure.com/devdiv/DevDiv/_git/VS/pullrequest/621080

It turns out that CloseDocument can easily fail resulting in IsDocumentOpen to report true for documents that are not actually open. This is because the _openDocumentSet is only updated after updating the project with a SourceText or TextLoader. For example, if the project has already been removed, CloseDocument wouldn't update the _openDocumentSet. This change updates _openDocumentSet before updating the document text, which should by more correct.
Retrieving TagHelperDescriptors from OOP is a two step process.

1. Call into OOP to get the checksum delta for tag helpers that are different from the last request.
2. If there are any checksums that aren't cached on the client-side, call into OOP to fetch them.

Unfortunately, the OutOfProcTagHelperResolver would always add any fetched tag helpers to the end of the array, effectively reordering them. Once ProjectState is updated with a ProjectWorkspaceState created with this set of tag helpers, they wouldn't equal the same tag helpers assigned by subsequent calls to OOP because SequenceEquals(...) wouldn't return true.
@DustinCampbell DustinCampbell requested a review from a team as a code owner March 19, 2025 22:20
Copy link
Member

@davidwengier davidwengier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That reordering thing is a very nice find! Probably caused a bunch of churn

With the current implementation, this should never happen. However, if something changes and *does* start happening, we'll log a warning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants