Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

versile2
Copy link
Contributor

@versile2 versile2 commented Apr 8, 2025

Description

Refactor mudPopover.js for performance.

Previously:

Initialize (Popover Service init) registers 2 listeners for resize/scroll.
Connect (Popover registered in Dom) Every popover registers on creation and attachs 2 observers and x1-?? scroll listeners usually 3+
Disconnect (Popover no longer in Dom) Services and Observers are disconnected. Scroll listeners are left.
PopoverChange (mud-popover-open class add/remove, data-ticks (any change), resize and place popover zindex, overlay, etc.
Result: Each popover in the dom maintains a scroll listener on every element from the node creating the popover to the body, a resize observer, a mutation observer, and 2 global resize/scroll listeners.

With Changes:

Initialize: Register one global observer, 2 listeners
Connect: Adds popover to this.map, nothing attached.
Disconnect: Checks this.map for any observers and listeners still attached, disconnects and disposes and sets null.
PopoverChange: Determines if open/closed and only performs actions if open. On open registers 1 resize observer and x1-?? scroll listeners and attaches to this.map for later removal. On close removes top/left properties on css effectively hiding it. removes observer and scroll listeners and sets this.map values of them to null. Data ticks verifies a popover is open then proceeds to place it appropriately.
Result: 1 global MutationObserver and 2 global resize/scroll listeners and then only additional observers/listeners on open popovers.

Non-Performance Tweaks

Commented every piece of the file for later use, so it should be clear what each piece does.
Separated concerns where it made sense.
Made mud-popover-provider a variable in PopoverOptions that is passed appropriately to the service then js.
Added contentpadding to provider options to provide padding when a popover height exceeds bounds.
Updated logic resizing over height popovers that do not have a maxheight in themselves or their firstchild to cover both top and bottom scenarios.
Simplified and enhanced greatly flipping logic to include up and down in every scenario using FlipMargin. (I would suggest in V9 setting FlipMargin to 24 to match content padding or combine them.)
Fixed Regression from #11117 where overlay was not being positioned to allow menu overlays to position except nested.

Reverted #11051
Reverted the rest of #10853

Resolves #11133
Resolves #11046
Resolves #11162
Resolves #10791
Resolves #10879 (flipped and oversize logic)

How Has This Been Tested?

Adjusted unit tests for reverts.
Visually tested every Viewer case (WASM) that has a popover. Added two Viewercases, one to stress the system and test tooltips and another to test flip logic extensively.
Visually tested every Docs example that has a popover. (BSS)
Monitored memory and CPU usage (in Debug mode) to ensure no undue spikes or otherwise)

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.

versile2 and others added 19 commits April 3, 2025 23:58
Updated `window.mudpopoverHelper` with new properties for better popover behavior. Improved `MudPopover` class initialization with error handling and a `MutationObserver`. Refactored `initialize` and `connect` methods to streamline observer management and removed unnecessary scroll and resize listeners. Simplified `dispose` method for better maintainability.
Refactor variable names and enhance comments for clarity.
Correct spelling of 'postion' to 'position'.
Simplify conditional checks for popover flipping logic.
Use removeProperty for off-screen positioning instead of
setting styles to '-9999px'.
These changes aim to maintain functionality while
making the code more understandable and easier to maintain.
… directly since we are modifying width on the fly. remove scroll from being debounced. set observers to connect on open and disconnect on close.
@github-actions github-actions bot added bug Unexpected behavior or functionality not working as intended PR: needs review labels Apr 8, 2025
@versile2 versile2 requested a review from ScarletKuro April 8, 2025 18:56
Copy link

codecov bot commented Apr 8, 2025

Codecov Report

Attention: Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.08%. Comparing base (d64aa4f) to head (692329c).
Report is 7 commits behind head on dev.

Files with missing lines Patch % Lines
...c/MudBlazor/Components/Tooltip/MudTooltip.razor.cs 75.00% 0 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (83.33%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev   #11165   +/-   ##
=======================================
  Coverage   91.08%   91.08%           
=======================================
  Files         436      436           
  Lines       14098    14143   +45     
  Branches     2727     2731    +4     
=======================================
+ Hits        12841    12882   +41     
+ Misses        640      639    -1     
- Partials      617      622    +5     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ScarletKuro ScarletKuro merged commit 886dcc9 into MudBlazor:dev Apr 19, 2025
5 of 6 checks passed
@LucianiChristian
Copy link

I'm running into an issue around using a MudMenu after upgrading to 8.6.0. It doesn't occur as of 8.5.1. I'm assuming its a result of this change?

Error in Google Chrome:

MudBlazor.min.js:153 No Popover Container found with class mudblazor-main-content

@versile2
Copy link
Contributor Author

I'm running into an issue around using a MudMenu after upgrading to 8.6.0. It doesn't occur as of 8.5.1. I'm assuming its a result of this change?

Error in Google Chrome:

MudBlazor.min.js:153 No Popover Container found with class mudblazor-main-content

Almost assuredly a cache problem since I changed the way that works. Either use Assets if .NET 9 or make sure your .css/.js files in index or app.razor have ?v=8.6 after them. If you continue to have an issue please create an issue and tag me I'll get right on it.

@LEC-Group
Copy link

I'm also having display issues since this update (I updated my cache!)

@versile2
Copy link
Contributor Author

versile2 commented May 7, 2025

I'm also having display issues since this update (I updated my cache!)

I am working on a fix and updating here:
#11269

@versile2 versile2 deleted the refactor/popovers branch July 16, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behavior or functionality not working as intended
Projects
None yet
4 participants