Skip to content

refactor: improve menu-bar overflow detection performance - #12802

Merged
web-padawan merged 6 commits into
mainfrom
refactor/menu-bar-overflow-detection
Sep 22, 2026
Merged

web-padawan merged 6 commits into
mainfrom
refactor/menu-bar-overflow-detection

Conversation

@web-padawan

@web-padawan web-padawan commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Description

Fixes #12783

The collapse loop wrote style on a button and then read its position on the next iteration, and each read forced a full-document layout. The loop now reads every position once, decides by arithmetic which buttons to collapse, and writes all hides in one pass.

  • Moved the measuring and the decision out of __setOverflowItems into __measureButtons and __getCollapsedButtons
    • Positions are mirrored in RTL, so one comparison serves both directions
  • Read the start margin of each button, because the first kept button keeps its own margin in front of the range
  • Read the width of the collapsed buttons before hiding any of them, so that saving the width of a button with a component costs no extra layout
  • Forced layouts per detection when the buttons overflow: 3, down from 4 to 12
  • Added a test that the overflow button position is read once per detection
  • Added a test for the start margin of the first kept button with reverseCollapse

Type of change

  • Refactor

Note

Collapse results are unchanged: 86 integer widths, 1563 fractional widths, 2892 widths across gap, reverseCollapse and direction, and 804 zoom levels under Aura all give the same result as main, in Chromium, Firefox and WebKit on base, Lumo and Aura styles.

🤖 Generated with Claude Code

@web-padawan
web-padawan requested a review from vursen September 22, 2026 08:19
Base automatically changed from refactor/menu-bar-overflow-lock to main September 22, 2026 10:35
@web-padawan
web-padawan force-pushed the refactor/menu-bar-overflow-detection branch 2 times, most recently from cc2e42d to c6f9145 Compare September 22, 2026 11:24
@web-padawan
web-padawan marked this pull request as draft September 22, 2026 11:52
web-padawan and others added 2 commits September 22, 2026 16:24
The collapse loop read `offsetLeft` after every `style` write, and each read
forced a full-document layout. Read every position first, decide by
arithmetic, then write all hides in one pass.

Part of #12783

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@web-padawan
web-padawan force-pushed the refactor/menu-bar-overflow-detection branch from c6f9145 to 66a2983 Compare September 22, 2026 13:30
@web-padawan
web-padawan marked this pull request as ready for review September 22, 2026 13:36

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ Nothing to flag — the changes look good.

@web-padawan web-padawan changed the title refactor: read menu-bar button positions once before hiding any refactor: improve menu-bar overflow detection performance Sep 22, 2026
…itions

The read order test only asserted that no position is read after a button
is hidden, which also holds when no detection runs at all. Count the reads
on both sides of the first hide and require the earlier ones. Move the
`_hasOverflow` spy into the test that uses it and explain the 177px width.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@web-padawan
web-padawan force-pushed the refactor/menu-bar-overflow-detection branch from ee1ff12 to 11531d7 Compare September 22, 2026 14:27
@web-padawan
web-padawan requested a review from vursen September 22, 2026 14:28
Comment thread packages/menu-bar/test/overflow.test.js Resolved
web-padawan and others added 2 commits September 22, 2026 17:48
The overflow button position is read once while the layout is measured, and
once per iteration by a loop that hides buttons as it goes. Counting those
reads with a spy replaces the hand written wrapper around
`getBoundingClientRect`. Narrowing the menu bar from a width where nothing
collapses makes the collapse itself prove that a detection ran.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@web-padawan
web-padawan force-pushed the refactor/menu-bar-overflow-detection branch from 49d0835 to 134581d Compare September 22, 2026 14:53
@sonarqubecloud

Copy link
Copy Markdown

@web-padawan
web-padawan merged commit 901ba41 into main Sep 22, 2026
12 checks passed
@web-padawan
web-padawan deleted the refactor/menu-bar-overflow-detection branch September 22, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vaadin-menu-bar: overflow detection forces one full-document layout per button, and toggles hidden twice per cycle

5 participants