I am experiencing an intermittent issue with scrolling in my React/Next.js application when using Safari on macOS. The scroll functionality works perfectly in other browsers like Chrome and Firefox, but in Safari, the scroll sometimes stops working entirely across the app. This issue seems to occur randomly and is not tied to any specific page or component.
I have tried the following solutions, but the issue persists:
Ensuring proper CSS for scrollable elements:
html, body {
height: 100%;
overflow: auto;
-webkit-overflow-scrolling: touch; /* Smooth scrolling for Safari */
}
.scrollable-container {
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
Debugging fixed or absolute positioning to ensure no elements block scrolling. Checking JavaScript event listeners to ensure no event.preventDefault() is interfering with scroll behavior. Here is an example of how I structure my scrollable components:
<div className="scrollable-container">
{/* Scrollable content */}
</div>
I am using Next.js with React, and the issue occurs across multiple pages. Below is a snippet of one of my pages (Dashboard):
export default function Dashboard() {
useEffect(() => {
// Ensure the body is scrollable
document.body.style.overflow = "auto";
return () => {
// Cleanup on unmount
document.body.style.overflow = "";
};
}, []);
return (
<div className="scrollable-container">
{/* Dashboard content */}
</div>
);
}
Despite these efforts, the issue persists. It seems to be specific to Safari on macOS, and I cannot consistently reproduce it.
Steps to Reproduce:
Open the app in Safari on macOS. Navigate through different pages. Scroll stops working randomly after some time. What I Have Tried:
Adding -webkit-overflow-scrolling: touch to scrollable containers.
Ensuring no event.preventDefault() is blocking scroll events.
Debugging fixed/absolute elements to ensure they don't block scrolling.
Testing in other browsers (works fine in Chrome and Firefox).
Expected Behavior: Scrolling should work consistently across all pages in Safari, as it does in other browsers.
Actual Behavior: Scrolling stops working intermittently in Safari, requiring a page refresh to restore functionality.
Video Link : Video
Question: What could be causing this intermittent scroll issue in Safari, and how can I resolve it? Are there any Safari-specific quirks or debugging techniques I should try?
Any help would be greatly appreciated!