1+ using Microsoft . Extensions . Logging ;
12using System . Reflection ;
23using System . Runtime . ExceptionServices ;
3- using Microsoft . Extensions . Logging ;
44
55namespace Bunit . Rendering ;
66
@@ -143,7 +143,7 @@ public Task DispatchEventAsync(
143143
144144 return result ;
145145 }
146- }
146+ }
147147
148148 /// <inheritdoc/>
149149 public IRenderedComponentBase < TComponent > FindComponent < TComponent > ( IRenderedFragmentBase parentComponent )
@@ -295,11 +295,19 @@ void LoadChangesIntoRenderEvent(int componentId)
295295 ref var frame = ref frames . Array [ i ] ;
296296 if ( frame . FrameType == RenderTreeFrameType . Component )
297297 {
298+ // If a child component of the current components has been
299+ // disposed, there is no reason to load the disposed components
300+ // render tree frames. This can also cause a stack overflow if
301+ // the current component was previously a child of the disposed
302+ // component (is that possible?)
298303 var childStatus = renderEvent . GetStatus ( frame . ComponentId ) ;
299304 if ( childStatus . Disposed )
300305 {
301306 logger . LogDisposedChildInRenderTreeFrame ( componentId , frame . ComponentId ) ;
302307 }
308+ // The assumption is that a component cannot be in multiple places at
309+ // once. However, in case this is not a correct assumption, this
310+ // ensures that a child components frames are only loaded once.
303311 else if ( ! renderEvent . GetStatus ( frame . ComponentId ) . FramesLoaded )
304312 {
305313 LoadChangesIntoRenderEvent ( frame . ComponentId ) ;
@@ -308,6 +316,10 @@ void LoadChangesIntoRenderEvent(int componentId)
308316 if ( childStatus . Rendered || childStatus . Changed || childStatus . Disposed )
309317 {
310318 status . Rendered = status . Rendered || childStatus . Rendered ;
319+
320+ // The current component should also be marked as changed if the child component is
321+ // either changed or disposed, as there is a good chance that the child component
322+ // contained markup which is no longer visible.
311323 status . Changed = status . Changed || childStatus . Changed || childStatus . Disposed ;
312324 }
313325 }
0 commit comments