Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSR/server interactivity Error Boundary not working with Blazor Web App Pre6/7 #49679

Closed
1 task done
guardrex opened this issue Jul 27, 2023 · 5 comments
Closed
1 task done
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug.
Milestone

Comments

@guardrex
Copy link
Contributor

guardrex commented Jul 27, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Error boundary seems dysfunctional in ordinary use in Pre6 (i.e., not just with Forms, which was a fix for Pre7 on #47903). The circuit is lost, and the normal Blazor error UI is shown ...

[2023-07-27T13:37:59.374Z] Error: There was an unhandled exception on the current circuit, so this circuit will be terminated. For more details turn on detailed exceptions by setting 'DetailedErrors: true' in 'appSettings.Development.json' or set 'CircuitOptions.DetailedErrors'.

image

Expected Behavior

Normal Error Boundary processing. The following is from a Blazor Server 7.0 app ...

image

Steps To Reproduce

In Shared/MainLayout.razor ...

<article class="content px-4">
    <ErrorBoundary>
        @Body
    </ErrorBoundary>
</article>

In Pages/Counter.razor ...

private void IncrementCount()
{
    currentCount++;

    if (currentCount > 5)
    {
        throw new InvalidOperationException("Current count is too big!");
    }
}

... with AddServerComponents + AddServerRenderMode.

Exceptions (if any)

No exception. The error boundary is dysfunctional.

.NET Version

8.0.100-preview.6.23330.14

UPDATE: Still broken in Pre7 (8.0.0-preview.7.23375.6).

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Jul 27, 2023
@mkArtakMSFT mkArtakMSFT added this to the 8.0-rc1 milestone Jul 27, 2023
@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label Jul 27, 2023
@mkArtakMSFT mkArtakMSFT modified the milestones: 8.0-rc1, 8.0-rc2 Jul 31, 2023
@guardrex guardrex changed the title SSR/server interactivity Error Boundary not working with Blazor Web App Pre6 SSR/server interactivity Error Boundary not working with Blazor Web App Pre6/7 Aug 10, 2023
@SteveSandersonMS
Copy link
Member

@guardrex You didn't mention what you're doing to make the ErrorBoundary itself interactive. If it's not interactive, it's not running in the interactive circuit, so it can't have any effect on exceptions thrown in the interactive circuit.

If you were to make the whole app interactive from the Router downwards (e.g., in the Blazor Web template, go into Routes.razor and put @attribute [RenderModeServer] at the top) then the layout and all its contents, including ErrorBoundary, would be interactive and hence it would work as you expected.

I'll close this as by design, but please let me know if you think I'm missing anything!

@SteveSandersonMS SteveSandersonMS closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2023
@guardrex
Copy link
Contributor Author

guardrex commented Aug 23, 2023

I see ... so MainLayout definitely won't be the right spot to enable interactivity ...

InvalidOperationException: Cannot pass the parameter 'Body' to component 'MainLayout' with rendermode 'ServerRenderMode'. This is because the parameter is of the delegate type 'Microsoft.AspNetCore.Components.RenderFragment', which is arbitrary code and cannot be serialized.

... but WRT Routes.razor, it's not there by default ...

https://github.com/dotnet/aspnetcore/blob/main/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Routes.razor

... so you're suggesting that documentation should explicitly instruct devs that they need to enable interactivity in Routes.razor for an error boundary in MainLayout.razor. I'll pitch that to devs in the docs. I'm good. 👍

@guardrex
Copy link
Contributor Author

.... almost good! 😄

make the whole app interactive from the Router downwards

I'm concerned about this because devs might not want SSR applied to the whole app. Let me know if there's something special that needs to be called out about this ... or some other approach. Are we going to say that error boundaries can't be enabled via MainLayout unless they commit to taking this drastic step?

@guardrex
Copy link
Contributor Author

@SteveSandersonMS ... I'm going to work on the text at dotnet/AspNetCore.Docs#30128. If you want, you can help me on the PR with the lingo.

@SteveSandersonMS
Copy link
Member

Error boundaries can be enabled wherever the developer wants them to be, but:

  • If they are not interactive, then they only apply during SSR
  • If they are interactive, then they apply during the interactive session

So it's up to the developer to decide what they want. The only thing they can't do is have a noninteractive error boundary somehow participate in interactive rendering.

Are we going to say that error boundaries can't be enabled via MainLayout unless they commit to taking this drastic step?

They can have an error boundary in MainLayout even without it being interactive, but it will only exist (and hence catch errors) during SSR, not during interactive rendering.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug.
Projects
None yet
Development

No branches or pull requests

3 participants