Problem/Motivation

In Drupal 11.3.x, Views AJAX automatically triggers two behaviors:

  • Updates the browser URL using SetBrowserUrl
  • Scrolls to the top of the view using ScrollTopCommand when a pager is present

These behaviors are always enabled and cannot be controlled via the UI.

This creates several issues:

  • Breaks custom frontend logic (SPA-like behavior, manual history handling)
  • Interferes with analytics tracking (e.g., gtag-based navigation tracking)
  • Causes poor UX due to unexpected scroll-to-top behavior, especially on initial load
  • Forces developers to patch core to disable these features

Steps to reproduce

  1. Create a View with:
    • AJAX enabled
    • Pager enabled
  2. Place the View on a page
  3. Load the page and interact with pagination

Observed:

  • URL is automatically updated with query parameters (e.g., ?page=1)
  • View scrolls to top when pager is triggered (and sometimes on initial load depending on implementation)

Proposed resolution

Introduce configurable options in Views UI to control AJAX behavior.

Add new settings under AJAX configuration:

  • update_browser_url (boolean, default: TRUE)
  • scroll_to_top (boolean, default: TRUE)

Update ViewAjaxController to conditionally execute commands:

  • Only trigger ScrollTopCommand when:
    • Pager interaction occurs (page query param exists)
    • AND scroll_to_top is enabled
  • Only trigger SetBrowserUrl when:
    • update_browser_url is enabled

This preserves backward compatibility while allowing flexibility.

Remaining tasks

  • [ ] Add new display options to Views UI (AJAX settings section)
  • [ ] Define schema for new configuration options
  • [ ] Update ViewAjaxController logic to respect settings
  • [ ] Add functional/kernel tests for:
    • URL update toggle
    • Scroll behavior toggle
  • [ ] Update documentation
  • [ ] Provide backward compatibility coverage

User interface changes

Add two checkboxes under Views → Advanced → AJAX settings:

  • [ ] Update browser URL on AJAX requests (default: checked)
  • [ ] Scroll to top on pager interaction (default: checked)

No changes to existing UI behavior unless user modifies settings.

Introduced terminology

None.

API changes

  • New optional display configuration:
    • ajax_settings.update_browser_url
    • ajax_settings.scroll_to_top
  • No breaking API changes
  • Existing behavior remains default

Data model changes

  • Add new configuration keys to Views display configuration
  • Requires updates to Views schema definition

Release notes snippet

Views AJAX behavior is now configurable. Site builders can disable automatic browser URL updates and scroll-to-top behavior via new options in the Views UI. This improves flexibility for custom frontend integrations and user experience control.

Comments

yusuf_khan created an issue. See original summary.

yusuf_khan’s picture

Issue summary: View changes
quietone’s picture

Version: 11.3.x-dev » main

For Drupal core, it is preferred that contributors add a comment that they are working on an issue instead of assigning it to themselves. See Assigning ownership of a Drupal core issue.

yusuf_khan’s picture

Thanks for the clarification.Unassigned