#14660·wagtail

Preview mode changes during an in-flight iframe load can leave the previous mode displayed

Author: DartDoesDataCreated Sep 30, 2026Updated Oct 1, 2026
Labelsstatus:Needs Review

Preview mode changes during an in-flight iframe load can leave the previous mode displayed

Summary

In Wagtail 7.4.3, selecting another preview mode while the first preview iframe is loading changes the enabled selector and “Preview in new tab” link, but the iframe can remain on the previous mode indefinitely. The interaction is accepted without an error or a subsequent request for the selected mode.

Observed in the native editor on Wagtail 7.4.3, Django 6.0.8, Python 3.14, Playwright 1.63.0 / Chromium 153, on macOS with desktop and mobile viewports. No preview-controller overrides are installed.

Minimal supported configuration

An ordinary Page with two modes is sufficient to exercise this controller path; RoutablePageMixin is not required. This reduced example is provided for reproduction; the runtime observations below come from our application, not a separate run of this example.

python
from wagtail.models import Page


class PreviewModePage(Page):
    template = "home/preview_mode_page.html"
    preview_modes = [("", "Default"), ("alternate", "Alternate")]

    def get_preview_context(self, request, mode_name):
        context = super().get_preview_context(request, mode_name)
        context["selected_mode"] = mode_name or "default"
        return context

home/preview_mode_page.html:

xml
{% load wagtailuserbar %}
<!doctype html>
<html lang="en">
  <head><meta charset="utf-8"><title>Preview mode example</title></head>
  <body>
    <main><h1>Mode: {{ selected_mode }}</h1></main>
    {% wagtailuserbar %}
  </body>
</html>

Steps to reproduce

  1. Add the page type, run its migration, and open a page of that type for editing.
  2. Use browser network throttling with high latency and open the native Preview panel. Wait until the iframe GET for the default mode has started, but before its response finishes loading.
  3. Choose Alternate in the enabled Preview mode selector.
  4. Let the original iframe response finish. Stop editing and observe the panel.

Expected: the iframe eventually renders the latest requested mode, or the control prevents a mode change until it can be honored.

Actual: the selector says Alternate and the new-tab link contains mode=alternate, while the iframe continues to display Mode: default. There is no follow-up iframe request. A later form edit or opening the new-tab link can update the preview, but the original selection itself has been dropped.

Evidence

Our browser trace showed an initial successful iframe request ending in ?mode=&in_preview_panel=true. While that response was loading, the selector changed to our second mode (full) and the new-tab href changed to ?mode=full. The iframe retained the default output and made no mode=full request. This occurred in both desktop and mobile Chromium tests.

A deterministic delayed-response regression reproduced this on both desktop and mobile Chromium on 2026-09-30 (UTC). It delays only delivery of the first real iframe response, selects the second mode, releases the response, and requires the second mode's content. It neither replaces the rendered document nor mocks the preview controller. Both runs accepted the enabled mode control and updated the link, then failed because the requested output never appeared. The request list in each run contained only the original iframe GET:

/cms/pages/4/edit/preview/?mode=&in_preview_panel=true

The separate settled-flow tests pass when mode selection happens after the initial iframe has rendered. Here is the essential Playwright timing control (assuming page is already signed in on the edit form and edit is its URL):

javascript
let started, release;
const firstRequest = new Promise(resolve => { started = resolve; });
const firstResponse = new Promise(resolve => { release = resolve; });
let held = false;
await page.route(`**${edit}preview/**`, async route => {
  if (route.request().method() !== "GET" || held) return route.continue();
  held = true;
  const response = await route.fetch();
  started();
  await firstResponse;
  await route.fulfill({ response });
});
await page.getByRole("button", { name: "Toggle preview", exact: true }).click();
await firstRequest;
await page.getByLabel("Preview mode", { exact: true }).selectOption("alternate");
release();
await expect(page.frameLocator("#w-preview-iframe").getByRole("heading", {
  name: "Mode: alternate", exact: true
})).toBeVisible();

The reduced alternate example above is an adaptation of the verified application test, which uses mode full and asserts its complete-document heading. No claim is made that the reduced example itself was run.

Relevant controller paths

This appears related to #14121 and its fix #14129: that change reschedules edits which set staleValue while an update is pending. The mode selection path does not set staleValue, so that recovery does not cover it.

This is distinct from #10585, where RoutablePageMixin.serve_preview() ignores the server-side mode hooks. Here the selected mode renders correctly when requested after the first preview finishes; the lost interaction is in the native client-side update lifecycle.

The corresponding controller source was also inspected at v8.0 and main commit 705dd679. Those paths still call the update method without marking a mode change stale; the v8.0 controller file matches v7.4.3. Neither 8.0 nor main was tested at runtime.