Skip to content

fix(ContextMenu): make ContextMenu work on wasm/maui#7504

Merged
ArgoZhang merged 9 commits intomainfrom
fix-context
Jan 14, 2026
Merged

fix(ContextMenu): make ContextMenu work on wasm/maui#7504
ArgoZhang merged 9 commits intomainfrom
fix-context

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Jan 13, 2026

Link issues

fixes #7450

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Update floating-ui DOM and core ESM bundles to the latest upstream utilities, adjust ContextMenu JavaScript to defer popper creation for WebAssembly/MAUI compatibility, and ensure context menu trigger reflection metadata for MouseEventArgs is preserved for trimming.

New Features:

  • Expose additional floating-ui middleware utilities (offset, shift, flip, size, hide, arrow, inline, limitShift, detectOverflow, platform helpers) from the DOM bundle.

Bug Fixes:

  • Fix ContextMenu positioning and initialization timing so it works correctly in WASM/MAUI environments.

Enhancements:

  • Refactor floating-ui DOM and core bundles to use shared utility modules for DOM and math helpers, improving cross-browser behavior (scrollbars, top-layer elements, WebKit, RTL, iframes) and auto-update logic.
  • Add DynamicDependency annotation to ContextMenuTrigger to keep required MouseEventArgs members when trimming in AOT scenarios.

Copilot AI review requested due to automatic review settings January 13, 2026 02:11
@bb-auto bb-auto Bot added the bug Something isn't working label Jan 13, 2026
@bb-auto bb-auto Bot added this to the v10.2.0 milestone Jan 13, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jan 13, 2026

Reviewer's Guide

Refactors the bundled floating-ui DOM/core modules to use shared utility ESM modules and updated platform logic, adds the missing floating-ui utils files, and adjusts the ContextMenu trigger and JS behavior to be compatible with Blazor WASM/MAUI and IL trimming.

Sequence diagram for ContextMenu show behavior with async Popper creation

sequenceDiagram
    actor User
    participant Blazor as Blazor_ContextMenuTrigger
    participant JS as ContextMenu_js
    participant Data as ContextMenu_DataStore
    participant Popper as floating_ui_dom

    User->>Blazor: Right-click (MouseEventArgs)
    Blazor->>JS: show(id, event)
    JS->>JS: setTimeout(0)
    Note over JS: Call is deferred to next tick
    JS->>Data: Data.get(id)
    alt ContextMenu_found
        Data-->>JS: cm
        JS->>JS: el = cm.el, zone = cm.zone
        JS->>JS: document.body.appendChild(el)
        alt existing_popper
            JS->>JS: cm.popper()
        end
        JS->>Popper: createPopper(zone, el, callback)
        Popper-->>JS: popperCleanup
        JS->>JS: cm.popper = popperCleanup
    else ContextMenu_missing
        Data-->>JS: null
        JS-->>Blazor: no-op
    end
Loading

Class diagram for ContextMenuTrigger and MouseEventArgs trimming dependency

classDiagram
    class ContextMenuTrigger {
        +ContextMenuZone ContextMenuZone
        +Task OnContextMenu(MouseEventArgs args)
    }

    class MouseEventArgs {
        <<from_Microsoft_AspNetCore_Components_Web>>
        %% Public methods preserved via DynamicDependency
    }

    class DynamicDependencyAttribute {
        +DynamicDependencyAttribute(DynamicallyAccessedMemberTypes memberTypes, Type type)
    }

    class DynamicallyAccessedMemberTypes {
        <<enum>>
        PublicMethods
    }

    ContextMenuTrigger --> MouseEventArgs : uses_in_OnContextMenu
    ContextMenuTrigger ..> DynamicDependencyAttribute : decorated_with
    DynamicDependencyAttribute --> DynamicallyAccessedMemberTypes
Loading

File-Level Changes

Change Details Files
Refactor floating-ui DOM integration to use shared utility modules and updated platform behavior.
  • Replace inlined DOM helper logic with imports from new floating-ui.utils.dom.esm.js and floating-ui.utils.esm.js
  • Update viewport, clipping, offset-parent, and iframe/scrollbar handling to modern upstream logic including WebKit visualViewport behavior and RTL scrollbar fixes
  • Enhance autoUpdate/observeMove to handle intersection observer edge cases, resize loops, and animation frame layout shift detection
  • Expose additional exports (arrow, autoPlacement, detectOverflow, flip, hide, inline, limitShift, offset, shift, size, getOverflowAncestors) from the DOM ESM entry
src/BootstrapBlazor/wwwroot/lib/floating-ui/floating-ui.dom.esm.js
Refactor floating-ui core positioning and middleware to use shared utilities and improved algorithms.
  • Import alignment/axis/padding/placement utilities from floating-ui.utils.esm.js instead of local implementations
  • Adjust computeCoordsFromPlacement, detectOverflow, arrow, autoPlacement, flip, inline, offset, shift, limitShift, and size middleware to use the new utility functions and updated overflow/axis logic
  • Improve handling of RTL, cross-axis flipping, alignment offsets (especially with arrow/offset interaction), and size constraints with shift middleware coordination
  • Simplify exports to rely on shared rectToClientRect from utils
src/BootstrapBlazor/wwwroot/lib/floating-ui/floating-ui.core.esm.js
Introduce shared floating-ui utility modules for DOM and core helpers.
  • Add floating-ui.utils.dom.esm.js implementing environment-safe DOM helpers, overflow ancestor traversal (including iframes), and containing-block detection
  • Add floating-ui.utils.esm.js implementing placement/side/alignment math, padding/rect helpers, and common numeric utilities
  • Ensure all new utilities are exported in a way compatible with the refactored dom/core modules
src/BootstrapBlazor/wwwroot/lib/floating-ui/floating-ui.utils.dom.esm.js
src/BootstrapBlazor/wwwroot/lib/floating-ui/floating-ui.utils.esm.js
Adjust ContextMenu JS to defer popper creation for WASM/MAUI compatibility.
  • Wrap ContextMenu.show logic in setTimeout(0) so DOM references and event data are available in Blazor WASM/MAUI before creating the popper
  • Keep previous behavior of disposing and recreating the popper instance while appending the menu element to document.body
src/BootstrapBlazor/Components/ContextMenu/ContextMenu.razor.js
Make ContextMenuTrigger compatible with IL trimming and linker on WASM/MAUI.
  • Add DynamicDependency attribute on MouseEventArgs for OnContextMenu to preserve public methods during trimming
  • Normalize BOM/license header in ContextMenuTrigger.cs
src/BootstrapBlazor/Components/ContextMenu/ContextMenuTrigger.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#7450 Ensure the ContextMenu in a .NET MAUI BlazorWebView app positions itself near the touch/click location (rather than the bottom-left corner) when running in Release mode on Android using Blazor WebAssembly.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b1b7c0d) to head (73eb15b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7504   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          748       748           
  Lines        32986     32986           
  Branches      4584      4584           
=========================================
  Hits         32986     32986           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@ArgoZhang ArgoZhang merged commit 4fb2a02 into main Jan 14, 2026
6 checks passed
@ArgoZhang ArgoZhang deleted the fix-context branch January 14, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(ContextMenu): positioning fails in release configuration on Android in a dotnet MAUI app

2 participants