fix: recalculate spotlight overlay position on scroll#920
Open
Niteshagarwal01 wants to merge 1 commit into
Open
fix: recalculate spotlight overlay position on scroll#920Niteshagarwal01 wants to merge 1 commit into
Niteshagarwal01 wants to merge 1 commit 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. |
Contributor
👋 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! 🎉 |
Contributor
✅ 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. |
Author
|
@magic-peach kindly review it and merge it if its ok to you |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛠 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