Skip to content

Commit

Permalink
Prevent scroll reset in first transition for fastboot enabled sites
Browse files Browse the repository at this point in the history
  • Loading branch information
jpdombrowski committed Nov 3, 2017
1 parent 252bbb7 commit 44bb233
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions addon/mixins/scroll-operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export default Mixin.create({
* now to resume watching scroll position.
*/
setupController(...args) {
const [ controller ] = args;
const [ controller, _, transition ] = args;

this._super(...args);

if (controller && (!this.get('fastboot') || !this.get('fastboot.isFastBoot'))) {
if (!this._isFirstTransition(transition) && controller && (!this.get('fastboot') || !this.get('fastboot.isFastBoot'))) {
run.schedule('afterRender', null, () => {
$(window).scrollTop(controller.getWithDefault('currentPosition', 0));
this._attachEvents();
Expand Down Expand Up @@ -87,6 +87,15 @@ export default Mixin.create({
return transition && transition.sequence > 1 && transition.hasOwnProperty('urlMethod');
},

/**
* Determine if transition is entry transition.
* The first transition should not scroll to top, in sites served by fastboot
* to prevent an unwatend jump back to top after DOM re-hydration.
*/
_isFirstTransition(transition) {
return this.get('fastboot') && !this.get('fastboot.isFastBoot') && !transition.sequence;
},

/**
* Set currentPosition to $(window).scrollTop value.
*/
Expand Down

0 comments on commit 44bb233

Please sign in to comment.