Skip to content

bug: Ionic Loading Controller: Dismissing loader after navigation unexpectedly restores scroll position (feature request for scroll control) #30352

Open
@alexcarrasco93

Description

@alexcarrasco93

Prerequisites

Ionic Framework Version

v8.x

Current Behavior

"The Ionic LoadingController, when its loader is dismissed shortly after a route navigation event (NavigationEnd, NavigationCancel, or NavigationError), unexpectedly causes the browser to scroll back to the position it was in before the navigation attempt.

This behavior is observed even when the global scrollPositionRestoration in the Angular router is set to 'disabled'.

Interestingly, setting the keyboardClose property of the LoadingController configuration to false prevents this unwanted scroll restoration. However, this seems like an unintended side effect, as keyboardClose is meant to control whether the loader dismisses when the keyboard is shown.

Expected Behavior

The dismissal of the Ionic loader should not interfere with the browser's scroll position, especially when global scroll restoration is disabled. Ideally, the scroll position should remain where it was after the navigation event (e.g., at the top if no specific scroll behavior is implemented).

Steps to Reproduce

  1. Navigate to a page with a significant scroll position (Component A).
  2. Trigger navigation to another page (Component B) that either: Is cancelled (NavigationCancel). Fails (NavigationError).
  3. Ensure an Ionic loader is presented on NavigationStart and dismissed shortly after the navigation event.
  4. Observe that after the loader is dismissed (especially in NavigationCancel or NavigationError scenarios), the browser scrolls back to the scroll position of Component A before the navigation was initiated.

Code Reproduction URL

null

Ionic Info

null

Additional Information

Workaround:

Setting keyboardClose: false in the LoadingController configuration prevents this unwanted scroll restoration. However, this is not an intuitive solution and might have unintended side effects on keyboard handling.

Feature Request:

It would be beneficial to have a dedicated property in the LoadingController configuration (e.g., preventScrollResetOnDismiss: boolean) that explicitly controls whether the loader's dismissal should affect the browser's scroll position. This would provide developers with a clear and intentional way to manage this behavior, independent of the keyboardClose property."

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions