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

Callsite rendermodes #48967

Merged

Conversation

SteveSandersonMS
Copy link
Member

@SteveSandersonMS SteveSandersonMS commented Jun 22, 2023

Add callsite rendermodes for Blazor full-stack web apps

Allows Blazor components to have a rendermode specified at the usage site. Among other use cases, this allows us to simplify the default project template by removing an otherwise pointless wrapper component.

We want to do this in preview 6 (to get customer feedback) but didn't land it in time for the normal code-complete cutoff.

Description

We already support specifying a fixed rendermode on a component type, e.g.:

@page "/my-component"
@attribute [RenderModeServer]

<h1>Here's some interactive stuff</h1>
...

However, it's commonly also desirable to specify a rendermode at the callsite for a component, e.g.:

<h1>Here's some interactive stuff</h1>
<Counter @rendermode="@RenderMode.Server" />

This allows the consumer to vary the rendermode according to their own preferences without having to do so on the parent component. In the default project template, it means that developers can have an interactive <HeadOutlet> just by writing:

<HeadOutlet @rendermode="@RenderMode.Server" />

... whereas without this change, they have to define some new component e.g., called AppHeadOutlet containing just:

@attribute [RenderModeServer]
<HeadOutlet />

... and then place <AppHeadOutlet /> at the intended call site.

Fixes #48793

Customer Impact

Allows the default migration experience from Blazor Server/WebAssembly to the new full-stack architecture to be more streamlined and not involve a weird, pointless-seeming wrapper component.

Regression?

  • Yes
  • No

[If yes, specify the version the behavior has regressed from]

Risk

  • High
  • Medium
  • Low

Low because this only impacts completely new code using the new functionality. It shouldn't be possible for this to break existing apps.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Jun 22, 2023
@SteveSandersonMS SteveSandersonMS added ask-mode This issue / PR is a patch candidate which we will bar-check internally before patching it. Servicing-consider Shiproom approval is required for the issue labels Jun 22, 2023
@ghost
Copy link

ghost commented Jun 22, 2023

Hi @SteveSandersonMS. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge.

To learn more about how to prepare a servicing PR click here.

@SteveSandersonMS SteveSandersonMS removed the ask-mode This issue / PR is a patch candidate which we will bar-check internally before patching it. label Jun 22, 2023
@SteveSandersonMS SteveSandersonMS marked this pull request as ready for review June 22, 2023 18:30
@SteveSandersonMS SteveSandersonMS requested a review from a team as a code owner June 22, 2023 18:30
@SteveSandersonMS SteveSandersonMS changed the title Return of the callsite rendermodes Callsite rendermodes Jun 22, 2023
@mkArtakMSFT
Copy link
Member

@SteveSandersonMS do you want to retarget this to preview6? Or will there be a port PR?

@SteveSandersonMS SteveSandersonMS force-pushed the stevesa/return-of-the-callsite-rendermodes branch from e335c90 to 31efd54 Compare June 23, 2023 08:36
@SteveSandersonMS SteveSandersonMS requested review from a team and wtgodbe as code owners June 23, 2023 08:36
@SteveSandersonMS SteveSandersonMS changed the base branch from main to release/8.0-preview6 June 23, 2023 08:36
@SteveSandersonMS SteveSandersonMS removed the request for review from wtgodbe June 23, 2023 08:36
@SteveSandersonMS SteveSandersonMS force-pushed the stevesa/return-of-the-callsite-rendermodes branch from 31efd54 to e45b03f Compare June 23, 2023 08:39
@javiercn
Copy link
Member

@SteveSandersonMS overall looks good.

Are we checking at some point that users don't intermingle server/webasembly components?

@SteveSandersonMS
Copy link
Member Author

Are we checking at some point that users don't intermingle server/webasembly components?

Yes, both the server and webassembly renderers reject instructions to render the other type of component.

@mkArtakMSFT mkArtakMSFT added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Jun 23, 2023
@ghost
Copy link

ghost commented Jun 23, 2023

Hi @SteveSandersonMS. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed.

@wtgodbe wtgodbe merged commit 0e48ee0 into release/8.0-preview6 Jun 23, 2023
@wtgodbe wtgodbe deleted the stevesa/return-of-the-callsite-rendermodes branch June 23, 2023 19:18
@ghost ghost added this to the 8.0-preview6 milestone Jun 23, 2023
@ghost ghost added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Jun 23, 2023
SteveSandersonMS added a commit that referenced this pull request Jun 27, 2023
* builder.AddComponentRenderMode API and storage on RenderTree

* Extend ResolveComponentForRenderMode to receive callerSpecifiedRenderMode, and supply it from ComponentFactory

* Simplify API: collapse the two rendermode sources into a single rendermode before calling ResolveComponentForRenderMode

* Corresponding renames

* Actually supply callsite rendermode from RenderTree

* Give clearer errors if misusing this feature

* Build fix

* Actually use the parameter name @rendermode for forward-compatibility with the final syntax

* Add E2E tests
SteveSandersonMS added a commit that referenced this pull request Jun 29, 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 area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RenderModeServer doesn't work when applied to root component
4 participants