<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/zeit/next.js/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h2 dir="auto">Expected Behaviour</h2>
<p dir="auto">When navigated using <code class="notranslate">&lt;Link scroll={false}&gt;</code> the component below should restore the saved scroll position when the component mounts.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="let scrollY = 0

export default class Thing extends Component {
  constructor(props) {
    super(props)
    this.onScroll = this.onScroll.bind(this)
  }

  onScroll(e) {
    scrollY = window.scrollY
  }
  
  componentDidMount() {
    window.addEventListener('scroll', this.onScroll)
    window.scroll(0, scrollY)
  }

  componentWillUnmount() {
    window.removeEventListener('scroll', this.onScroll)
  }

  ...
}"><pre class="notranslate"><code class="notranslate">let scrollY = 0

export default class Thing extends Component {
  constructor(props) {
    super(props)
    this.onScroll = this.onScroll.bind(this)
  }

  onScroll(e) {
    scrollY = window.scrollY
  }
  
  componentDidMount() {
    window.addEventListener('scroll', this.onScroll)
    window.scroll(0, scrollY)
  }

  componentWillUnmount() {
    window.removeEventListener('scroll', this.onScroll)
  }

  ...
}
</code></pre></div>
<h2 dir="auto">Current Behaviour</h2>
<p dir="auto">The code works on latest Chrome (macOS) and Edge (Windows 10), but fails on Safari 10 (macOS).</p>
<p dir="auto">The behaviour I'm observing in Safari is that the scroll position is first briefly set to my correct saved position, but then another scroll event is fired and the scroll position reset somewhere nearer the top of the page (always the same pixel value). I think it might have something to do with component load order, or a race condition, since I'm observing the problem on a fairly image heavy page.</p>
<h2 dir="auto">Steps to Reproduce (for bugs)</h2>
<p dir="auto">There's a live example here <a href="http://www.gillythomas.co.uk" rel="nofollow">http://www.gillythomas.co.uk</a></p>
<ol dir="auto">
<li>Using Safari 10 visit the site and scroll down the page to near the bottom</li>
<li>Click an image to view a larger version</li>
<li>Click the "back to gallery" button</li>
<li>Observe that the scroll position wasn't properly restored</li>
<li>Try on different browsers, should work well on Chrome for example</li>
</ol>
<h2 dir="auto">Context</h2>
<p dir="auto">This is using the Next.js v3 beta and new static site output feature. I'm just trying to persist the scroll position on a page, but its not working on Safari.</p>
<h2 dir="auto">Your Environment</h2>
<ul dir="auto">
<li>Next.js version: <code class="notranslate">3.0.1-beta.8</code> static export</li>
<li>Environment name and version (e.g. Chrome 39, Node.js 5.4): Safari 10</li>
<li>Operating System (Linux, maxOS, Windows): macOS</li>
</ul>
<h1 dir="auto">Bug report</h1>
<h2 dir="auto">Describe the bug</h2>
<p dir="auto">Dependencies not properly shared across pages and _app.js</p>
<h2 dir="auto">To Reproduce</h2>
<p dir="auto">Create a number of pages. Add a module to _app.js.<br>
Increase the number of times a module is included from once to N times, track progress</p>
<p dir="auto">Takes at least 2 pages for a dep included in _app.js to be factored out.</p>
<h2 dir="auto">Expected behavior</h2>
<p dir="auto">Once a module has been included in _app, it should never be packed again.</p>
<h2 dir="auto">Screenshots</h2>
<p dir="auto">In a 4 page + _app + _document app</p>
<p dir="auto">// _app only  (_app.js includes Auth)<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/5543229/50240340-86039100-0392-11e9-880f-3852dc46ccda.png"><img width="555" alt="screen shot 2018-12-19 at 1 29 25 pm" src="https://user-images.githubusercontent.com/5543229/50240340-86039100-0392-11e9-880f-3852dc46ccda.png" style="max-width: 100%;"></a></p>
<p dir="auto">// 1 page (_app.js + submit.js  include Auth)<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/5543229/50240341-86039100-0392-11e9-8333-0961ac723210.png"><img width="571" alt="screen shot 2018-12-19 at 1 30 22 pm" src="https://user-images.githubusercontent.com/5543229/50240341-86039100-0392-11e9-8333-0961ac723210.png" style="max-width: 100%;"></a></p>
<p dir="auto">// 2 pages (_app.js + submit.js + scorecard.js include Auth)<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/5543229/50240334-7edc8300-0392-11e9-8045-6b643f9fc66f.png"><img width="565" alt="screen shot 2018-12-19 at 1 31 00 pm" src="https://user-images.githubusercontent.com/5543229/50240334-7edc8300-0392-11e9-8045-6b643f9fc66f.png" style="max-width: 100%;"></a></p>
<h2 dir="auto">System information</h2>
<ul dir="auto">
<li>OS: Mac OS X</li>
<li>Version of Next.js: canary, 7.0.2</li>
</ul>
<h2 dir="auto">Additional context</h2>
<p dir="auto">Related to: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="297575727" data-permission-text="Title is private" data-url="https://github.com/vercel/next.js/issues/3818" data-hovercard-type="issue" data-hovercard-url="/vercel/next.js/issues/3818/hovercard" href="https://github.com/vercel/next.js/issues/3818">#3818</a> (though in this case import isn't being exported as in HOC)<br>
Related to: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="185765247" data-permission-text="Title is private" data-url="https://github.com/vercel/next.js/issues/118" data-hovercard-type="issue" data-hovercard-url="/vercel/next.js/issues/118/hovercard" href="https://github.com/vercel/next.js/issues/118">#118</a> and <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="189175432" data-permission-text="Title is private" data-url="https://github.com/vercel/next.js/issues/253" data-hovercard-type="issue" data-hovercard-url="/vercel/next.js/issues/253/hovercard" href="https://github.com/vercel/next.js/issues/253">#253</a></p>
<p dir="auto">Potential solutions: expose or document modifying the threshold for placing a dependency in the common bundle.</p>
<p dir="auto">However, it seems there should be a more intelligent procedure, in which unnecessary data is not bundled for any descendants of _app.js.</p>