From 7b7b67f6d4384ee055b23c439f62e3ae09c1eacf Mon Sep 17 00:00:00 2001 From: Roberto Aranda Date: Wed, 14 Oct 2026 15:49:39 +0200 Subject: [PATCH] Windows: Reload a saved new post, not an empty draft On WordPress 7.1 the block editor is sent with Document-Isolation-Policy in Chromium, so the shell cannot call the editor frame's location.reload(). The title-bar Reload then fell back to re-assigning the iframe's src. A window opened on post-new.php keeps that src after the first save, even though the editor has moved itself to post.php?post=N, so Reload opened a brand-new empty draft and the post with its photos looked gone. The fallback now loads the URL the page last reported, which is what the reload already uses everywhere else. --- src/window/index.ts | 11 +++++---- .../vitest/window-unsaved-navigation.test.ts | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/window/index.ts b/src/window/index.ts index 85f1b4431..723844ace 100644 --- a/src/window/index.ts +++ b/src/window/index.ts @@ -2998,10 +2998,13 @@ export class Window { try { iframe.contentWindow?.location.reload(); } catch { - // Cross-origin or detached frame — re-assign src - // as a fallback. The current src is what's already - // loaded, so re-setting it triggers a fresh load. - iframe.src = iframe.src; + // An isolated page (the block editor sends + // `Document-Isolation-Policy`) or a detached frame. + // Load the URL the page last reported, not `src`: + // the editor rewrites its own URL on a first save, + // and `src` would reload post-new.php, an empty new + // draft instead of the post that was just saved. + iframe.src = withChromelessParam( reloadedUrl ) ?? iframe.src; } }; } else { diff --git a/tests/vitest/window-unsaved-navigation.test.ts b/tests/vitest/window-unsaved-navigation.test.ts index ed93300f2..2b81c5686 100644 --- a/tests/vitest/window-unsaved-navigation.test.ts +++ b/tests/vitest/window-unsaved-navigation.test.ts @@ -187,6 +187,29 @@ describe( 'a navigation the page inside can refuse', () => { expect( win._deferredNavigationCommit ).toBeNull(); } ); + test( 'reload of a frame it cannot reach loads the URL the page reported', async () => { + // The block editor is sent with `Document-Isolation-Policy`, so + // the shell cannot call its `location.reload()`, and a first save + // moves it from post-new.php to the saved post without touching + // `src`. Reloading `src` would open an empty new draft. + const iframe = win.iframe as HTMLIFrameElement; + iframe.src = ADMIN + 'post-new.php?openstation_chromeless=1'; + win._reportedLocation = { + url: ADMIN + 'post.php?post=52&action=edit', + src: iframe.src, + }; + + win.reload(); + await vi.waitFor( () => expect( asked ).toHaveLength( 1 ) ); + answerGuard( false ); + + await vi.waitFor( () => + expect( iframe.src ).toBe( + ADMIN + 'post.php?post=52&action=edit&openstation_chromeless=1', + ), + ); + } ); + test( 'a second reload click cannot slip past the in-flight query', async () => { win.reload(); await vi.waitFor( () => expect( asked ).toHaveLength( 1 ) );