Skip to content

fix(native-windows): switch to list tab on embedded editor back navigation - #952

Open
CookieDarb wants to merge 2 commits into
WordPress:trunkfrom
CookieDarb:fix/native-window-editor-back-nav
Open

CookieDarb wants to merge 2 commits into
WordPress:trunkfrom
CookieDarb:fix/native-window-editor-back-nav

Conversation

@CookieDarb

@CookieDarb CookieDarb commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #951

Fixes the issue where clicking the back button (e.g. "View Pages" / "View Posts") inside an embedded "Add New" editor tab does not return to the list view.

Why?

Native windows (like Posts and Pages) embed administrative pages (such as Gutenberg's Add New editor) via synthetic iframes inside native tab containers rather than top-level shell windows. Because synthetic iframes lack the shell-managed Window.iframe binding that routes through src/window/iframe-bridge.ts, in-frame navigation events (os-iframe-admin-link) posted by the chromeless bridge were ignored.

When a user clicked the back button to return to the list view, the event was dropped, leaving the user unable to return to the item list from within the editor interface.

How?

  • src/native-windows.ts:
    • Added an os-iframe-admin-link listener in buildIframeContentRender() for synthetic iframe message dispatches.
    • Implemented same-window resolution via resolveNativeUrlRemap(): when the admin URL maps back to the current window, it extracts the target tab (supporting os_tab parameter with a fallback to the primary list tab) and triggers a tab switch via os-tabs in place.
    • Added support to delegate cross-window remaps to tryNativeUrlRemap() and fallback unmapped admin links to windowManager.open().
  • tests/vitest/native-window-iframe-admin-link.test.ts:
    • Added targeted Vitest tests covering same-window tab switching with os_tab, delegation to other native windows, classic window fallback, and listener teardown cleanup.

Testing Instructions

  1. Open the native Pages or Posts window.
  2. Switch to the Add New tab to load the embedded Gutenberg editor.
  3. Click the back button ( "View Pages" / "View Posts") in the editor toolbar.
  4. Verify that the window smoothly switches back to the list tab.
  5. Verify that clicking an admin link pointing to another window or section correctly remaps or opens the corresponding window.

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Diagnosing the root cause, aligning the implementation and adding tests. Final review and edits were made by me.

Open Question

When navigating back, should we prompt for unsaved changes or rely on keeping the tab mounted? Currently, switching tabs preserves the editor state in memory without destroying drafts.

Open WordPress Playground Preview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native Windows: Back navigation ("View Posts" / "View Pages") in embedded "Add New" editor is not responding

1 participant