Skip to content

Conversation

@pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Aug 3, 2021

  • Annotate cshtml files with CreateNewOnMetadataUpdateAttribute when targeting RazorLangVersion = 6.0
  • Additionally annotate cshtml files with an attribute that identifies the path (identifier)
  • Update RazorCompiledItemFeatureProvider to substitute a compiled type with a hot reloaded type
  • Clear more Razor specific caches as part of a hot reload event

Fixes #34248

@pranavkm pranavkm requested review from a team, Pilchie and javiercn as code owners August 3, 2021 22:13
@pranavkm pranavkm requested a review from davidfowl August 4, 2021 00:01
@mkArtakMSFT mkArtakMSFT added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Aug 4, 2021
@pranavkm pranavkm force-pushed the prkrishn/reloadable-type branch from f5a3e5d to 48f3ddc Compare August 4, 2021 23:07
foreach (var type in types)
{
// The Razor file has a [RazorCompiledItemMetadata("Identifier", "/Index.cshtml")]. We'll look it up.
var metadataAttribute = type.GetCustomAttributes<RazorCompiledItemMetadataAttribute>()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out there was already a type-level attribute in Razor.Hosting that we could use. It's slightly stringly typed (you have to look up an attribute by name), but we already do this when looking up routing metadata in Razor Pages.

@pranavkm pranavkm requested a review from a team August 5, 2021 13:40
ITagHelperFactory tagHelperFactory,
IViewCompilerProvider viewCompilerProvider,
ITagHelperComponentPropertyActivator tagHelperComponentPropertyActivator,
ApplicationPartManager applicationPartManager)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to do anything for page action descriptors? (I imagine at some point the endpoints need to be recalculated)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The CompiledPageActionDescriptorProvider uses the ApplicationPart feature to get the set of Razor Pages - https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.RazorPages/src/Infrastructure/CompiledPageActionDescriptorProvider.cs#L56-L61. It's a fairly similar code path to how the RazorViewEngine calculates it's inputs. We update that as part of this type, and poke the IActionDescriptorChangeProvider as part of HotReloadService, so it causes Razor Pages and it's routing to be rediscovered.

It might be worthwhile to create a fake provider and simulate this e2e given how many moving parts there are to this. I'd be happy to do that in a follow up (just getting the runtime changes in since it's a major hassle to sync across dotnet/aspnetcore, dotnet/sdk, and dotnet/roslyn to test these changes out)

Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

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

Couple of small questions, but other than that looks great!

@pranavkm pranavkm merged commit e30d3c5 into main Aug 5, 2021
@pranavkm pranavkm deleted the prkrishn/reloadable-type branch August 5, 2021 16:13
@ghost ghost added this to the 6.0-rc1 milestone Aug 5, 2021
pranavkm added a commit that referenced this pull request Sep 27, 2021
As part of #35017, I had consolidated the DefaultViewCompiler and DefaultViewCompilerProvider
types, largely as a clean up. The type DefaultViewCompilerProvider is looked up by the RuntimeCompilation package by name, and when making
this change, this code was also updated.

However, we've had two reports so far of users trying to use an 5.0 or earlier version of the runtime compilation package with a 6.0 app. In this case, the lookup
fails and the runtime compilation feature doesn't work as expected after this.

Fixes #35267
pranavkm added a commit that referenced this pull request Sep 27, 2021
As part of #35017, I had consolidated the DefaultViewCompiler and DefaultViewCompilerProvider
types, largely as a clean up. The type DefaultViewCompilerProvider is looked up by the RuntimeCompilation package by name, and when making
this change, this code was also updated.

However, we've had two reports so far of users trying to use an 5.0 or earlier version of the runtime compilation package with a 6.0 app. In this case, the lookup
fails and the runtime compilation feature doesn't work as expected after this.

Fixes #35267
pranavkm added a commit that referenced this pull request Sep 27, 2021
#37035)

As part of #35017, I had consolidated the DefaultViewCompiler and DefaultViewCompilerProvider
types, largely as a clean up. The type DefaultViewCompilerProvider is looked up by the RuntimeCompilation package by name, and when making
this change, this code was also updated.

However, we've had two reports so far of users trying to use an 5.0 or earlier version of the runtime compilation package with a 6.0 app. In this case, the lookup
fails and the runtime compilation feature doesn't work as expected after this.

Fixes #35267
captainsafia pushed a commit that referenced this pull request Sep 29, 2021
#37037)

As part of #35017, I had consolidated the DefaultViewCompiler and DefaultViewCompilerProvider
types, largely as a clean up. The type DefaultViewCompilerProvider is looked up by the RuntimeCompilation package by name, and when making
this change, this code was also updated.

However, we've had two reports so far of users trying to use an 5.0 or earlier version of the runtime compilation package with a 6.0 app. In this case, the lookup
fails and the runtime compilation feature doesn't work as expected after this.

Fixes #35267
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Makes razor views (.cshtml) files reloadable

6 participants