Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/window/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions tests/vitest/window-unsaved-navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down
Loading