-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Support reloadable cshtml #35017
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
Support reloadable cshtml #35017
Conversation
src/Mvc/Mvc.Razor/src/ApplicationParts/RazorCompiledItemFeatureProvider.cs
Show resolved
Hide resolved
src/Mvc/Mvc.Razor/src/ApplicationParts/RazorCompiledItemFeatureProvider.cs
Outdated
Show resolved
Hide resolved
f5a3e5d to
48f3ddc
Compare
| foreach (var type in types) | ||
| { | ||
| // The Razor file has a [RazorCompiledItemMetadata("Identifier", "/Index.cshtml")]. We'll look it up. | ||
| var metadataAttribute = type.GetCustomAttributes<RazorCompiledItemMetadataAttribute>() |
There was a problem hiding this comment.
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.
| ITagHelperFactory tagHelperFactory, | ||
| IViewCompilerProvider viewCompilerProvider, | ||
| ITagHelperComponentPropertyActivator tagHelperComponentPropertyActivator, | ||
| ApplicationPartManager applicationPartManager) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)
javiercn
left a comment
There was a problem hiding this 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!
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
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
#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
#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
CreateNewOnMetadataUpdateAttributewhen targeting RazorLangVersion = 6.0Fixes #34248