Closed hhhenggg closed 1 month ago
SpawnDev.BlazorJS requires IJSInProcessRuntime to make synchronous calls into the Javascript environment. Server side rendering uses the default Javascript runtime, IJSRuntime, which only supports asynchronous calls to Javascript. Because of that, there is no easy way to make SpawnDev.BlazorJS work in server side rendering at this time. I cannot say it will never work with server side rendering as I do have some ideas that I may try at some point, but I do not see it happening anytime soon.
Thank you for your reply. I use the auto mode in blazor, which is something I need. I think many people will also need it, and I hope to use it in future projects. I will continue to monitor the progress of blazorjs, and thank you for providing excellent projects for everyone.
According to my project README.md I have tested SpawnDev.BlazorJS in auto
mode and it is working. Have you tried it?
I'm sure it only works in the client project though and not in the server project.
According to my project README.md I have tested SpawnDev.BlazorJS in
auto
mode and it is working. Have you tried it?
I have tried the webassembly mode and it works. The server that runs first in auto mode, and the client that runs only after downloading the client code, will report the following error if the service is not registered when running on the server.
My comment:
SpawnDev.BlazorJS in auto mode and it is working.
That isn't very clear. So to clarify: The app Interactive render mode`` can be set to
Auto (Server and WebAssembly)can use any rendering mode for components that do not use SpawnDev.BlazorJS. But components that do use SpawnDev.BlazorJS will have to be set to
InteractiveWebAssemblywith prerendering disabled at the component level.
Interactivity locationshould be
Per page/component```.
Example WasmPage.raozr:
@page "/wasm"
@using SpawnDev.BlazorJS;
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
<h1>Wasm Page</h1>
RenderMode: @(OperatingSystem.IsBrowser() ? "WebAssembly" : "Server")
@code {
[Inject]
BlazorJSRuntime JS { get; set; }
protected override void OnInitialized()
{
JS.Set("document.title", "Hello world from wasm page!");
}
}
You can even use WASM components in the server project's serer rendered pages. The below component WasmComponent
can be added to server rendered pages and it will load using the WASM environment
Example WasmComponent.raoz:
@using SpawnDev.BlazorJS;
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
<h1>Wasm Component</h1>
RenderMode: @(OperatingSystem.IsBrowser() ? "WebAssembly" : "Server")
@code {
[Inject]
BlazorJSRuntime JS { get; set; }
protected override void OnInitialized()
{
JS.Set("document.title", "Hello world from wasm component!");
}
}
I spend most of my time working on the WASM part of it. I created a Blazor Web App
to test this out to help clarify what needs to happen to get it working (for us both.) I hope this helps.
I uploaded the Blazor Web App
project I tested with. The repo is here: BlazorJSWebAppTest
Thank you, I know where the problem is and I used global auto mode. Or is it because it's running on the server。
I added a new section to the project README.md Blazor Web App compatibility
To change an existing project Interacticity location
from Global
to Per component/page
remove the @rendermode
attribute from the Routes
element in your App.razor
page. Then the @rendermode
attribute will work in your WebAssembly pages and components.
Change this:
<body>
<Routes @rendermode="InteractiveAuto" />
<script src="_framework/blazor.web.js"></script>
</body>
To this:
<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
</body>
Then this will work in your WebAssembly components:
@rendermode @(new InteractiveWebAssemblyRenderMode(prerender: false))
Microsoft documentation on setting (or unsetting) the rendermode
for the entire app: Apply a render mode to the entire app
Thank you, I know all of this. My project has a lot of content, and the first access in client mode will be slow, so I need to run it on the server side, so I can only wait for the support server to run.
I am looking for blazer to run JavaScript. This project is great, I need to use it in projects in auto mode,but the web app auto mode is not yet supported. Will it be supported in the future?