Skip to content

Commit 4cb7458

Browse files
committed
fix: remove capture and dispatch to user sync context
1 parent fd85b8d commit 4cb7458

1 file changed

Lines changed: 1 addition & 27 deletions

File tree

src/bunit.core/Rendering/TestRenderer.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class TestRenderer : Renderer, ITestRenderer
1515
private static readonly MethodInfo GetRequiredComponentStateMethod = RendererType.GetMethod("GetRequiredComponentState", BindingFlags.Instance | BindingFlags.NonPublic)!;
1616

1717
private readonly object renderTreeUpdateLock = new();
18-
private readonly SynchronizationContext? usersSyncContext = SynchronizationContext.Current;
1918
private readonly Dictionary<int, IRenderedFragmentBase> renderedComponents = new();
2019
private readonly List<RootComponent> rootComponents = new();
2120
private readonly ILogger<TestRenderer> logger;
@@ -264,7 +263,7 @@ protected override Task UpdateDisplayAsync(in RenderBatch renderBatch)
264263
{
265264
var renderEvent = new RenderEvent();
266265
PrepareRenderEvent(renderBatch);
267-
InvokeApplyRenderEvent();
266+
ApplyRenderEvent(renderEvent);
268267

269268
return Task.CompletedTask;
270269

@@ -332,31 +331,6 @@ void LoadChangesIntoRenderEvent(int componentId)
332331
}
333332
}
334333
}
335-
336-
void InvokeApplyRenderEvent()
337-
{
338-
if (usersSyncContext is not null && usersSyncContext != SynchronizationContext.Current)
339-
{
340-
// The users' sync context, typically one established by
341-
// xUnit or another testing framework is used to update any
342-
// rendered fragments/dom trees and trigger WaitForX handlers.
343-
// This ensures that changes to DOM observed inside a WaitForX handler
344-
// will also be visible outside a WaitForX handler, since
345-
// they will be running in the same sync context. The theory is that
346-
// this should mitigate the issues where Blazor's dispatcher/thread is used
347-
// to verify an assertion inside a WaitForX handler, and another thread is
348-
// used again to access the DOM/repeat the assertion, where the change
349-
// may not be visible yet (another theory about why that may happen is different
350-
// CPU cache updates not happening immediately).
351-
//
352-
// There is no guarantee a caller/test framework has set a sync context.
353-
usersSyncContext.Send(_ => ApplyRenderEvent(renderEvent), null);
354-
}
355-
else
356-
{
357-
ApplyRenderEvent(renderEvent);
358-
}
359-
}
360334
}
361335

362336
private void ApplyRenderEvent(RenderEvent renderEvent)

0 commit comments

Comments
 (0)