Skip to content

Optimize back scrolling functionality#8192

Open
Sujaicodes wants to merge 1 commit intosegmentio:developfrom
Sujaicodes:patch-2
Open

Optimize back scrolling functionality#8192
Sujaicodes wants to merge 1 commit intosegmentio:developfrom
Sujaicodes:patch-2

Conversation

@Sujaicodes
Copy link

Refactor scroll handling to use a single optimized listener and improve component handling.

Proposed changes

Refactored the scroll handling logic to use a single shared scroll event listener instead of assigning window.onscroll inside a loop.

Cached the list of components using querySelectorAll once to avoid repeated DOM queries.

Moved scroll state computation outside of component iteration to prevent redundant calculations.

Used classList.toggle for cleaner and more efficient class management.

Added a passive scroll event listener to improve browser scroll performance.

Simplified component click handling while keeping the existing typewriter.scrollToTopClicked() analytics event and smooth scrolling behavior.

These changes improve performance, maintainability, and correctness, especially when multiple components use the data-back-scrolling attribute.

Merge timing

ASAP once approved.
The changes are backward-compatible and do not modify existing behavior or analytics events.

Related issues (optional)

None.
This change focuses on internal performance and code structure improvements for the scroll handling logic.

Refactor scroll handling to use a single optimized listener and improve component handling.
@Sujaicodes Sujaicodes requested a review from a team as a code owner March 14, 2026 21:51
@Sujaicodes Sujaicodes requested a review from rchinn1 March 14, 2026 21:51
@netlify
Copy link

netlify bot commented Mar 14, 2026

Deploy Preview for segment-docs ready!

Name Link
🔨 Latest commit 109e173
🔍 Latest deploy log https://app.netlify.com/projects/segment-docs/deploys/69b5d8629e5969000898ab8c
😎 Deploy Preview https://deploy-preview-8192--segment-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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.

1 participant