Leave preview popup on ajax call

Created on 8 May 2025, 15 days ago

Problem/Motivation

When using the Preview on same page feature for content editing, Drupal displays a confirmation modal when navigating away from the preview. However, this modal is also triggered during in-page AJAX interactions (e.g., filtering, autosubmit forms, autocomplete selections), causing confusion and unnecessary interruptions to the user experience.

This is especially disruptive when working with features like view mode switching, inline form updates, or autocomplete fields that are AJAX-driven but donโ€™t constitute actual navigation away from the page.

Steps to reproduce

  1. Enable content preview for a node type.
  2. Start creating/editing content and preview it.
  3. Trigger an AJAX action, such as:
  • Using an autocomplete field.
  • Changing a view mode that autosubmits.
  • Observe the "Leave preview?" modal incorrectly appears, despite not leaving the page.
  • Proposed resolution

    This patch updates the nodePreviewDestroyLinks and nodePreviewSwitchViewMode behaviors to properly:

    • Detect and handle AJAX requests via ajaxComplete, setting a hasAjaxRun flag.
    • Suppress the leave-preview modal for AJAX-driven interactions
    • Prevent false-positive triggers of the modal during expected UI events.

    Remaining tasks

    • Review JavaScript logic for robustness.
    • Confirm patch fixes the issue across different browsers.
    • Confirm behavior works with modal and non-modal previews.
    ๐Ÿ› Bug report
    Status

    Active

    Version

    10.4 โœจ

    Component

    node system

    Created by

    ๐Ÿ‡ง๐Ÿ‡ชBelgium britt.vanderlinden

    Live updates comments and jobs are added and updated live.
    Sign in to follow issues

    Comments & Activities

    Production build 0.71.5 2024