Skip to content

Commit 208aeda

Browse files
Handle another case in temporary API
1 parent ad6d845 commit 208aeda

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/Components/Components/src/Rendering/RenderTreeBuilder.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public sealed class RenderTreeBuilder : IDisposable
4545
/// <param name="elementName">A value representing the type of the element.</param>
4646
public void OpenElement(int sequence, string elementName)
4747
{
48+
CompletePendingNamedSubmitEvent();
49+
4850
// We are entering a new scope, since we track the "duplicate attributes" per
4951
// element/component we might need to clean them up now.
5052
if (_hasSeenAddMultipleAttributes)
@@ -64,11 +66,7 @@ public void OpenElement(int sequence, string elementName)
6466
/// </summary>
6567
public void CloseElement()
6668
{
67-
if (_pendingNamedSubmitEvent is { } pendingNamedSubmitEvent)
68-
{
69-
AddNamedEvent(pendingNamedSubmitEvent.Sequence, "onsubmit", pendingNamedSubmitEvent.AssignedName);
70-
_pendingNamedSubmitEvent = default;
71-
}
69+
CompletePendingNamedSubmitEvent();
7270

7371
var indexOfEntryBeingClosed = _openElementIndices.Pop();
7472

@@ -82,6 +80,16 @@ public void CloseElement()
8280
_entries.Buffer[indexOfEntryBeingClosed].ElementSubtreeLengthField = _entries.Count - indexOfEntryBeingClosed;
8381
}
8482

83+
// TODO: Remove this once Razor supports @onsubmit:name
84+
private void CompletePendingNamedSubmitEvent()
85+
{
86+
if (_pendingNamedSubmitEvent is { } pendingNamedSubmitEvent)
87+
{
88+
AddNamedEvent(pendingNamedSubmitEvent.Sequence, "onsubmit", pendingNamedSubmitEvent.AssignedName);
89+
_pendingNamedSubmitEvent = default;
90+
}
91+
}
92+
8593
/// <summary>
8694
/// Appends a frame representing markup content.
8795
/// </summary>
@@ -592,6 +600,8 @@ public void SetKey(object? value)
592600

593601
private void OpenComponentUnchecked(int sequence, [DynamicallyAccessedMembers(Component)] Type componentType)
594602
{
603+
CompletePendingNamedSubmitEvent();
604+
595605
// We are entering a new scope, since we track the "duplicate attributes" per
596606
// element/component we might need to clean them up now.
597607
if (_hasSeenAddMultipleAttributes)

src/Components/Components/test/Rendering/RenderTreeBuilderTest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,15 +2300,18 @@ public void TemporaryApiForNamedSubmitEventsWorksEvenIfAttributesAddedAfter()
23002300
builder.AddAttribute(1, "attr1", 123);
23012301
builder.AddAttribute(2, "@onsubmit:name", "some custom name");
23022302
builder.AddAttribute(3, "attr2", 456);
2303+
builder.OpenElement(4, "other");
2304+
builder.CloseElement();
23032305
builder.CloseElement();
23042306

23052307
// Assert
23062308
Assert.Collection(
23072309
builder.GetFrames().AsEnumerable(),
2308-
frame => AssertFrame.Element(frame, "div", 4, 0),
2310+
frame => AssertFrame.Element(frame, "div", 5, 0),
23092311
frame => AssertFrame.Attribute(frame, "attr1", "123", 1),
23102312
frame => AssertFrame.Attribute(frame, "attr2", "456", 3),
2311-
frame => AssertFrame.NamedEvent(frame, "onsubmit", "some custom name", 2));
2313+
frame => AssertFrame.NamedEvent(frame, "onsubmit", "some custom name", 2),
2314+
frame => AssertFrame.Element(frame, "other", 1));
23122315
}
23132316

23142317
private class TestComponent : IComponent

0 commit comments

Comments
 (0)