Skip to content
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

Pre DOM patch event listener in Blazor SSR #58630

Open
darrelsilveira047 opened this issue Oct 25, 2024 · 3 comments
Open

Pre DOM patch event listener in Blazor SSR #58630

darrelsilveira047 opened this issue Oct 25, 2024 · 3 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components Docs This issue tracks updating documentation

Comments

@darrelsilveira047
Copy link

darrelsilveira047 commented Oct 25, 2024

Hi Blazor Folks,

I’m using Blazor Static Server-Side Rendering (SSR) for my project, where the interactivity is handled exclusively via JavaScript. In my workflow, I have certain JS components (e.g., Tiny Slider) that need to be disposed of before Blazor applies any DOM updates (patches) to avoid conflicts.

Currently, I use a MutationObserver to detect DOM changes after they occur, but this approach is reactive and doesn’t prevent issues that occur during the DOM patching process itself.

Would it be possible to add an event listener or lifecycle hook that fires before Blazor begins DOM patching in SSR mode? This would allow developers to clean up or dispose of JavaScript components before DOM updates take place, similar to how an “unmount” or “pre-patch” hook works in other frameworks.

Thank you !

Originally posted by @darrelsilveira047 in #58596

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Oct 25, 2024
@javiercn javiercn added this to the .NET 10 Planning milestone Oct 25, 2024
@mkArtakMSFT
Copy link
Member

Thanks for contacting us.
We already have support for this and it shipped in .NET 9 earlier today.
Looks like we missed to document this. @MackinnonBuck can you please provide info here for @guardrex to use to add documentation for this? Thanks!

@mkArtakMSFT mkArtakMSFT added the Docs This issue tracks updating documentation label Nov 12, 2024
@mkArtakMSFT mkArtakMSFT modified the milestones: .NET 10 Planning, 9.0.0 Nov 12, 2024
@MackinnonBuck
Copy link
Member

We would want to extend our docs about Blazor.addEventListener() to include information about the enhancednavigationstart and enhancednavigationend events. Those events run before and after an enhanced navigation, respectively.

https://learn.microsoft.com/aspnet/core/blazor/javascript-interoperability/static-server-rendering?view=aspnetcore-8.0

@guardrex
Copy link
Contributor

@mkArtakMSFT ... The docs PR is at dotnet/AspNetCore.Docs#34101.

I pinged you, @MackinnonBuck, for review.

@danroth27 danroth27 modified the milestones: 9.0.0, .NET 10 Planning Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Docs This issue tracks updating documentation
Projects
None yet
Development

No branches or pull requests

6 participants