Skip to content

EventUtil: Propagate exceptions.#9967

Merged
ScarletKuro merged 3 commits intoMudBlazor:devfrom
ScarletKuro:asnorender_fix
Oct 13, 2024
Merged

EventUtil: Propagate exceptions.#9967
ScarletKuro merged 3 commits intoMudBlazor:devfrom
ScarletKuro:asnorender_fix

Conversation

@ScarletKuro
Copy link
Member

@ScarletKuro ScarletKuro commented Oct 11, 2024

Description

Finall, fixes: #8437

See dotnet/aspnetcore#54543 for more details about the problem.

Now, instead of calling:

EventUtil.AsNonRenderingEventHandler(...)

you should call it as:

this.AsNonRenderingEventHandler(...)

Because it is now an extension method that requires a reference of ComponentBase.

Why is the IComponentException necessary?

The DispatchExceptionAsync method of ComponentBase is protected, meaning we cannot call it directly from outside of ComponentBase. While we could have made AsNonRenderingEventHandler specific to MudComponentBase and added our own internal DispatchExceptionAsync, I opted for the interface approach. This allows users to utilize it with their own ComponentBase implementations. Alternatively, we could have used UnsafeAccessor and use ComponentBase directly, eliminating the need for an interface. However, I chose the interface route is better.

Changed my mind and decided to go for ComponentBase + UnsafeAccessor, because of this: #9967 (comment).

How Has This Been Tested?

Existing unit tests that I wrote back then.

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (fix or improvement to the website or code docs)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@github-actions github-actions bot added breaking change This change will require consumer code updates bug Unexpected behavior or functionality not working as intended PR: needs review labels Oct 11, 2024
@codecov
Copy link

codecov bot commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.77%. Comparing base (28bc599) to head (71c98ea).
Report is 563 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #9967      +/-   ##
==========================================
+ Coverage   89.82%   90.77%   +0.94%     
==========================================
  Files         412      407       -5     
  Lines       11878    12578     +700     
  Branches     2364     2454      +90     
==========================================
+ Hits        10670    11418     +748     
+ Misses        681      598      -83     
- Partials      527      562      +35     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ScarletKuro
Copy link
Member Author

We could also leave the old one in place, and then it wouldn't be a breaking change, but I feel like the original one is broken and it not what you would want most of the time and we should not encourage it's usage.

@ScarletKuro
Copy link
Member Author

ScarletKuro commented Oct 11, 2024

Changed my mind, and decided to go for ComponentBase + UnsafeAccessor as then you can use it on normal pages and won't require to implement IComponentException like I had in EventUtil1Test.razor.

@danielchalmers
Copy link
Member

I wonder if this could be used for #6104 and #6413

@ScarletKuro
Copy link
Member Author

I wonder if this could be used for #6104 and #6413

Yes

Copy link
Member

@danielchalmers danielchalmers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

working for me

@danielchalmers
Copy link
Member

The last one that's still impacting me is the menu items. They're still triggering renders even with AutoClose="false"

@ScarletKuro
Copy link
Member Author

The last one that's still impacting me is the menu items. They're still triggering renders even with AutoClose="false"

Interesting, maybe something else there triggering re-render?

@henon
Copy link
Contributor

henon commented Oct 13, 2024

Are we removing EventUtil.AsNonRenderingEventHandler(...) ? It is v8 after all, we can break and this is easy to migrate.

@ScarletKuro
Copy link
Member Author

ScarletKuro commented Oct 13, 2024

Are we removing EventUtil.AsNonRenderingEventHandler(...) ? It is v8 after all, we can break and this is easy to migrate.

That was my question in #9967 (comment)
Do you want to keep it considering that this wouldn't propagate the exception to ErrorBoundary and people might not expect it(we can add it to xmldoc, but not everyone is reading that) or we just remove it and only the "correct" new API will exist. There is also always a chance that someone from community will PR with using the wrong version and that gets missed in the review.

@ScarletKuro
Copy link
Member Author

Added to v8.0.0 Migration Guide #9953

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change This change will require consumer code updates bug Unexpected behavior or functionality not working as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: Exception doesn't flow to ErrorBoundary.

3 participants