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

no dispatchGlobalEventToAllElements when no renderer attached #58667

Conversation

zuizuihao
Copy link
Contributor

ROOT CAUSE

when Blazor connection closed, the detachWebRendererInterop in the callback of connection.onclose will be invoked. here, it will invoke interopMethodsByRenderer.delete(rendererId);, all the interopMethodsByRenderer will be cleaned. also There are lots of global event listener in form.js like window.addEventListener('focus'), window.addEventListener('keydown'). if user still interact with our app like focus, click, the global event will be triggered, then invoked EventDelegator.onGlobalEvent, invoked EventDelegator.dispatchGlobalEventToAllElements invoked WebRendererInteropMethods.dispatchEvent invoked WebRendererInteropMethods.getInteropMethods, here since the interopMethodsByRenderer is empty, will throw this exception.

SOLUTION:

check isRendererAttached before dispatchGlobalEventToAllElements in EventDelegator

Fixes #57828

Before Fixes:
no_interop_methods_for_render

After Fixes:
no_interop_methods_for_render_solution

@zuizuihao zuizuihao requested a review from a team as a code owner October 28, 2024 07:43
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Oct 28, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 28, 2024
@dotnet-policy-service dotnet-policy-service bot added this to the 8.0.x milestone Oct 28, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Nov 5, 2024
@zuizuihao
Copy link
Contributor Author

/azp run

Copy link

Commenter does not have sufficient privileges for PR 58667 in repo dotnet/aspnetcore

@zuizuihao
Copy link
Contributor Author

any progress on it @javiercn

@tomvandyckVdP
Copy link

tomvandyckVdP commented Jan 23, 2025

I've got the impression quite some people are experiencing this issue ... any updates on the solution please?

@jscott1277
Copy link

Would love to see this fix get merged in as well. Thanks!

@javiercn javiercn added the pending-merge PR is scheduled to get merged at a convenient time label Jan 24, 2025
@javiercn javiercn changed the base branch from release/8.0 to main January 28, 2025 12:00
@javiercn javiercn force-pushed the zuizuihao/no-interop-methods-for-renderer-onGlobalEvent branch from 97b442f to 289f7cd Compare January 28, 2025 12:11
@javiercn javiercn removed the request for review from a team January 28, 2025 12:12
@tomvandyckVdP
Copy link

tomvandyckVdP commented Jan 28, 2025 via email

@javiercn javiercn merged commit 78862e8 into dotnet:main Jan 28, 2025
27 checks passed
@dotnet-policy-service dotnet-policy-service bot modified the milestones: 8.0.x, 10.0-preview2 Jan 28, 2025
captainsafia pushed a commit that referenced this pull request Feb 11, 2025
…rer attached (#58667)

* Prevents an issue where the event tries to get dispatched when no renderer is attached.

---------

Co-authored-by: Javier Calvarro Nelson <jacalvar@microsoft.com>
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 community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun pending-merge PR is scheduled to get merged at a convenient time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clean up global event listener, when connection closed
4 participants