Skip to content

[release/7.0] Hot reload: Acknowledge Blazor component parameter removal #43418

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

Merged
merged 1 commit into from
Sep 2, 2022

Conversation

MackinnonBuck
Copy link
Member

@MackinnonBuck MackinnonBuck commented Aug 20, 2022

[release/7.0] Hot reload: Acknowledge Blazor component parameter removal

If a parameter value was removed from a component during a hot reload edit, the component would retain the previously-supplied value. This PR fixes the issue by reinstantiating a component when a hot reload edit removes one of its parameters.

Description

One approach to solving this bug could be to directly default-out all parameter properties before applying the new set of parameter values. The main problem with that is any custom construction logic initializing properties to their default values will be skipped. This can be fine in some cases, but even some of our E2E test pages would throw exceptions or break in other ways when any hot reload change was applied using this approach.

Thus, with the changes in this PR, a component will get completely disposed and reinstantiated when a component parameter removal is detected during hot reload. This allows the component's construction logic to correctly reset parameter property values.

Fixes #31272

Customer Impact

Certain types of code edits require the customer to either rebuild their project or refresh the webpage in order for the changes to be applied. Expanding the range of edits that a customer can make to their code without requiring manual refreshing/rebuilding makes Hot Reload a larger productivity booster. Supporting the live removal of Blazor component parameters is a step in that direction.

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

This PR adds a single additional code path to the rendering logic, and it only applies for hot reload scenarios. New automated tests have been added for the logic determining when that new code path should be taken (i.e., detecting when component parameters have been removed).

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@MackinnonBuck MackinnonBuck added area-blazor Includes: Blazor, Razor Components feature-hot-reload This issue is related to the Hot Reload feaature labels Aug 20, 2022
@MackinnonBuck MackinnonBuck requested a review from a team as a code owner August 20, 2022 00:02
@MackinnonBuck MackinnonBuck changed the base branch from main to release/7.0 August 20, 2022 00:04
@MackinnonBuck MackinnonBuck changed the title Hot reload: Acknowledge Blazor component parameter removal [release/7.0] Hot reload: Acknowledge Blazor component parameter removal Aug 20, 2022
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.

Looks great so far, I have a minor question, but that's it.

@SteveSandersonMS
Copy link
Member

The overall approach here looks good to me 👍

@SteveSandersonMS SteveSandersonMS self-requested a review September 2, 2022 11:05
@MackinnonBuck
Copy link
Member Author

@Pilchie Would you be able to take a look at this? It's ready to be merged.

@Pilchie
Copy link
Member

Pilchie commented Sep 2, 2022

Approved for .NET 7 RC2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components feature-hot-reload This issue is related to the Hot Reload feaature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Components don't reset their received parameters during hot reload updates
4 participants