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

[Blazor] Update discovery APIs and automatically configure the endpoints based on the discovered RenderModes #48283

Merged
merged 14 commits into from
May 23, 2023

Conversation

javiercn
Copy link
Member

@javiercn javiercn commented May 17, 2023

@javiercn javiercn requested a review from a team as a code owner May 17, 2023 15:40
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label May 17, 2023
@SteveSandersonMS
Copy link
Member

SteveSandersonMS commented May 19, 2023

Can we open a discussion about the pros and cons of automatically wiring up websocket/wasm endpoints based on the existence of components with particular render modes? I know you've done a lot of work to enable that here, however developers still have to understand what's going on and could be at risk of misconfiguration. For example, the default setup would automatically switch on the WebSocket listener if someone adds an Auto-mode component anywhere in the whole app (and even if one gets added in a new version of an RCL? that seems very troublesome), without making this obvious to the app owner who might never want to support Server components.

We could potentially simplify this a lot (remove a lot of implementation that would have to be maintained) and take a more risk-averse position on opening endpoints with only a tiny extra bit of explicit code in Program.cs.

If the default project template was a bit more explicit:

-app.MapRazorComponents<App>();
+app.MapRazorComponents<App>()
+    .EnableServerRenderMode()
+    .EnableWebAssemblyRenderMode();

... then we could remove lots of the rules about how the endpoint registrations are detected and how you can override that via combinations of UseServerRendering/UseWebAssemblyRendering/UseStaticRendering. It would be extremely obvious that you get the WebSocket listener or wasm static file serving if and only if you have the corresponding explicit opt-in.

Again, I know it's painful to even have this discussion given the amount of code already written and how invested you may feel in the autodetection design. We could always add the autodetection in the future (e.g., app.MapRazorComponents<App>(detectRenderModes: true)).

Definitely also interested in opinions from others (cc @danroth27 @mkArtakMSFT) to try to stay objective about product goals.

}

return (pages, components);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be unit-tested?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't plan to. This is covered by our E2E tests and will be source generated by default. This is here as a fallback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the scenarios where someone would disable the source generator?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there? I see the SG similar to the Razor SG. It's part of the core experience, not something you opt in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the source generator is available, we won't use this code path at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the source generator is available, we won't use this code path at all.

OK that's great - I'm guessing that means we'll be able to remove it and won't have to worry about maintaining two implementations. If that's not the case it would be great if you could correct me on this.

@javiercn javiercn force-pushed the javiercn/discovery-render-mode branch from 09eb756 to 28e9c61 Compare May 23, 2023 17:06
Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Added a couple of questions which it would be great if you could answer. The nitpick code remarks I'll leave to your judgement.

@javiercn javiercn merged commit d622921 into main May 23, 2023
@javiercn javiercn deleted the javiercn/discovery-render-mode branch May 23, 2023 23:27
@ghost ghost added this to the 8.0-preview5 milestone May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants