-
Notifications
You must be signed in to change notification settings - Fork 27.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swipe back on mobile browser with getInitialProps flickers the previous page #10465
Comments
See my comments on #9833 |
This can be reproduced with desktop Safari as well. |
Here's an extremely simple isolated example: https://github.com/guigrpa/bug-report-nextjs-flicker (no dependencies apart from React and Next, latest versions of both). |
Having the same issue here Anyone knows exact reason why this happens?? it is because you swiped back the page before the page was rendered completely? |
same issue. |
above example, even though i add seven, fast swiping back to index page from data page makes a very short flickering. |
Any ETA on when this will be worked on/fixed? Does anybody know of any temporary workarounds? |
Any updates on this? I only have this issue on iPhones. |
@dirkjf personally, the approach I went for was invalidating the snapshot of the page that webkit generates.
|
Any updates on that? |
Same thing happens also with "getServerSideProps". Flickering happens only on IOS, on swipe, even with the "useSnapshotInvalidation" hack mentioned above by @TTiole. I still haven't found anything working for me. "next": "^13.1.2" |
Anybody has found a solution to this? The issue also appears when you try to implement modal close (via hash). The most annoying thing is not the flicker, but that in between frames while flickering it's showing Modal Close=>Model Open=>Modal close. Using both slightScroll with alternator mentioned above and document.body.style.opacity switch, but the issue persists. |
(on iOS both Chrome and Firefox also use Safari’s webkit browser engine, afaik.) |
I hope someone from vercel explains the reason for this bug |
I think this bug is because when you swipe back in Safari on iOS it uses a screenshot of the previous page during the transition but then Safari automatically refreshes the previous page once you get there. |
Any updates? This doesn't seem to be a frequent issue so there must be a specific reason why this starts happening... |
Same issue here, and it's very annoying for the users. Especially image flickering is hard on the eyes :/ |
Any updates on this? This happens on every page that is server-side rendered. To recap since the video link in the OP is broken:
I am using server-side rendering for both page A and page B. |
Related issues on other repos: |
It’s not directly an issue with NextJS (more of an SPA issue), but NextJS could/should implement a default way to handle this (since it’s so prevalent), which you could opt-out of if you wanted. Some potential workarounds in the meanwhile. I think you can either: To disable the swipe-back gesture in Safari on iOS, you can use JavaScript to prevent the default action of the "touchstart" event. This is possible on iOS 13.4 and later: const element = document.querySelector('div');
element.addEventListener('touchstart', (e) => {
if (e.pageX > 20 && e.pageX < window.innerWidth - 20) return; // Check if near edge
e.preventDefault(); // Prevent swipe to navigate back gesture
}); This code prevents the swipe-back gesture when the touch event starts near the edges of the viewport[1][2]. —- Or: Just make the page transparent before leaving. For example: window.addEventListener('pagehide', () => {
document.body.style.opacity = 0
}) The snapshot will be transparent, so you'll see nothing when swiping. Curtesy of gustavepoch at https://stackoverflow.com/a/72694167 — Or: Hacking scroll position to mess with how Safari (and all other iOS browsers, which has to use Safari’s WebKit under the hood) decides what image to use for its preview of the previous page. Curtesy of Eli at https://stackoverflow.com/a/68491147 —— Citations: |
Bug report
Describe the bug
On mobile browsers (tested with Chrome and Firefox), swiping back or forward on a dynamic page (one that gets data from
getInitialProps
) will sometimes "flash" the previous page while the content is loading. Here is a video that shows the problem.To Reproduce
index.js
data.js
Now, add
"seven"
to the data returned indata.js
, and notice the problem doesn't happen anymoreExpected behavior
No flash of the previous page when swiping forward or backward on mobile browser. This is what happens now vs this is what should happen
System information
The text was updated successfully, but these errors were encountered: