From 33c5f82c43fbe9da901490d1aeda6182e189b09a Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 10 Mar 2026 11:56:22 +0000 Subject: [PATCH] :bug: Fix penpot.openPage() to navigate in same tab by default - Change the default for the newWindow param from true to false, so openPage() navigates in the same tab instead of opening a new one - Accept a UUID string as the page argument in addition to a Page object, avoiding the need to call penpot.getPage(uuid) first - Add validation error when an invalid page argument is passed Signed-off-by: Andrey Antukh --- CHANGES.md | 1 + frontend/src/app/plugins/api.cljs | 11 ++++++++--- frontend/src/app/plugins/page.cljs | 2 +- plugins/libs/plugin-types/index.d.ts | 6 +++--- plugins/libs/plugins-runtime/src/lib/api/index.ts | 4 ++-- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a55bcfed02..6d52b2b01f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -41,6 +41,7 @@ - Fix crash in select component when options vector is empty [Github #8578](https://github.com/penpot/penpot/pull/8578) - Fix scroll on colorpicker [Taiga #13623](https://tree.taiga.io/project/penpot/issue/13623) - Fix crash when pasting non-map transit clipboard data [Github #8580](https://github.com/penpot/penpot/pull/8580) +- Fix `penpot.openPage()` plugin API not navigating in the same tab; change default to same-tab navigation and allow passing a UUID string instead of a Page object [Github #8520](https://github.com/penpot/penpot/issues/8520) ## 2.13.3 diff --git a/frontend/src/app/plugins/api.cljs b/frontend/src/app/plugins/api.cljs index 14effac100..febb24e4ba 100644 --- a/frontend/src/app/plugins/api.cljs +++ b/frontend/src/app/plugins/api.cljs @@ -540,9 +540,14 @@ :openPage (fn [page new-window] - (let [id (obj/get page "$id") - new-window (if (boolean? new-window) new-window true)] - (st/emit! (dcm/go-to-workspace :page-id id ::rt/new-window new-window)))) + (let [id (cond + (page/page-proxy? page) (obj/get page "$id") + (string? page) (uuid/parse* page) + :else nil) + new-window (if (boolean? new-window) new-window false)] + (if (nil? id) + (u/display-not-valid :openPage "Expected a Page object or a page UUID string") + (st/emit! (dcm/go-to-workspace :page-id id ::rt/new-window new-window))))) :alignHorizontal (fn [shapes direction] diff --git a/frontend/src/app/plugins/page.cljs b/frontend/src/app/plugins/page.cljs index e6c9f95bab..b0302a1939 100644 --- a/frontend/src/app/plugins/page.cljs +++ b/frontend/src/app/plugins/page.cljs @@ -269,7 +269,7 @@ (u/display-not-valid :openPage "Plugin doesn't have 'content:read' permission") :else - (let [new-window (if (boolean? new-window) new-window true)] + (let [new-window (if (boolean? new-window) new-window false)] (st/emit! (dcm/go-to-workspace :page-id id ::rt/new-window new-window))))) :createFlow diff --git a/plugins/libs/plugin-types/index.d.ts b/plugins/libs/plugin-types/index.d.ts index 75861797bf..f1b1595aec 100644 --- a/plugins/libs/plugin-types/index.d.ts +++ b/plugins/libs/plugin-types/index.d.ts @@ -1256,15 +1256,15 @@ export interface Context { /** * Changes the current open page to given page. Requires `content:read` permission. - * @param page the page to open - * @param newWindow if true opens the page in a new window + * @param page the page to open (a Page object or a page UUID string) + * @param newWindow if true opens the page in a new window, defaults to false * * @example * ```js * context.openPage(page); * ``` */ - openPage(page: Page, newWindow?: boolean): void; + openPage(page: Page | string, newWindow?: boolean): void; /** * Aligning will move all the selected layers to a position relative to one diff --git a/plugins/libs/plugins-runtime/src/lib/api/index.ts b/plugins/libs/plugins-runtime/src/lib/api/index.ts index b24c2328f3..1ecbbafb59 100644 --- a/plugins/libs/plugins-runtime/src/lib/api/index.ts +++ b/plugins/libs/plugins-runtime/src/lib/api/index.ts @@ -336,9 +336,9 @@ export function createApi( return plugin.context.createPage(); }, - openPage(page: Page, newWindow?: boolean): void { + openPage(page: Page | string, newWindow?: boolean): void { checkPermission('content:read'); - plugin.context.openPage(page, newWindow ?? true); + plugin.context.openPage(page, newWindow ?? false); }, alignHorizontal(