1+ using Microsoft . Extensions . Logging ;
12using System . Reflection ;
23using System . Runtime . ExceptionServices ;
3- using Microsoft . Extensions . Logging ;
44
55namespace Bunit . Rendering ;
66
@@ -133,7 +133,7 @@ public Task DispatchEventAsync(
133133
134134 return result ;
135135 }
136- }
136+ }
137137
138138 /// <inheritdoc/>
139139 public IRenderedComponentBase < TComponent > FindComponent < TComponent > ( IRenderedFragmentBase parentComponent )
@@ -285,11 +285,19 @@ void LoadChangesIntoRenderEvent(int componentId)
285285 ref var frame = ref frames . Array [ i ] ;
286286 if ( frame . FrameType == RenderTreeFrameType . Component )
287287 {
288+ // If a child component of the current components has been
289+ // disposed, there is no reason to load the disposed components
290+ // render tree frames. This can also cause a stack overflow if
291+ // the current component was previously a child of the disposed
292+ // component (is that possible?)
288293 var childStatus = renderEvent . GetStatus ( frame . ComponentId ) ;
289294 if ( childStatus . Disposed )
290295 {
291296 logger . LogDisposedChildInRenderTreeFrame ( componentId , frame . ComponentId ) ;
292297 }
298+ // The assumption is that a component cannot be in multiple places at
299+ // once. However, in case this is not a correct assumption, this
300+ // ensures that a child components frames are only loaded once.
293301 else if ( ! renderEvent . GetStatus ( frame . ComponentId ) . FramesLoaded )
294302 {
295303 LoadChangesIntoRenderEvent ( frame . ComponentId ) ;
@@ -298,6 +306,10 @@ void LoadChangesIntoRenderEvent(int componentId)
298306 if ( childStatus . Rendered || childStatus . Changed || childStatus . Disposed )
299307 {
300308 status . Rendered = status . Rendered || childStatus . Rendered ;
309+
310+ // The current component should also be marked as changed if the child component is
311+ // either changed or disposed, as there is a good chance that the child component
312+ // contained markup which is no longer visible.
301313 status . Changed = status . Changed || childStatus . Changed || childStatus . Disposed ;
302314 }
303315 }
0 commit comments