Preserve TagHelper child content when appending output content#67087
Open
Wezylnia wants to merge 1 commit into
Open
Preserve TagHelper child content when appending output content#67087Wezylnia wants to merge 1 commit into
Wezylnia wants to merge 1 commit into
Conversation
Contributor
|
Thanks for your PR, @Wezylnia. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR changes TagHelperOutput.Content to surface existing child content via a new wrapper that avoids marking content as modified on read, and adds tests to validate the new semantics.
Changes:
- Update
TagHelperOutput.Contentto initialize fromGetChildContentAsync()via a newTagHelperOutputContentwrapper. - Adjust
Reinitialize/SuppressOutputbehavior around_contentlifecycle. - Add unit tests covering
Contentread/append/set/suppress/reinitialize scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Razor/Razor/test/TagHelpers/TagHelperOutputTest.cs | Adds tests validating new Content behavior (append/read/set/suppress/reinitialize). |
| src/Razor/Razor/src/TagHelpers/TagHelperOutput.cs | Changes Content initialization and introduces TagHelperOutputContent wrapper to track modifications and preserve initial child content. |
Comments suppressed due to low confidence (1)
src/Razor/Razor/src/TagHelpers/TagHelperOutput.cs:110
Contentnow eagerly blocks onGetChildContentAsync()viaGetAwaiter().GetResult(). This is sync-over-async and also forces child-content evaluation even when callers only intend to overwrite content (e.g.,output.Content.SetContent(...)), which can introduce unnecessary work and potential deadlocks in environments with a synchronization context. Consider making the child-content retrieval lazy insideTagHelperOutputContent(store theTask/factory and only block when the initial content is actually needed for reading or for append-merge), soSetContent/Clearcan avoid evaluating child content entirely.
public TagHelperContent Content
{
get
{
if (_content == null)
{
_content = new TagHelperOutputContent(GetChildContentAsync().GetAwaiter().GetResult());
}
return _content;
}
Comment on lines
+446
to
+457
| public override bool IsEmptyOrWhiteSpace | ||
| { | ||
| get | ||
| { | ||
| if (_isModified || _initialContent == null) | ||
| { | ||
| return _content.IsEmptyOrWhiteSpace; | ||
| } | ||
|
|
||
| return new DefaultTagHelperContent().SetHtmlContent(_initialContent).IsEmptyOrWhiteSpace; | ||
| } | ||
| } |
Comment on lines
+568
to
+575
| private void EnsureInitialContent() | ||
| { | ||
| if (!_isModified && _initialContent != null) | ||
| { | ||
| _content.AppendHtml(_initialContent); | ||
| _initialContent = null; | ||
| } | ||
| } |
Author
|
@dotnet-policy-service agree |
3e921f3 to
e897165
Compare
Open
3 tasks
e897165 to
99552ea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #29835
Summary
TagHelperOutput.Contentfrom cached child content soAppendHtmlappends instead of replacing unmaterialized child markupContentreads from marking content as modifiedSetContent/SetHtmlContent, suppress output behavior, and reinitialization reuseTagHelperOutputregression testsTesting
restore.cmd;dotnet testwith the installed .NET 10 SDK reaches MSBuild but fails on missingartifacts/bin/GenerateFiles/Directory.Build.props.