Htmxor icon indicating copy to clipboard operation
Htmxor copied to clipboard

In BlazorSSR running in AWS Lambda Dotnet, OnInitializedAsync gets called twice

Open genifycom opened this issue 1 year ago • 2 comments
trafficstars

Hi Egil,

I know this is not mainstream for you, but you might be able to tell me where to look.

Using the AWS Lambda Application template combined with the Blazor Web App SSR (Interaction type None) I get the following behavior.

On the Weather.razor page.

  1. Without any HTMX parts, OnInitializedAsync gets called once.
  2. Just adding .AddHtmx(); to services causes OnInitializedAsync to be called once if used in the URL e.g. https://localhost:64219/weather but called twice if called from the NavMenu.

This has nothing to do with pre-rendering (which the web is full of info on) since this is Interaction type None and calls none of the interactive parts.

I suspect it is to do with the internal rendering of components by Htmxor.

Any suggestions on how to trace it?

genifycom avatar Sep 20 '24 16:09 genifycom

Hey, no worries, if you can share a minimal repro of the issue you are seeing I can try to run it locally and see if I can figure it out.

egil avatar Sep 20 '24 16:09 egil

AWSServerlessHtmxor.zip

Hi Egil,

Here is the project. The Project template was created using the AWS Toolkit https://aws.amazon.com/visualstudio/ It is a Serverless Application

To run it locally, you will need the AWS Mock Lamda tool https://github.com/aws/aws-lambda-dotnet/tree/master/Tools/LambdaTestTool

Once you have this, you start the application normally.

I used the components folder from Blazor Web App and in startup, the Blazor Component requirements were added.

Then I added Htmxor Nuget preview.

In startup line 18, is the normal services.AddRazorComponents(); and the Weather.razor page runs with a single call to OnInitializedAsync (breakpoint at Weather.razor line 45).

If you then comment out Startup line 18 and uncomment line 21 and run again, this time the Weather.razor page runs with a two calls to OnInitializedAsync (breakpoint at Weather.razor line 45).

I hope you can get this running easily.

Thank you, Dave

genifycom avatar Sep 24 '24 18:09 genifycom