File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,22 @@ if (typeof window !== 'undefined') {
25
25
26
26
export default function MyApp ( { Component, pageProps} : AppProps ) {
27
27
const router = useRouter ( ) ;
28
+
29
+ React . useEffect ( ( ) => {
30
+ // Taken from StackOverflow. Trying to detect both Safari desktop and mobile.
31
+ const isSafari = / ^ ( (? ! c h r o m e | a n d r o i d ) .) * s a f a r i / i. test ( navigator . userAgent ) ;
32
+ if ( isSafari ) {
33
+ // This is kind of a lie.
34
+ // We still rely on the manual Next.js scrollRestoration logic.
35
+ // However, we *also* don't want Safari grey screen during the back swipe gesture.
36
+ // Seems like it doesn't hurt to enable auto restore *and* Next.js logic at the same time.
37
+ history . scrollRestoration = 'auto' ;
38
+ } else {
39
+ // For other browsers, let Next.js set scrollRestoration to 'manual'.
40
+ // It seems to work better for Chrome and Firefox which don't animate the back swipe.
41
+ }
42
+ } , [ ] ) ;
43
+
28
44
React . useEffect ( ( ) => {
29
45
const handleRouteChange = ( url : string ) => {
30
46
ga ( 'set' , 'page' , url ) ;
You can’t perform that action at this time.
0 commit comments