-
Notifications
You must be signed in to change notification settings - Fork 647
Conversation
/// <param name="textContent">Content for the new markup text frame.</param> | ||
public void AddMarkupContent(int sequence, string textContent) => | ||
// TODO stevesa implement me | ||
throw null; |
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.
ex dee
FYI the test failures are of course expected right now. The rendering tests and E2E tests throw because the If you rename the new method on |
9d21e23
to
61baf31
Compare
Thanks @rynowak! This looks perfect. I've rebased on master (hence the changes to the commit history here now) and will proceed with the runtime bits. |
Still to do:
|
OK all done now. @rynowak We should discuss the existence of the new |
/// <param name="value">The value for the new instance.</param> | ||
public MarkupString(string value) | ||
{ | ||
_value = value ?? string.Empty; |
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.
Why this? Is it ever meaningful to have null markup string?
For instance the following is true. ((MarkupString)null).ToString() == ""
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.
Good point.
I've now changed it so that MarkupString
can hold the value null
.
- If you
.ToString()
such an instance, you getstring.Empty
just like HtmlAbstractions'HtmlString
. - If you
renderTreeBuilder.AddContent
such an instance, it creates a markup frame whose value isstring.Empty
, just like if youAddContent((string)null)
.
So the net effect is that nulls continue to be treated like string.Empty
, but now it's possible to observe that null
was stored in the MarkupString
to avoid losing that info.
if (markupContent == null) | ||
{ | ||
throw new ArgumentNullException(nameof(markupContent)); | ||
} |
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.
Should we check non-null here? new MarkupContent(string)
is happy to accept null. IMO we should permit both or neither
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.
Good point. It now just null-coalesces with string.Empty
like we do for regular string
values.
// The JavaScript-side rendering code does not rely on this behavior. It supports | ||
// inserting markup frames with arbitrary markup (e.g., multiple top-level elements | ||
// or none). This test exists only as an observation of the current behavior rather | ||
// than a promise that we never want to change it. |
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.
Do you think it's desirable that we change this in the compiler? It would be straightforward to do.
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.
Perf-wise yes, the ideal would be for adjacent literal markup frames (and any adjacent literal text frames) to be coalesced.
If you think this is a simple addition that would be neat, but I think it’s also a good improvement as-is.
Note that we shouldn’t treat text literals as markup unless they are coalesced into a markup frame, because text nodes on their own are much cheaper to render than markup frames.
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.
Moved this to #1170
My assumption is that you wanted to avoid the allocation and the extra references. In particular I think WebEncoders is pretty heavy-weight - this is why I didn't suggest it from the beginning. |
|
Yes, avoiding unnecessary allocations was one reason, the other was that simply referencing |
… markup dynamically.
…eding custom RenderFragment code
2f49cc4
to
19bb950
Compare
* Add HTML Block rewriter * Baseline updates * test gaps * Update some unit tests to represent same behavior as before * Define Markup frame type. Tests for rendering markup frames into render tree. * Support markup frames during diffing (retain, insert, update, delete) * Support markup blocks on WebAssembly * Support rendering markup frames with server-side execution too * Support markup blocks with multiple top-level nodes. Support updating markup dynamically. * Define MarkupString type as a way to insert dynamic markup without needing custom RenderFragment code * Remove comment * CR: Better null value handling
/cc @SteveSandersonMS - handing this off for you to do the runtime piece.
Rewrites HTML-only subtrees of the IR in an HTML 'block' node with simple string content.
This will rely on new runtime/rendertree support in order to work E2E.