Skip to content
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

Modify HtmlRenderer to update content when a component re-renders #40512

Merged
merged 2 commits into from
Mar 3, 2022

Conversation

pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Mar 3, 2022

Prior to this change HtmlRenderer would return a snapshot of a component immediately after it was initially rendered. This meant any updates to a component as a result of other components rendering were lost.

In this change, we update the HtmlRenderer to return a placeholder IHtmlContent that retrieves render frames only when WriteTo is invoked. Typically MVC will defer calling WriteTo until the content is about to be sent to the wire, which means any updates to a component (e.g. HeadOutlet being updated) are picked up.

Also updates the template to consolidate _Host and _Layout.

Fixes #38400

@pranavkm
Copy link
Contributor Author

pranavkm commented Mar 3, 2022

Need to test this with more cases (and in particular with whatever magical thing we're doing with select elements), but this worked for the Blazor Server sample.

@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented Mar 3, 2022

This is

image

Very nice! Especially with the removal of OnComponentRendered, this now looks so simple and natural. I guess it was always meant to be this way.

I'd approve this PR, but it's still in draft.

Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

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

Approving even though it's draft

@javiercn
Copy link
Member

javiercn commented Mar 3, 2022

Yeah, this is much nicer

@Pilchie Pilchie added the area-blazor Includes: Blazor, Razor Components label Mar 3, 2022
@pranavkm pranavkm marked this pull request as ready for review March 3, 2022 18:16
@pranavkm pranavkm requested review from a team and Pilchie as code owners March 3, 2022 18:16
@pranavkm pranavkm enabled auto-merge (squash) March 3, 2022 18:20
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate not requiring unintuitive requirements for pre-rendering PageTitle
4 participants