Skip to content

fix: debounce toolbar hover events to stop flickering (#1330)#1338

Merged
giswqs merged 2 commits into
masterfrom
fix-issue-1330
Jul 4, 2026
Merged

fix: debounce toolbar hover events to stop flickering (#1330)#1338
giswqs merged 2 commits into
masterfrom
fix-issue-1330

Conversation

@giswqs

@giswqs giswqs commented Jul 4, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #1330.

The toolbar (wrench icon) expands/collapses on hover via ipyevents mouseenter/mouseleave events that swap the widget's children. In webview-based frontends such as VS Code Jupyter, swapping the children re-renders the widget, which itself fires another mouseenter/mouseleave. That creates a feedback loop: expand → re-render → leave → collapse → re-render → enter → expand … so the toolbar flickers rapidly and needs multiple clicks to open.

Fix

Add throttle_or_debounce="debounce" with a 250 ms wait to every toolbar hover ipyevents.Event (18 handlers across toolbar.py, all sharing the same pattern). Debouncing coalesces the rapid enter/leave storm into a single settled event, so the child swap only happens after the mouse stops moving — breaking the re-render → event feedback loop.

  • Click-to-toggle is unaffected (that path is a separate ToggleButton observer, not debounced).
  • Genuine hover still expands, just after the mouse settles (~250 ms), which also reduces accidental triggering.

Testing

  • python -m py_compile leafmap/toolbar.py — OK.
  • Smoke test: leafmap.Map() builds with the toolbar; throttle_or_debounce/wait kwargs validated against ipyevents 2.0.4.

The flicker is specific to webview frontends (VS Code) and is not reproducible in a headless browser, so this relies on the mechanism above rather than an automated end-to-end check. Reporter (@meetk3011) can confirm in VS Code.

Summary by CodeRabbit

  • Bug Fixes
    • Improved toolbar hover responsiveness across the app, reducing flicker/jitter when moving between toolbar buttons and tool panels.
    • Standardized hover behavior across multiple toolbars for more consistent expand/collapse interactions and fewer redundant hover-triggered updates.
  • Chores
    • Updated the event-handling dependency to ensure reliable toolbar hover behavior with a minimum supported version.

The toolbar expand/collapse is driven by ipyevents mouseenter/mouseleave
events that swap the widget's children. In webview-based frontends such as
VS Code Jupyter, swapping the children re-renders the widget, which in turn
fires another mouseenter/mouseleave, creating a feedback loop that makes the
toolbar flicker rapidly and require multiple clicks to open.

Add `throttle_or_debounce="debounce"` with a 250 ms `wait` to every toolbar
hover Event so the child swap only happens after the mouse events settle,
breaking the re-render -> event feedback loop while leaving click-to-toggle
unaffected.

Fixes #1330
Copilot AI review requested due to automatic review settings July 4, 2026 20:40
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a84c6fa5-b9c9-44a0-958c-edf6017354dc

📥 Commits

Reviewing files that changed from the base of the PR and between 2aea6b5 and a8a9000.

📒 Files selected for processing (2)
  • leafmap/toolbar.py
  • requirements.txt

📝 Walkthrough

Walkthrough

leafmap/toolbar.py now routes toolbar hover handling through a shared debounced helper, and the ipyevents dependency is constrained to >=0.8.0 in requirements.txt.

Changes

Toolbar hover debounce

Layer / File(s) Summary
Shared hover helper
leafmap/toolbar.py, requirements.txt
Adds hover debounce constants and _toolbar_hover_event(), and pins ipyevents to a minimum version.
Toolbar hover callsites
leafmap/toolbar.py
All toolbar builders listed in the diff now use the shared hover helper instead of creating inline hover events.

Estimated code review effort: 2 (Simple) | ~10 minutes

Related Issues: #1330

Poem

A rabbit tapped the toolbar rail,
And flicker vanished from the trail.
Hover now waits, calm and small,
While debounced paws delight them all. 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: debouncing toolbar hover events to fix flickering.
Linked Issues check ✅ Passed The PR debounces the toolbar hover handlers and supports the runtime dependency needed to fix the flicker in #1330.
Out of Scope Changes check ✅ Passed The changes stay focused on the toolbar hover fix and its dependency constraint, with no unrelated code paths introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-issue-1330

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mergify

mergify Bot commented Jul 4, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses toolbar flickering in webview-based Jupyter frontends (e.g., VS Code Jupyter) by debouncing ipyevents hover handlers so rapid mouseenter/mouseleave storms don’t trigger repeated widget re-renders and feedback loops.

Changes:

  • Adds throttle_or_debounce="debounce" and wait=250 to all toolbar hover ipyevents.Event registrations in leafmap/toolbar.py.
  • Standardizes hover handling behavior across the various toolbar/widget builders that use the same expand/collapse-on-hover pattern.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread leafmap/toolbar.py Outdated
Comment thread leafmap/toolbar.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@leafmap/toolbar.py`:
- Around line 550-555: The hover debounce setup for toolbar widgets is
duplicated in multiple toolbar-building functions, making `ipyevents.Event`
configuration hard to maintain. Create a shared helper such as
`_hover_toolbar_event(widget, wait=250)` that returns the debounced
mouseenter/mouseleave event, then replace each inline `ipyevents.Event(...)`
block in the toolbar constructors with that helper so the shared config lives in
one place.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 679aa78f-61cf-4027-920b-a9a52f08d4da

📥 Commits

Reviewing files that changed from the base of the PR and between d201b04 and 2aea6b5.

📒 Files selected for processing (1)
  • leafmap/toolbar.py

Comment thread leafmap/toolbar.py Outdated
- Pin ipyevents>=0.8.0 in requirements.txt. The debounce kwargs
  (wait / throttle_or_debounce) have been supported since ipyevents 0.8.0,
  so pinning the minimum guarantees pip upgrades an older install and the
  new kwargs cannot raise a TypeError at runtime (Copilot).
- Centralize the debounced hover-event configuration in a single
  _toolbar_hover_event() factory plus TOOLBAR_HOVER_DEBOUNCE_MS /
  TOOLBAR_HOVER_MODE constants, and use it across all 18 toolbar hover
  handlers instead of duplicating the wait=250 / "debounce" literals (Copilot).
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot temporarily deployed to pull request July 4, 2026 20:46 Inactive
@github-actions github-actions Bot temporarily deployed to pull request July 4, 2026 20:52 Inactive
@giswqs giswqs merged commit d0b96cf into master Jul 4, 2026
21 checks passed
@giswqs giswqs deleted the fix-issue-1330 branch July 4, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leafmap toolbar control keep flickering

2 participants