question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v4 scroll position is not restored

See original GitHub issue

Bug Report

Ionic Info

Ionic:

   ionic (Ionic CLI)          : 4.0.0-rc.9 (C:\Users\xxxx\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework            : @ionic/angular 4.0.0-alpha.7
   @angular-devkit/core       : 0.7.0-rc.0
   @angular-devkit/schematics : 0.7.0-rc.0
   @angular/cli               : 6.1.0-rc.0
   @ionic/ng-toolkit          : 1.0.0-rc.9
   @ionic/schematics-angular  : 1.0.0-rc.9

System:

   NodeJS : v10.5.0 (C:\Program Files\nodejs\node.exe)
   npm    : 5.2.0
   OS     : Windows 10

Describe the Bug The scroll position is not restored when navigating back from a page. If you scroll down a list and then navigate to a detail page and then hit the back button, the scroll position on the originating page is set back to [0, 0], basically loosing the context. This behaviour is really bad for the user experience.

Steps to Reproduce

  1. Run ionic serve
  2. On home page wait until the list loads and scroll down to e.g. to the last list entry.
  3. Click on the list entry and then navigate back from the detail page to the home page.
  4. After navigating back the scroll position is set to [0,0], the previously scroll state is not restored.

Related Code Example reproduction: https://github.com/coonmoo/IonicScrollPosBug

Expected Behavior The scroll position should be correctly restored when navigating back from a page.

Additional Context I tried to fix it with the latest Angular 6.1.0 feature of scrollPositionRestoration, but it does not seem to work. Angular’s ViewportScroller always reports [0,0] scroll position when navigating back. I suppose that is an Ionic issue, because using plain Angular it seems to work (see also https://github.com/angular/angular/issues/24547).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:11
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
mhartingtoncommented, Sep 11, 2018

Hey yall, just chiming in on an update for this.

  1. Why is this happening.

In 6.1 of ngRouter, there was a new API in place for restoring scroll position. Only issue is that the API used the document body to work with scrolling. While this works for typical Angular Apps, it does not work with nested scroll containers, like ion-content.

  1. What can be done.

Similar to how we override the router RouteReuseStrategy class, we can do the same thing for the ViewportScroller API. This is what I’m working on currently and hope to have something to present soon.

5reactions
bashoogzaadcommented, Aug 10, 2018

What is the latest status of this? Should I implement a ViewPortScroller or are you guys at Ionic working on a solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

v4 scroll position is not restored · Issue #14737 · ionic-team ...
The scroll position is not restored when navigating back from a page. If you scroll down a list and then navigate to a...
Read more >
React Router v4 - Keep scrolling position when switching ...
React Router v4 does not provide out of the box support for scroll restoration and as it currently stands they won't either.
Read more >
Restore RecyclerView scroll position | Android Developers
There are several ways to ensure a correct scroll position that you might have adopted. The best one is making sure that you...
Read more >
2 History Tips to Improve Page Experience
Use the scrollRestoration property of history, and state param of pushState/replaceState to restore the scroll position.
Read more >
Scroll Restoration | TanStack Query Docs
Traditionally, when you navigate to a previously visited page on a web browser, you would find that the page would be scrolled to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found