Skip to content

Conversation

kjac
Copy link
Contributor

@kjac kjac commented Oct 7, 2025

Prerequisites

  • I have added steps to test this contribution in the description below

Description

In an effort to make Umbraco support 🔥 Hot Reload, the Models Builder models generation needs to change a little:

  1. It must not delete and recreate files. This constitutes a "rude edit" towards Hot Reload, which in turn requires an application restart.
  2. It must not generate virtual properties, as adding virtual 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 properties since forever for 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 to true 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:

  • Use the SourceCodeManual mode.
  • Generate non-virtual properties (GenerateVirtualProperties set to false).

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:

  • Adding new properties to a doctype and subsequently rendering them in the template.
  • Making other rendering changes to the template (i.e. changing the rendering of an existing property).

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.

@dawoe
Copy link
Contributor

dawoe commented Oct 7, 2025

@kjac

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.

@skttl
Copy link
Contributor

skttl commented Oct 7, 2025

It has not been generating virtual properties forever. If my memory serves me correctly, this was added by PR from @skttl

It wasn't me :)

@dawoe
Copy link
Contributor

dawoe commented Oct 7, 2025

@skttl like I said...it was @Matthew-Wise :-)

#9335

@kjac
Copy link
Contributor Author

kjac commented Oct 7, 2025

@dawoe fair enough 😆 the PR description has been appropriately amended 😛

@skttl
Copy link
Contributor

skttl commented Oct 7, 2025

@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)

@kjac
Copy link
Contributor Author

kjac commented Oct 7, 2025

@skttl I hope we're always taking feature requests 😄

Raise it as a feature request in GitHub discussions?

@dawoe
Copy link
Contributor

dawoe commented Oct 7, 2025

@skttl +1 for the property aliases.

@Matthew-Wise
Copy link
Contributor

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.

@kjac
Copy link
Contributor Author

kjac commented Oct 7, 2025

@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.

Copy link
Contributor

@lauraneto lauraneto left a 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.

@kjac
Copy link
Contributor Author

kjac commented Oct 7, 2025

@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 😆

@lauraneto
Copy link
Contributor

@kjac I was testing it further and it appears to also work in Rider, as long as you are not debugging. 🤷🏻‍♀️

@lauraneto lauraneto changed the title Make Models Builder better at not performing "rude edits" Models Builder: Make Models Builder better at not performing "rude edits" Oct 7, 2025
@lauraneto lauraneto merged commit ba4a874 into v17/dev Oct 7, 2025
25 of 26 checks passed
@lauraneto lauraneto deleted the v17/feature/hot-reload-for-models-builder branch October 7, 2025 10:47
@kjac
Copy link
Contributor Author

kjac commented Oct 7, 2025

Docs added in umbraco/UmbracoDocs#7477

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants