Scrolling fix#1208
Conversation
Added check to observeElementOffset to prevent continuous re-renders
📝 WalkthroughWalkthroughA guard is added in ChangesobserveElementOffset Rerender Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 `@packages/virtual-core/src/index.ts`:
- Around line 782-788: The current code in the scroll offset handling block only
calls maybeNotify() when the offset equals the current scrollOffset, but fails
to notify when the offset actually changes (offset !== this.scrollOffset). This
prevents onChange notifications from being emitted during normal scroll updates.
Add a notification call (maybeNotify()) for the case where the offset differs
from this.scrollOffset to ensure virtual range updates are properly triggered.
This fix should be applied to both occurrences mentioned, including the one
around line 814.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 555ddbcd-1cbe-4be9-8450-226ab25e8ff7
📒 Files selected for processing (2)
.changeset/cold-ads-lose.mdpackages/virtual-core/src/index.ts
piecyk
left a comment
There was a problem hiding this comment.
@dracofulmen Hi, could you clarify what "continuous re-renders" means concretely here, what's measured as re-rendering, and under what interaction?
Basic maybeNotify is memoized on [isScrolling, startIndex, endIndex], so a scroll event at an unchanged offset can't cause a re-render unless isScrolling toggles (the range can't have moved)
|
@piecyk I'm using |
Hmm, that looks off. Could you prepare a reproducible example on stackblitz using the minimal example you mentioned, so we can investigate further? Once we have that, we can dig into why isScrolling remains stuck. |
|
@piecyk Here's the stackblitz reproduction |
Added check to observeElementOffset to prevent continuous re-renders
🎯 Changes
Currently,
observeElementOffsetcausesisScrollingto get stuck as true for as long asoffset > 0. This causes continuous rerenders even after scrolling stops. Thethis.maybeNotify();call also causes continuous rerenders while scrolling. Both of these issues cause the scroll bar to flicker. This fix adds a check to make sure that scrolling only causes notifications once, when the scrolling stops.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit