MackinnonBuck / blazor-page-script

A Blazor component enabling per-page JavaScript initialization logic in statically rendered Blazor Web apps
MIT License
70 stars 7 forks source link

No Script File #1

Closed johndalloxx closed 9 months ago

johndalloxx commented 10 months ago

Hey I cant seem to get this to work. Im doing everything in the setup, although my Program.cs file has some more things to it:


// Add services to the container.
builder.Services.AddRazorComponents().AddInteractiveServerComponents();

builder.Services.AddHttpContextAccessor();
builder.Services.AddDistributedMemoryCache();
builder.Services.AddAntiforgery();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error", createScopeForErrors: true);
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseStaticFiles();
app.UseAntiforgery();

app.MapRazorComponents<App>().AddInteractiveServerRenderMode();

app.Run();

I there anything in here that might interfer with how this package works?

DOM looks like this:

Skjermbilde 2023-12-13 kl  23 41 38

Home.razor file:

@page "/"

<PageTitle>Home</PageTitle>
<PageScript Src="./Components/Pages/Home.razor.js" />
<h1 class="text-sm text-blue-800 m-auto w-fit z-10">
    Home
</h1>

Home.razor.js:

// Called when the script first gets loaded on the page.
export function onLoad() {
    console.log('Load');
}

// Called when an enhanced page update occurs, plus once immediately after
// the initial load.
export function onUpdate() {
    console.log('Update');
}

// Called when an enhanced page update removes the script from the page.
export function onDispose() {
    console.log('Dispose');
}
MackinnonBuck commented 10 months ago

Hm, looks fine to me. Some questions:

  1. How are you getting the <PageScript /> component into your app? Are you consuming the NuGet package or copying the source code into your project?
  2. Are there any errors in the console? That might point to the problem.

If you could link to a minimal repro project hosted as a GitHub repository, I would be able to look into it more to find out what's going on. Thanks!

MackinnonBuck commented 9 months ago

Closing this out since I haven't heard back in a while. If you can trace the problem back to an issue with the library, please feel free to open a new issue. Thanks!