fix: recalculate spotlight overlay position on scroll#920
fix: recalculate spotlight overlay position on scroll#920Niteshagarwal01 wants to merge 2 commits into
Conversation
|
@Niteshagarwal01 is attempting to deploy a commit to the magic-peach1's projects Team on Vercel. A member of the Team first needs to authorize it. |
👋 Thanks for your PR, @Niteshagarwal01!Welcome to Reframe — a browser-based video editor built for everyone 🎬 What happens next
Quick checklist
Useful links
Happy coding! 🎉 |
✅ PR Format Check Passed — @Niteshagarwal01Basic format checks passed. A maintainer will review your code changes. This does not mean the PR is approved — it just means the format is correct. |
|
@magic-peach kindly review it and merge it if its ok to you |
|
@Niteshagarwal01 The fix concept is solid — separating the However:
Note: PR #1011 by @Arsh-sudo addresses the same issue. If that PR gets merged first, this PR may be closed. We'll merge whichever passes CI first. Steps to fix: git checkout -b fix/spotlight-scroll-tracking
# Apply your changes
git fetch upstream
git rebase upstream/main
git push origin fix/spotlight-scroll-tracking
# Then open a new PR from that branch |
|
@magic-peach fixed the conflicts |
|
@magic-peach bro when the pr is merged tomorrow so why you are messaging me today ? the management on this repo is totally trash |
🛠 Fix: Recalculate Spotlight Overlay Position on Scroll and Resize #913
📝 Description
This PR resolves a visual regression within the
OnboardingTourcomponent where the spotlight overlay (<Spotlight />) detaches from its targeted DOM element when the user scrolls or resizes the viewport.🐛 The Bug
During the onboarding flow, the highlighted spotlight rectangle uses absolute coordinates computed via
getBoundingClientRect()at the exact moment a tour step is initialized.<svg>overlay uses afixedinset positioning layout, scrolling the page causes the underlying target element to shift relative to the viewport while the SVG mask remains stationary. This results in the spotlight illuminating unrelated content.measureTargetfunction. BecausemeasureTargetusesscrollIntoView({ behavior: "smooth" })to ensure the targeted element is visible, any window resize implicitly forced the browser to hijack the user's scroll position, resulting in a jarring UX.💡 The Solution
This PR decouples the "scrolling into view" logic from the coordinate recalculation logic, ensuring the spotlight dynamically tracks its target frame by frame without coercively scrolling the page.
Key Changes:
Separation of Concerns (
updatePosition)Introduced a pure
updatePositioncallback that safely retrieves the active target element (document.getElementById) and updates thetargetRectstate purely usinggetBoundingClientRect()without any side effects.Capture-Phase Scroll Listener
Added a
scrollevent listener to the window. Crucially, this listener is attached withuseCapture: true(window.addEventListener("scroll", handler, true)). Since scroll events on inner overflow containers do not bubble up to the window, the capturing phase is required to ensure we detect scrolling occurring within any nested scrollable area.Performance Optimization (
requestAnimationFrame)Scroll and resize events can fire at extremely high frequencies. To prevent layout thrashing and state-update bottlenecks, the
handleUpdateevent handler wrapsupdatePositioninsiderequestAnimationFrame. Existing frames are cleanly cancelled to guarantee the recalculation strictly binds to the browser's native rendering cycle.Refactored
useEffectTeardownEnsured no memory leaks by securely cleaning up both the
scroll(with matchinguseCaptureboolean) andresizeevent listeners alongside canceling any lingering animation frames on component unmount.📸 Expected Behavior
🧪 Steps to Test
localStoragekeyreframe_onboarding_completeis cleared).scrollIntoViewjump.Closes #913