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

Avoid transforming solution for Hot Reload when Razor's ForceRuntimeCodeGeneration feature flag is enabled #77221

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

Conversation

tmat
Copy link
Member

@tmat tmat commented Feb 14, 2025

Aims to avoid overhead of a separate solution snapshot used for Hot Reload and EnC.

The feature flag is checked at two locations:

  1. CompileTimeSolutionProvider, where we simply return the design time solution without updating it
  2. Global editorconfig option reader in project, where we need to override the value of editorconfig option build_property.SuppressRazorSourceGenerator if the feature flag is enabled. The option is set in an editorconfig file included to all Razor projects by Razor SDK and defaults to true. When the solution was transformed in CompileTimeSolutionProvider the editorconfig file was removed, which enabled the source generator. If the transformation is not performed the source generator would be disabled if we didn't override the option.
  3. Disable Razor's IDynamicFileInfoProvider

@tmat tmat requested a review from a team as a code owner February 14, 2025 04:08
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 14, 2025
@tmat
Copy link
Member Author

tmat commented Feb 14, 2025

@jasonmalinowski @davidwengier ptal

@tmat tmat changed the title Avoid forking solution for Hot Reload when Razor's ForceRuntimeCodeGeneration feature flag is enabled Avoid transforming solution for Hot Reload when Razor's ForceRuntimeCodeGeneration feature flag is enabled Feb 14, 2025

if (legacyOverrideSuppressRazorSourceGenerator)
{
entries = entries.SetItem("build_property.SuppressRazorSourceGenerator", "false");
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this bit. Why do we want to allow the generator to run if forceRuntimeCodeGen is on? Seems like that would break Razor IDE scenarios, because the IDE is going to provide C# via IDynamicFileInfoProvider, and the source generator will provide the same C#.

Copy link
Member Author

Choose a reason for hiding this comment

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

We need to run the source generator for Hot Reload. Do we need to disable IDynamicFileInfoProvider if forceRuntimeCodeGen then?

Copy link
Member

Choose a reason for hiding this comment

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

That would definitely break the IDE.

Maybe I'm missing context here, it this feels like the PR we would want for cohosting, once dotnet/razor#11412 is merged for example. That PR does indeed turn off IDynamicFilInfo in favour of the generator. Cohosting is a different feature flag though.

Force runtime code generation doesn't fundamentally change how Razor works in the IDE, it just makes the code generated look the same as what the source generator produces.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see, so we will need cohosting as well to make this work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants