-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Improve the dev experience when a user doesn't apply an interactive render mode to a component that requires interactivity #57009
Comments
This has become the bane of our existence (as a Blazor component vendor) so I more than welcome the discussion. |
Nevermind, as per the comment below, the new APIs available in 9.0 enable this scenario |
@akorchev with the new APIs in .NET 9.0 you can check the rendermode and throw if there isn't any defined. |
Wouldn't I have to add such check to all 70+ components we have though? I would much prefer a built-in solution that doesn't require developers to add runtime render mode checks. We would do it if there is no other way but what about all other developers that don't know of rendering modes and wonder why Can't you throw an exception at runtime if EventCallbackFactory.Create is used in static rendering mode? |
No, because that's a perfectly valid thing to do for interactive components that support prerendering. Whatever solution we could come up with here would require you to modify all the components that require interactivity. Otherwise, it would be a massive breaking change for our customers. That said, it's reasonably easy to achieve this by placing this logic in a base class and inheriting from it. You either do that on each of your components, or if you are defining them in razor files, use an _Imports.razor to specify the base class. |
I thought we are discussing SSR here not prerendering. Aren't they different? What is the valid use case for using events in SSR when they will never be raised? Or do you mean that a distinction between SSR and prerendering can't be made? If the latter is true then your suggestion for checking the current render mode won't work either.
I've heard of base classes :) What is the .NET 9 API which can be used to get the current rendering mode? |
From the release notes ASP.NET Core in .NET 9 Preview 5 - Release Notes
From the releases notes ASP.NET Core in .NET 9 Preview 6 - Release Notes
|
Thanks! I have the following remaining questions:
|
There's plenty of components that can work with just by rendering HTML and offer interactivity through standard web semantics (form posts) which Blazor supports from .NET 8.0+ and onwards.
Prerendering is a subset of SSR, but its mandatory when your component is not interactive (otherwise nothing would get rendered) from there your component might register handlers when running interactively or define named forms to handle SSR actions.
You can throw inside your components if you require In general, is a design principle that interactivity is not required for components to render. Just because you can't interact with a component doesn't mean the page should completely stop working. |
I was asking specifically about interactive components - ones that need to handle DOM events e.g.
There are many cases for components that won't work - any component that handles a DOM event won't work.
That's a problem for me. Interactive components appear broken in SSR as no DOM event ever fires. Thus I suggest an exception is thrown. I still don't think there is a valid use case for rendering interactive components in SSR. What is the purpose of rendering a button whose |
Rendering components statically by default with no user feedback that interactive features won’t work is a major usability issue right now with Blazor. It’s not currently an error to render an interactive component statically, because interactive components are often prerendered statically. But accidentally rendering a component statically when you wanted it to be interactive is common. We should think about how we can help users out with this issue.
The text was updated successfully, but these errors were encountered: