Skip to content

PopoverService: Add CheckForPopoverProvider#9391

Merged
ScarletKuro merged 3 commits intoMudBlazor:devfrom
ScarletKuro:popoverprovider_check
Jul 13, 2024
Merged

PopoverService: Add CheckForPopoverProvider#9391
ScarletKuro merged 3 commits intoMudBlazor:devfrom
ScarletKuro:popoverprovider_check

Conversation

@ScarletKuro
Copy link
Member

@ScarletKuro ScarletKuro commented Jul 13, 2024

Description

Adds as error: Unhandled exception rendering component: Missing <MudPopoverProvider/>, please add it to your layout. See https://mudblazor.com/getting-started/installation#manual-install-add-components

We adhere to the "fail fast" policy, so it makes sense to add a check to see if the MudPopoverProvider exists when trying to create a popover, tooltip, dropdown, etc.—anything that relies on the provider.

Many of our users often forget to add the MudPopoverProvider to the MainLayout or Page (in the case of per-page render mode) and then complain that we should add a hint that it's required. Many suggested adding an alert to the documentation for components that need it, but I think this approach is more effective.

If someone wants the old behavior, they should set:

Services.AddMudServices(options =>
{
    options.PopoverOptions.CheckForPopoverProvider = false;
});

Or, if they are adding services individually for some reason:

Services.AddMudPopoverService(options => options.CheckForPopoverProvider = false);

This is how it looks if MudPopoverProvider is missing:
Exception

How Has This Been Tested?

Unit tests & visually

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 enhancement Adds a new feature or enhances existing functionality (not fixing a defect) in the main library PR: needs review labels Jul 13, 2024
@codecov
Copy link

codecov bot commented Jul 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.61%. Comparing base (28bc599) to head (5378833).
Report is 342 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #9391      +/-   ##
==========================================
+ Coverage   89.82%   90.61%   +0.78%     
==========================================
  Files         412      403       -9     
  Lines       11878    12663     +785     
  Branches     2364     2447      +83     
==========================================
+ Hits        10670    11475     +805     
+ Misses        681      632      -49     
- Partials      527      556      +29     

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

@ScarletKuro ScarletKuro requested a review from henon July 13, 2024 11:49
@ScarletKuro
Copy link
Member Author

Let me know if the message should be different:

throw new InvalidOperationException($"The component requires to have at least one observer({nameof(MudPopoverProvider)}) to create a popover.");

@henon
Copy link
Contributor

henon commented Jul 13, 2024

How about this error message: Missing <MudPopoverProvider/>, please add it to your layout. See https://mudblazor.com/getting-started/installation#manual-install-add-components

@henon
Copy link
Contributor

henon commented Jul 13, 2024

Also, I suggest pasting the console error message as text in the head of this issue so people googling for this error will land here.

@ScarletKuro ScarletKuro merged commit 4890a07 into MudBlazor:dev Jul 13, 2024
@ScarletKuro ScarletKuro deleted the popoverprovider_check branch July 13, 2024 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Adds a new feature or enhances existing functionality (not fixing a defect) in the main library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants