Issue Context
I have a blazor component to wrap bootstrap modal with some basic binding.
I have two components that wrap EditForm
components that I expose via this modal component: ConversionForm.razor and ConversionInputForm.razor.
I then use these two form/modal components on a page with some simple buttons (not using bootstrap modal data binding).
Issue
Add Conversion Input
button causes the modal to appear and works properly. The Add Conversion
button causes the modal to appears then disappears and leaves the modal backdrop.
Troubleshooting
I added a Console.WriteLine
to the OnAfterRenderAsync of the modal component to see if there is a difference and the only one I noticed is that the conversion-modal.OnAfterRenderAsync(True)
is rendered after the modal.ShowAsync
method on the one that disappears.
I'm wondering if there is something about the binding behavior that is causing that behavior as I believe the firstRender=true should only happen once during initial load of the page of the component.
To replicate this behavior, create a new blazorserver app dotnet new blazorserver
and add/modify the files in this gist.
The console output for what works:
conversion-modal.OnAfterRenderAsync(True) [1]
conversion-input-modal.OnAfterRenderAsync(True) [1]
conversion-input-modal.ShowAsync()
conversion-input-modal.OnAfterRenderAsync(False) [2]
conversion-modal.OnAfterRenderAsync(False) [2]
conversion-input-modal.OnAfterRenderAsync(False) [3]
The console output for what is broken:
conversion-modal.OnAfterRenderAsync(True) [1]
conversion-input-modal.OnAfterRenderAsync(True) [1]
conversion-modal.ShowAsync()
conversion-modal.OnAfterRenderAsync(True) [1] <<-------------
conversion-modal.OnAfterRenderAsync(False) [2]
conversion-input-modal.OnAfterRenderAsync(False) [2]
The 4th line conversion-modal.OnAfterRenderAsync(True) [1]
is what I am suspicious of, it's like the component was reinitialized. Not sure why or if this is even part of the problem.
Help is appreciated.
Update
I added OnInitializedAsync console output to the Modal and confirmed that the modal is getting reinstantiated by the framework for some reason, again now sure this is causing the issue but is suspect till I find another avenue of troubleshooting.
Add Conversion Input (WORKING) Output
conversion-modal.OnInitializedAsync() [1]
conversion-input-modal.OnInitializedAsync() [1]
conversion-modal.OnInitializedAsync() [1]
conversion-input-modal.OnInitializedAsync() [1]
conversion-modal.OnAfterRenderAsync(True) [1]
conversion-input-modal.OnAfterRenderAsync(True) [1]
conversion-input-modal.ShowAsync()
conversion-input-modal.OnAfterRenderAsync(False) [2]
conversion-modal.OnAfterRenderAsync(False) [2]
conversion-input-modal.OnAfterRenderAsync(False) [3]
Add Conversion (BROKEN) Output
conversion-modal.OnInitializedAsync() [1]
conversion-input-modal.OnInitializedAsync() [1]
conversion-modal.OnInitializedAsync() [1]
conversion-input-modal.OnInitializedAsync() [1]
conversion-modal.OnAfterRenderAsync(True) [1]
conversion-input-modal.OnAfterRenderAsync(True) [1]
conversion-modal.ShowAsync()
conversion-modal.OnInitializedAsync() [1] <<-------------
conversion-modal.OnAfterRenderAsync(True) [1] <<---------
conversion-modal.OnAfterRenderAsync(False) [2]
conversion-input-modal.OnAfterRenderAsync(False) [2]