Repository navigation
fix(native-windows): switch to list tab on embedded editor back navigation - #952
Conversation
|
Thanks for tracking this one down, @CookieDarb! A dead back button in the embedded editor is a really good catch, and routing The part I'd change is where the decision lives. Right now the shell finds // src/native-windows.ts, os-iframe-admin-link branch
if ( e.origin !== window.location.origin ) {
return; // same trust boundary as the neighbouring handlers
}
const target = resolveNativeUrlRemapTarget( linkUrl );
const tab = target?.params?.tab;
if ( target?.id === baseId && tab && cfg.onAdminLink?.( linkUrl, tab ) ) {
cfg.onMessage?.( e.data ); // keep forwarding every message
return;
}// apps/posts/parts/app.ts
ui.editor = window.wp?.os?.embedAdminPage?.( host, url, {
onAdminLink: ( _url, tab ) => {
activateTab( ctx, ui, tab );
return true;
},
} ) ?? null;The same-origin check matches the neighbouring handlers. With a new option on |
…editor Add onAdminLink callback option to embedAdminPage so synthetic iframes inside native windows can delegate same-window back navigation to the host app's tab management rather than opening a second window.
|
Hey @epeicher, thanks for the detailed review! That made total sense. I've refactored the PR along those lines:
Also updated the PR description to match the same. Let me know what you think! |
The admin-link routing returned early for links handed to another native window and for links from another origin, so a window's `iframeContent.onMessage` stopped seeing them. That broke the documented contract that every message reaches `onMessage`, and a plugin routing its own links could lose them or, on the fallback path, open the link twice. The routing now lives in `routeAdminLink()` and the handler always falls through to `onMessage`, whichever way the link was routed. Same-origin links only are routed, as before.
epeicher
left a comment
There was a problem hiding this comment.
Thanks @CookieDarb for addressing the comments! I have pushed some small fixes on top and test this, and it LGTM!
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.iframebinding that routes throughsrc/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:os-iframe-admin-linklistener inbuildIframeContentRender()for synthetic iframe message dispatches.resolveNativeUrlRemapTarget( linkUrl ). If the link targets the current window (matchingwindowIdorbaseId), it delegates to the host app'sopts.onAdminLink( linkUrl, tab )callback instead of mutating DOM directly.tryNativeUrlRemap( linkUrl )and falls back unmapped links towindowManager.open().src/desktop.ts:desktop-mode-postsanddesktop-mode-pagesto provide aparamshook returning{ tab: tagged ? tagged : 'posts' }(or'pages'), supplying the target tab dynamically.apps/posts/parts/app.ts:onAdminLink: ( _url, tab ) => { activateTab( ctx, ui, tab ); return true; }toembedAdminPage, letting the Posts app handle its own tab switching.docs/:docs/javascript-reference.md,docs/bridge-protocol.md,docs/examples/native-posts.md, anddocs/api-index.mddocumentingopts.onAdminLinkand remap landing tabs.tests/:tests/vitest/native-window-iframe-admin-link.test.tscovering same-window callback invocation, multi-instance window resolution viabaseId, cross-window remap delegation, unmapped fallbacks, and teardown cleanup.apps/posts/posts.test.tsverifying thatonAdminLinkswitches the Posts app back to the list tab.Testing Instructions
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.