Skip to content

Commit 0d1b201

Browse files
committed
Fix content jumping on Opera mobile browsers
Add Opera browser detection to scroll restoration logic to fix content jumping issue when scrolling on Opera on iPhone. Opera has similar scroll behavior to Safari and needs the same scroll restoration fix. This sets history.scrollRestoration to 'auto' for Opera browsers, preventing the content jumping issue. Fixes #7777
1 parent 55a265c commit 0d1b201

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/pages/_app.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ export default function MyApp({Component, pageProps}: AppProps) {
3535
useEffect(() => {
3636
// Taken from StackOverflow. Trying to detect both Safari desktop and mobile.
3737
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
38-
if (isSafari) {
38+
// Detect Opera (desktop uses OPR, mobile may use Opera in user agent)
39+
const isOpera = /OPR|Opera/i.test(navigator.userAgent);
40+
if (isSafari || isOpera) {
3941
// This is kind of a lie.
4042
// We still rely on the manual Next.js scrollRestoration logic.
41-
// However, we *also* don't want Safari grey screen during the back swipe gesture.
43+
// However, we *also* don't want Safari/Opera grey screen during the back swipe gesture.
4244
// Seems like it doesn't hurt to enable auto restore *and* Next.js logic at the same time.
45+
// Opera on mobile has similar scroll behavior issues as Safari, so it needs the same fix.
4346
history.scrollRestoration = 'auto';
4447
} else {
4548
// For other browsers, let Next.js set scrollRestoration to 'manual'.

0 commit comments

Comments
 (0)