From 61a3270eb0dec1edec0b34d44ce89a5cde1ef560 Mon Sep 17 00:00:00 2001 From: laoyh Date: Sat, 19 Sep 2026 04:49:39 +0800 Subject: [PATCH] fix(native): keep a link's url seed on the tab it opens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clicking an external link opened the sidebar's browser tab with an empty address bar. Three sites dropped the URL: - `openTab` built the native surface's tab record from `path` and `diff` only, ignoring the seed's `url`. - The native tab adapter did the same when minting a record on first open. - Navigating a record that already existed stored the URL in `meta.url`, which no view reads. The browser view takes its address from `tab.path` and writes navigations back to that same field, so every path left the bar empty. Each site now resolves `path ?? url` into `path`, and the dead `meta.url` copy goes with the change that made it unnecessary. The comparison is parenthesised deliberately: `??` binds looser than `===`, so the unparenthesised form sends a present `path` into the empty-object branch and loses it — measured while writing this change. The bottom-workbench branch already resolved the url onto `path`; it is left as it was. --- src/client/native/tab-adapter.tsx | 15 +++++++-------- src/client/service.ts | 8 +++++++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/client/native/tab-adapter.tsx b/src/client/native/tab-adapter.tsx index 89bfa218..8c100bda 100644 --- a/src/client/native/tab-adapter.tsx +++ b/src/client/native/tab-adapter.tsx @@ -140,12 +140,16 @@ export function createNativeTabRecords(): NativeTabRecords { if (existing === undefined) { const seeded = params?.title === undefined && params?.meta === undefined ? mint?.() : undefined const meta = params?.meta ?? seeded?.meta + // A url seed lands on `path`: the browser tab reads its address from + // there and persists navigations back to the same field, so a record + // that dropped it opened with an empty address bar. + const path = params?.path ?? params?.url const minted: View = { tab: { id, type: kind as TabType, title: params?.title ?? seeded?.title ?? title, - ...(params?.path === undefined ? {} : { path: params.path }), + ...(path === undefined ? {} : { path }), ...(params?.diff === undefined ? {} : { diff: params.diff }), ...(meta === undefined ? {} : { meta }), }, @@ -161,14 +165,9 @@ export function createNativeTabRecords(): NativeTabRecords { // a browser tab pointed at another URL); the record's identity and any // plugin-side mutation (title/meta from updateTab) stay. const patch: Partial = {} - if (params?.path !== undefined && params.path !== existing.tab.path) patch.path = params.path + const nextPath = params?.path ?? params?.url + if (nextPath !== undefined && nextPath !== existing.tab.path) patch.path = nextPath if (params?.diff !== undefined) patch.diff = params.diff - if (params?.url !== undefined) { - const meta = typeof existing.tab.meta === 'object' && existing.tab.meta !== null - ? existing.tab.meta as Record - : {} - patch.meta = { ...meta, url: params.url } - } if (existing.scope.cwd !== scope.cwd) { views.set(id, { ...existing, scope, tab: { ...existing.tab, ...patch } }) return views.get(id)! diff --git a/src/client/service.ts b/src/client/service.ts index 84dd909a..3f12fc3e 100644 --- a/src/client/service.ts +++ b/src/client/service.ts @@ -914,11 +914,17 @@ export function createBetterSidebarService(store: SidebarStore): BetterSidebarSe // Multi-instance kinds (terminal / browser / side chat / diff) mint a // fresh tab per open; single-instance kinds focus the existing one. const revealIfOpened = descriptor.createTab === undefined + // A url seed lands on `path`: the browser tab reads its address from + // there and persists navigations back to the same field + // (BrowserView's `persist`), so dropping the seed left an opened tab + // with an empty address bar. `path` means the file to open only for + // `editor`, which never carries a url seed. + const componentPath = seed.path ?? seed.url const synthetic: SidebarTab = { id: seed.id ?? minted?.tab.id ?? seed.type, type: seed.type, title, - ...(seed.path === undefined ? {} : { path: seed.path }), + ...(componentPath === undefined ? {} : { path: componentPath }), ...(seed.diff === undefined ? {} : { diff: seed.diff }), ...(seed.meta === undefined && minted?.tab.meta === undefined ? {} : { meta: seed.meta ?? minted?.tab.meta }), }