-
Notifications
You must be signed in to change notification settings - Fork 56
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
scroll position reset on slow loading fastboot served pages #55
Comments
@bcardarella I came to the same conclusion and implemented a small demo which I haven't pushed any where. Are you 100% sure it's because of |
I suspect this line is being hit when app starts: https://github.com/dollarshaveclub/ember-router-scroll/blob/master/addon/services/router-scroll.js#L35 |
Keep in mind we can't simply assume the current x,y position of scroll here. One of the reqs of this lib is to reset the scroll position on each page transition, or reposition if it is in history. So there needs to be a way to distinguish that this is an app instantiation event and ember is taking over from fastboot rendered page. There could be a flag in an initializer for the service that is a |
There are two issues. The first is what @bcardarella pointed out here, which is that this line is resetting the scroll position to However, even if you work around that, there's a second issue (also pointed out by @bcardarella Here's a temporary hack to fix both of these problems. I put the following in my top-level application route:
|
I gave this some thought a while ago, I think we should wait for DOM hydration before making any changes |
Here is another workaround (until DOM hydration lands) for those getting here via Google. The thinking is that we give the body a nice Add a script tag to a file you control, some vanilla JS. <!-- index.html -->
{{content-for 'body'}}
<script src="{{rootURL}}assets/init-scroll.js"></script>
<!-- ^ this one is the important one, should be BEFORE ember scripts download -->
<script src="{{rootURL}}assets/vendor.js"></script> // assets/init-scroll.js
(function() {
if (typeof FastBoot === 'undefined') {
document.body.style['min-height'] = document.body.clientHeight + 'px';
}
}()); Finally, you revert the body // routes/application.js
actions: {
didTransition() {
if (!get(this, 'fastboot.isFastBoot')) {
run.scheduleOnce('afterRender', () => {
document.body.style['min-height'] = '100vh';
});
}
}
} Its not great, obviously DOM hydration will be better. Figured it could help the next person that googles their way to this corner of github. |
I know why this is happening, I'm not sure what the correct solution is yet.
If a page is served with Fastboot the immediate render is available. Then if Ember is slow to instantiate for any reason if you've scrolled down the page when the App starts the scroll position is reset. This is not the correct experience.
I suspect the correct thing to do is if the state is new assume the current scroll position rather than
0,0
The text was updated successfully, but these errors were encountered: