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.

bug: Page is automatically scroll up to the top of the screen when ion-list is updating from a backend service call.

See original GitHub issue

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x
  • Nightly

Current Behavior

When ion-list is updating from a backend call, page (ion-content) is automatically scroll to the top of the page from the current location.

Expected Behavior

Page(ion-content) should stay on it’s current location when the list is updated from a backend call.

Steps to Reproduce

Steps: npm install

Go to the ‘server’ folder inside repo and run node dummyServer to run the dummy server. (port number is 8887) Change URL from src/app/const/const.enum.ts if needed.

Then run, ionic serve

go to the bottom of the page and wait until service call completed.

Code Reproduction URL

https://github.com/mandis2010/auto-scrollup

Ionic Info

Ionic:

Ionic CLI : 6.19.0 Ionic Framework : @ionic/angular 6.1.6 @angular-devkit/build-angular : 13.2.6 @angular-devkit/schematics : 13.2.6 @angular/cli : 13.2.6 @ionic/angular-toolkit : 6.1.0

Capacitor:

Capacitor CLI : 3.5.1 @capacitor/android : not installed @capacitor/core : 3.5.1 @capacitor/ios : not installed

Utility:

cordova-res : 0.15.4 native-run : 1.6.0

System:

NodeJS : v14.17.6 npm : 6.14.15 OS : Windows 10

Additional Information

Below same issue is happening for me as well. This issue is happing only after upgrading to IONIC 6.

Click Here

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lincolnthreecommented, May 24, 2022

@mandis2010 I noticed you are not using trackBy in your *ngFor loop. This may be the cause of your issue, as without trackBy, Angular will re-render the entire list, rather than only refreshing and updating as needed.

This could cause an issue where the list is temporarily blank/empty, and the list height is reduced to 0px, at which point scroll will be reset and you’ll be back at the top because the list no longer exceeds the height of the page. Essentially the the page is “too short” to stay scrolled down.

https://dzone.com/articles/how-to-use-trackby-with-ngfor-in-angular-8

You could also try setting a manual CSS height on your list to verify this.

1reaction
DwieDimacommented, May 23, 2022

Your reproduction URL returns 404. Is your project private? And you could try this suggestion

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: Bug? Odd behavior with automatically moving view
When I click on the first 11 that are listed in the OOB "SC Categories" widget, the page snaps back to the top...
Read more >
ionic 2 + angular 2 : auto scroll to bottom of list / page / chat
I want that one "chat" segment the page auto-scroll to the bottom with no effect. The chat is a <ion-list> with several <ion-item>...
Read more >
iPhone 12 Max Pro Randomly scrolling up - Apple Community
My new iPhone 12 Pro Max is acting up. It's 2 weeks old and on WhatsApp, Facebook and Safari it randomly scrolls up....
Read more >
Bootstrap Scroll To Top Button - free examples & tutorial
Scroll Back To Top link built with Bootstrap 5. Create a button that appears when you start scrolling and on click smooth scrolls...
Read more >
How to Build Your First Ionic 6 App with API Calls
On top of the basics we will also implement infinite scroll so we can go through a ... Use the CLI to generate...
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