MudBlazor: MudDialog.Show not working for inline MudDialogs
Bug type
Component
Component name
MudDialog
What happened?
In my project, I use inlined MudDialogs in a couple of places. I use these to provide user input. As they’re highly specific to the page they’re used in, I’ve inlined these dialogs.
In MudBlazor 6.0.2 this works as expected. I’m now trying to upgrade to MB6.0.7, and found out that the functionality no longer works as it did before.
Expected behavior
Similar behaviour as how it worked in MudBlazor 6.0.2, or when using DialogService.Show<T>().
Reproduction link
https://try.mudblazor.com/snippet/wEQcOHEHTrPPKude
Reproduction steps
- Declare an inline MudDialog and store its reference in a variable
- Invoke
Show()on said variable - Observe the dialog not showing, the task being returned by IDialogReference.Result having ran to completion, and its value being
null
Relevant log output
No response
Version (bug)
6.0.7
Version (working)
6.0.2
What browsers are you seeing the problem on?
Microsoft Edge
On what operating system are you experiencing the issue?
Windows
Pull Request
- I would like to do a Pull Request
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 17 (4 by maintainers)
FYI, this issue is still present in 6.0.10.
@horaciodiez: I have been experiencing the same problem as you - sometimes the dialog won’t close, but sometimes it does. (Although I don’t think this is the same problem that the OP has).
I traced the problem and found that it is because I have multiple Layouts in my app. I have <MudDialogProvider/> in MainLayout.razor as per the ‘Getting Started’ page in the docs. This means that when I am moving between pages that use MainLayout and other Layouts that the MudDialogProvider gets created multiple times.
This shouldn’t be a problem. However the MudDialogProvider is not Disposed correctly. The event handlers for OnDialogInstanceAdded and OnDialogCloseRequested are not being removed in the Dispose method like they should be. This causes a problem in the DismissInstance method and the dialog is not closed.
As a workaround I have moved <MudDialogProvider/> to App.razor. This means that only one instance of MudDialogProvider is ever created.
Edit: Created a new issue as this is not the same as the OP’s problem. New issue is #4508.