Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor Server - When is blazor-error-ui displayed?

I'm slightly confused about how blazor-error-ui works in practice. I understand that it's hidden by default because of CSS (via display: none), but I can't seem to get it to appear by causing errors in the application.

According to the Blazor docs:

The blazor-error-ui element is normally hidden due to the presence of the display: none style of the blazor-error-ui CSS class in the site's stylesheet [...] When an error occurs, the framework applies display: block to the element.

Emphasis mine.

The docs say that an error should cause the blazor-error-ui div to have its display property set to block, but throwing an exception takes me to an developer exception page, and doesn't actually display the div at all. If I set the environment to Release, it takes me to the /Error page, instead.

So, when does the blazor-error-ui div actually get shown? When Blazor itself has an internal error?

like image 446
micka190 Avatar asked Aug 12 '26 08:08

micka190


1 Answers

I won't mark this as accepted, because I couldn't find an official source for this, and my own testing yielded mixed results so far.

It seems like errors that occur within events can trigger blazor-error-ui, but those thrown from page lifecycle methods don't.

For example:

Clicking on a <button> element that has an @onclick=[...] method defined that throws an exception causes blazor-error-ui to appear.

However, throwing an exception directly from a @page's lifecycle methods (i.e. OnInitializedAsync()) appear to not trigger blazor-error-ui.

I'm unsure if this is intended behavior or not, since the docs don't seem to mention this.

like image 61
micka190 Avatar answered Aug 13 '26 22:08

micka190



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!