fix(native): keep a link's url seed on the tab it opens

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.
This commit is contained in:
laoyh committed 2026-09-19 04:49:39 +08:00
1 parent 1fcf43ccbe
commit 61a3270eb0
2 files changed
+14 -9

No files matched your search

+7 -8
View File
@@ -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<SidebarTab> = {}
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<string, unknown>
: {}
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)!
+7 -1
View File
@@ -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 }),
}