Swipe back on mobile browser with getInitialProps flickers the previous page
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
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
- Create a next.js app with the following pages:
index.js
import Link from "next/link";
export default function Index() {
return (
<div>
<p><Link href="data"><a>Link</a></Link></p>
</div>
);
}
data.js
const Index = props => {
return (
<div>
<h1>Test mobile back</h1>
<ul>
{props.data.map(name => (
<li key={name}>
<a>{name}</a>
</li>
))}
</ul>
</div>
)
};
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
Index.getInitialProps = async function() {
await sleep(1000)
return {
data: ["one", "two", "three", "four", "five", "six"]
};
};
export default Index;
- Run it, and access it with a mobile browser.
- Click on the link, you are now on a page with "one", "two"...
- Swipe back
- Now swipe forward. Notice the "flash" of the previous screen.
Now, add "seven" to the data returned in data.js, and notice the problem doesn't happen anymore
Expected 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
- OS: MacOS
- Browser (if applies): Mobile Safari, chrome and firefox
- Version of Next.js: 9.2.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided index.js and data.js pages, using data.js getInitialProps with its one-second delay and testing swipe navigation on mobile Safari, Chrome, or Firefox. Trace Next.js history navigation and page loading to identify the cause of the previous-page flash; done means swiping back and forward shows no flash while the dynamic content loads.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, next.js
- Domain
- frontend, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100