Skip to content

fix(ScrollArea): clear scrollbar registration on unmount so corner stays in sync - #2670

Merged
zernonia merged 1 commit into
v2from
fix/scroll-area-corner-hover-2669
May 30, 2026
Merged

zernonia merged 1 commit into
v2from
fix/scroll-area-corner-hover-2669

Conversation

@zernonia

@zernonia zernonia commented May 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #2669

Problem

With type="hover" and both scrollbars enabled, the ScrollAreaCorner syncs correctly on the first hover cycle but permanently disappears from the second cycle onward.

Root cause

ScrollAreaScrollbarX/Y register their element into the root context on mount but never clear it on unmount:

onMounted(() => {
  if (scrollbarElement.value)
    rootContext.onScrollbarXChange(scrollbarElement.value)
})

Radix's React original does this via a ref-callback, which fires with the node on mount and null on unmount. The Vue port dropped the unmount half.

Since hover mounts/unmounts the scrollbars each cycle, scrollbarX/scrollbarY stayed truthy after the first leave, so the corner's condition !!scrollbarX.value && !!scrollbarY.value never went false and ScrollAreaCornerImpl never unmounted. Its ResizeObserver is bound to the scrollbar element captured once at setup, so on the second hover the corner pointed at a now-detached element and failed to re-render — the "stuck at false on cycle 2" reported in the issue.

Fix

Add onUnmounted cleanup in both scrollbars to reset the registration, mirroring the React ref-callback semantics. The corner now unmounts with the scrollbars on leave and re-mounts fresh (re-binding its observer to the live element) on each enter.

Tests

Added a regression test in ScrollArea.test.ts that drives two hover cycles on a both-scrollbars + corner setup. It fails before the fix (corner stuck mounted after leave) and passes after. Full core suite passes (1642 passed, 3 skipped).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed a regression where the scrollbar corner would not properly re-appear during repeated hover interactions with multiple scrollbars.
    • Improved cleanup of scrollbar references when components unmount to prevent stale states.
  • Tests

    • Added regression test for ScrollArea with multiple scrollbars during hover cycles.

Review Change Stack

…ays in sync

ScrollAreaScrollbarX/Y registered their element into the root context on
mount but never cleared it on unmount. Radix's React original does this via
a ref-callback that fires with the node on mount and `null` on unmount; the
Vue port dropped the unmount half.

With type="hover" the scrollbars mount/unmount every hover cycle. Because
scrollbarX/scrollbarY were never reset, the corner's visibility condition
stayed true after the first leave, so ScrollAreaCornerImpl never unmounted.
Its ResizeObserver is bound to the scrollbar element captured once at setup,
so on the second hover the corner pointed at a detached element and failed
to re-render.

Add onUnmounted cleanup in both scrollbars to reset the registration.

Fixes #2669

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c62618f9-ebd9-4125-bc56-829225a856bd

📥 Commits

Reviewing files that changed from the base of the PR and between 04799b6 and a68deae.

📒 Files selected for processing (3)
  • packages/core/src/ScrollArea/ScrollArea.test.ts
  • packages/core/src/ScrollArea/ScrollAreaScrollbarX.vue
  • packages/core/src/ScrollArea/ScrollAreaScrollbarY.vue

📝 Walkthrough

Walkthrough

This PR fixes a reactivity bug where ScrollAreaCorner loses visibility on the second and subsequent hover cycles. The root cause is stale scrollbar references remaining in rootContext after unmount. The fix registers onUnmounted cleanup hooks in both scrollbar components to clear their references, and adds a regression test validating correct corner behavior across repeated hover cycles.

Changes

ScrollArea Corner Hover State

Layer / File(s) Summary
Scrollbar unmount cleanup registration
packages/core/src/ScrollArea/ScrollAreaScrollbarX.vue, packages/core/src/ScrollArea/ScrollAreaScrollbarY.vue
Both scrollbar components now import and register onUnmounted hooks to clear their scrollbar references (onScrollbarXChange(null) and onScrollbarYChange(null) respectively) from rootContext when unmounting, preventing stale references during hover cycles.
Hover corner visibility regression test
packages/core/src/ScrollArea/ScrollArea.test.ts
New test suite for type="hover" with both scrollbars and corner includes a mock ResizeObserver for jsdom compatibility, HTML prototype dimension/scroll overrides, and a regression assertion verifying corner content correctly appears on first enter, disappears on leave, and re-appears on second enter without losing context state.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 The scrollbars now clean up after themselves,
No stale ghosts haunting context shelves.
The corner dances on every hover's call,
First, second, third—it shows up for 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 accurately summarizes the main fix: clearing scrollbar registration on unmount to keep the corner synchronized across hover cycles.
Linked Issues check ✅ Passed All code changes directly address issue #2669: ScrollAreaScrollbarX/Y now clear their registrations on unmount (via onUnmounted), and the test validates the fix across repeated hover cycles.
Out of Scope Changes check ✅ Passed All changes are scoped to the ScrollArea component's scrollbar unmount behavior and its associated regression test; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/scroll-area-corner-hover-2669

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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 and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented May 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/reka-ui@2670

commit: a68deae

@zernonia
zernonia merged commit 7698318 into v2 May 30, 2026
8 checks passed
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.

[Bug]: ScrollAreaCorner loses rootContext state (scrollbar X/Y references evaluate to false) on second and subsequent hover cycles

1 participant