-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Models Builder: Make Models Builder better at not performing "rude edits" #20394
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
Conversation
It has not been generating virtual properties forever. If my memory serves me correctly, this was added by PR from @skttl The reason for this, was to make it easier to mock strongly typed models in unit tests. Before this change you had to mock the entire property on a underlying IPublishedContent. So it's a good thing it's configurable to have them generated. |
It wasn't me :) |
@skttl like I said...it was @Matthew-Wise :-) |
@dawoe fair enough 😆 the PR description has been appropriately amended 😛 |
@kjac are you taking feature requests for ModelsBuilder now? Would love some kind of config setting, that could make ModelsBuilder property values fall back to the fallback language. Also, make a list of constants containing all the property aliases. Right now we are doing this by implementing our own IModelsGenerator, which basically does some regex magic on the generated models files (as we don't want to reimplement everything) |
@skttl I hope we're always taking feature requests 😄 Raise it as a feature request in GitHub discussions? |
@skttl +1 for the property aliases. |
Of course I am the problem 😄. @kjac given this is targeting 17 so we can break things, I wonder if the setting should default to false. We don't see a lot of people writing test code and the virtual properties do have an over head, adding more configuration for people doing more advanced things feels better than those doing less. |
@Matthew-Wise I'm fine with changing the default. I think it should be done for 18, though, to keep from disrupting the LTS > LTS upgrade path unnecessarily. |
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.
Works great using both dotnet watch
and Visual Studio. 🙌
I'm having some issues with Hot Reload of views in Rider, but not sure if it's a Rider (or Rider in Mac) quirk.
@lauraneto I forgot to mention that 🙈 I too have issues with Hot Reload vs Razor template editng in Rider (on Windows). It works well with Notepad++ so I assume it's a Rider thing 😆 |
@kjac I was testing it further and it appears to also work in Rider, as long as you are not debugging. 🤷🏻♀️ |
Docs added in umbraco/UmbracoDocs#7477 |
Prerequisites
Description
In an effort to make Umbraco support 🔥 Hot Reload, the Models Builder models generation needs to change a little:
virtual
properties, as addingvirtual
members is an unsupported edit for Hot Reload.The first change is relatively simple; I have made Models Builder a bit more conscious about file deletions.
The second is harder. Models Builder has generated
virtual
propertiessince foreverfor the past five years, so simply removing that would be quite the breaking change.To work around this, I have introduced a new configuration option in the Models Builder settings. It's called
GenerateVirtualProperties
, and it's a boolean which defaults totrue
to retain backwards compatibility by default.Considerations
Adding yet another configuration option is not ideal. We have plenty of those 🙈
On the flip side, Umbraco is by default configured to generate in-memory models and use Razor Runtime Compilation, so one needs to jump through a fair few hoops to get to a point where Hot Reload can be used (see #20187 for details). An extra configuration is probably not the worst that can happen.
Testing this PR
It is likely best to test this PR using the NuGet packages generated by the build server.
Start by setting up a site without Razor Runtime Compilation (again, see #20187 for details), and configure Models Builder to:
SourceCodeManual
mode.GenerateVirtualProperties
set tofalse
).Start the site with
dotnet run
and build up a basic setup for testing - just a few pages and a template.Now restart the site using
dotnet watch
, and verify that Hot Reload allows for:Please note that you're likely to encounter this issue while testing. That's a problem with the .NET 10 runtime, not an Umbraco specific problem. If you run into that issue, you need to restart the site to continue testing.