MackinnonBuck / blazor-page-script

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

Issue with <PageScript> component in Blazor interactive server with prerender false #11

Open WALEED-NET opened 7 months ago

WALEED-NET commented 7 months ago

Dear Mackinnon Buck ,

I hope this message finds you well. I wanted to bring to your attention an issue I encountered while using the component in Blazor interactive server with prerender set to false.

The component is designed to enable per-page JavaScript navigation callbacks in Blazor web applications, allowing for page-specific JavaScript that works seamlessly with enhanced navigation enabled or disabled. However, I noticed that when using the interactive server with prerender set to false, the component does not function correctly.

Here are the steps to reproduce the issue:

  1. Set up a Blazor web application using the interactive server template then Set Prerender to False.
  2. Create a new page (e.g., Example.razor) and define the page-specific JavaScript callbacks using the component.
  3. Make sure prerender is set to false in the server configuration.
  4. Load the page and observe that the JavaScript callbacks defined in Example.razor.js (such as onLoad, onUpdate, and onDispose) are not properly invoked.

Or you can go back to the example that you reviewed in the "ASP.NET Community Standup - Blazor Experiments + eShop Q&A"(https://www.youtube.com/live/fkDSaIti_KU?t=595&si=BsVBrvA0pS8porfk) And Change its Render Mode Of Example to interactive server with Prerender False.

I have thoroughly tested this behavior and found that the component works as expected in other configurations, such as Blazor interactive server with prerender set to true or Blazor WebAssembly.

I believe this issue could potentially impact developers who rely on the component for page-specific JavaScript functionality in Blazor interactive server applications with prerender set to false.

I wanted to report this issue and seek your guidance on how to address it. If there are any workarounds or known solutions, I would greatly appreciate your insights. Additionally, I am willing to provide further details or assist in any further investigation required to resolve this issue.

Thank you for your attention to this matter. I look forward to your response.

Best regards, Waleed Bensumaidea

MackinnonBuck commented 2 months ago

Hi @WALEED-NET, I appreciate the issue report. Apologies for the delayed reply.

Does the project you're testing with utilize top-level interactivity (not per-page)? If that's the case, the project is using interactive routing. The PageScript component is designed to work with a static router, and it uses enhanced navigation callbacks to detect when a navigation occurs. It could be adapted to support interactive routing, although I haven't prioritized this because the primary benefit of PageScript is when interactive routing/JS interop are not possible. That said, I can see the advantage of having the component work the same way regardless of the render mode configuration.

I'll use this issue to track adding support for interactive routing. It might also be worth considering calling the onUpdate method after the component renders interactively.

WALEED-NET commented 2 months ago

Hi Mackinnon,

Thank you for your response, and no worries about the delay!

Yes, the project I'm testing does use top-level interactivity with interactive routing. I understand that the PageScript component is primarily designed for static routing, and I appreciate your insights regarding its current limitations.

As someone who is passionate about Blazor, I love diving deep into its features and solving related problems. I agree that it would be beneficial for the component to support interactive routing, especially as many applications adopt more dynamic navigation patterns. Implementing a way to call the onUpdate method after the component renders interactively could serve as a useful workaround in the meantime.

If there are any further contributions you would like me to make in the .NET community regarding Blazor, I would be more than happy to assist. Please let me know if you need any additional information from my side or if there's anything I can do to help with this issue.

Thank you once again for your attention to this matter!