Skip to content

Commit 2bfb44e

Browse files
committed
fix: satisfy browser tab landing guards
1 parent 6aab02e commit 2bfb44e

3 files changed

Lines changed: 24 additions & 15 deletions

File tree

‎ui/src/components/browser/browser-panel-controller-input.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ describe("BrowserPanelController capture and input ownership", () => {
663663
const previousUrl = "https://example.test/previous";
664664
const { client, request } = createBrowserClient(async (envelope) => {
665665
if (envelope.path === "/act") {
666-
const fn = String(envelope.body?.fn ?? "");
666+
const fn = typeof envelope.body?.fn === "string" ? envelope.body.fn : "";
667667
return fn.includes("history.go")
668668
? { result: true }
669669
: createBrowserPanelTestMetrics(previousUrl, "Previous");

‎ui/src/components/browser/browser-panel-controller.ts‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
paintBrowserPanelOverlay,
3838
type BrowserPanelView,
3939
} from "./browser-panel-surface.ts";
40+
import { reconcileCapturedTab } from "./browser-panel-tabs.ts";
4041
import { normalizeBrowserUrlDraft } from "./browser-url.ts";
4142

4243
const INSPECT_THROTTLE_MS = 120;
@@ -223,19 +224,9 @@ export class BrowserPanelController implements ReactiveController {
223224
shot.url && observedMetrics?.url && shot.url !== observedMetrics.url
224225
? null
225226
: observedMetrics;
226-
const tabIndex = this.tabs.findIndex((tab) => tab.id === targetId);
227-
const tab = this.tabs[tabIndex];
228-
if (tab) {
229-
// Tab snapshots can lag history and in-page navigation. Keep the active
230-
// tab's stable identity aligned with the document this capture owns.
231-
const url = metrics?.url || shot.url || tab.url;
232-
const title = metrics ? metrics.title : tab.title;
233-
if (url !== tab.url || title !== tab.title) {
234-
const tabs = [...this.tabs];
235-
tabs[tabIndex] = { ...tab, title, url };
236-
this.setState("tabs", tabs);
237-
}
238-
}
227+
// Tab snapshots can lag history and in-page navigation. Keep the stable
228+
// identity aligned with the document this capture owns.
229+
this.setState("tabs", reconcileCapturedTab(this.tabs, targetId, metrics, shot.url));
239230
this.setState("view", { targetId, dataUrl, image, url: shot.url, metrics });
240231
if (!this.urlDraftEditing && shot.url) {
241232
this.setState("urlDraft", shot.url);

‎ui/src/components/browser/browser-panel-tabs.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
import { t } from "../../i18n/index.ts";
22
import { renderPanelTabStrip, type PanelTabStripTab } from "../panel-tab-strip.ts";
3-
import type { BrowserPanelTab } from "./browser-client.ts";
3+
import type { BrowserPageMetrics, BrowserPanelTab } from "./browser-client.ts";
4+
5+
export function reconcileCapturedTab(
6+
tabs: BrowserPanelTab[],
7+
targetId: string,
8+
metrics: BrowserPageMetrics | null,
9+
screenshotUrl: string,
10+
): BrowserPanelTab[] {
11+
const tab = tabs.find((entry) => entry.id === targetId);
12+
if (!tab) {
13+
return tabs;
14+
}
15+
const title = metrics?.title ?? tab.title;
16+
const url = metrics?.url || screenshotUrl || tab.url;
17+
if (title === tab.title && url === tab.url) {
18+
return tabs;
19+
}
20+
return tabs.map((entry) => (entry.id === targetId ? { ...entry, title, url } : entry));
21+
}
422

523
function tabLabel(tab: BrowserPanelTab): string {
624
if (tab.title.trim()) {

0 commit comments

Comments
 (0)