-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Identifying whether the page is server or client for RenderMode.Auto #50859
Comments
@gragra33 thanks for contacting us. You can use |
@javiercn well, shoot ... yep, that works well. When was that added? |
@gragra33 It's been there for a while. We do plan to make this a more obvious concept in the API, but we haven't made it a priority since there are easy ways to figure this out. |
It's covered in our JSImport/Export JS interop article ... https://learn.microsoft.com/aspnet/core/blazor/javascript-interoperability/import-export-interop ... but it should also appear in our JS interop overview. I'll add it there to improve its visibility. Looks like it came in at 6.0 on #26140. |
This is how I solved it: I have an abstract For Server: https://github.com/marinasundstrom/Blazor8Test/blob/main/src/Server/ServerRenderingContext.cs These are, of course, registered depending on context. You can inject RenderingContext into your component, and it will resolve to the correct implementation depending on context. When the component is running on the server, the Server-specific implementation has a property that return a value indicating whether it is pre-rendering. You can then just check the |
Dupe of #49401 |
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
Whilst writing components to support all render modes is preferred, there may be cases where it is not always possible.
Describe the solution you'd like
For these cases, having a property or method with the running state for the component on the
ComponentBase
class would make this possible.Additional context
A current workaround is to check the
IJSRuntime
interface for if it inheritsIJSInProcessRuntime
. Here is my current workaround: Blazor.WhereAmIRunning. The sample project visually demonstrates how it works.The text was updated successfully, but these errors were encountered: