Skip to content

Commit 4bb7077

Browse files
committed
fix: clear stale queued navigation recovery
1 parent e45ec90 commit 4bb7077

3 files changed

Lines changed: 30 additions & 18 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ describe("BrowserPanelController tab and lifecycle ownership", () => {
341341
committedNavigation.resolve({ targetId: "raw-stable", url: committedUrl });
342342
await expect(Promise.all([previous, latest])).resolves.toEqual([undefined, undefined]);
343343

344+
expect(controller.activeTargetId).toBeNull();
345+
expect(controller.view).toBeNull();
346+
expect(controller.urlDraft).toBe("");
344347
expect(controller.errorText).toBe("Browser request failed: Original navigation rejected");
345348
expect(controller.loading).toBe(false);
346349
},

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -351,32 +351,31 @@ export class BrowserPanelController implements ReactiveController {
351351
}
352352
} catch (error) {
353353
if (invocation.isCurrent()) {
354-
this.reportError(error);
355354
if (previousNavigationQueued && this.activeTargetId) {
356355
const targetId = this.activeTargetId;
357-
const navigationErrorText = this.errorText;
358356
// An earlier queued navigation may already have committed remotely.
359357
// Recover its actual document without replacing an unchanged view.
360-
try {
361-
const refreshed = await this.refreshTabsOnly(client, () => invocation.isCurrent());
362-
const active = this.tabs.find((tab) => tab.id === targetId);
363-
if (refreshed === "accepted" && invocation.isCurrent() && active) {
364-
await this.refreshView(targetId, invocation.epoch);
365-
if (
366-
invocation.isCurrent() &&
367-
this.view?.targetId === targetId &&
368-
this.errorText === navigationErrorText
369-
) {
370-
this.operations.markNavigationReconciled(client, targetId);
371-
}
358+
const refreshed = await this.refreshTabsOnly(client, () => invocation.isCurrent());
359+
const active = this.tabs.find((tab) => tab.id === targetId);
360+
if (refreshed === "accepted" && invocation.isCurrent() && active) {
361+
this.setState("view", null);
362+
await this.refreshView(targetId, invocation.epoch);
363+
if (invocation.isCurrent() && this.view?.targetId === targetId) {
364+
this.operations.markNavigationReconciled(client, targetId);
372365
}
373-
} catch {
374-
// Recovery is best-effort; retain the original navigation failure.
375366
}
376-
if (invocation.isCurrent()) {
377-
this.reportError(error);
367+
if (
368+
invocation.isCurrent() &&
369+
this.operations.hasUnreconciledNavigation(client, targetId)
370+
) {
371+
this.setState("activeTargetId", null);
372+
this.setState("view", null);
373+
if (!this.urlDraftEditing) {
374+
this.setState("urlDraft", "");
375+
}
378376
}
379377
}
378+
this.reportError(error);
380379
}
381380
} finally {
382381
if (invocation.isCurrent()) {

‎ui/src/components/panel-tab-strip.browser.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ describe.skipIf(!hasBrowserLayout)("panel tab strip browser lifecycle", () => {
105105

106106
expect(reorderedActive).toBe(initialActive);
107107
await vi.waitFor(() => expect(container.activeElement).toBe(initialActive));
108+
109+
renderControlledStrip({
110+
container,
111+
tabs: [tabs[2]!, tab("d"), tabs[1]!, tabs[0]!],
112+
activeId: "b",
113+
onSelect: vi.fn(),
114+
});
115+
const insertedActive = await expectControlledSelection(container, "b");
116+
expect(insertedActive).toBe(initialActive);
117+
expect(container.activeElement).toBe(initialActive);
108118
});
109119

110120
it("keeps arrow and mouse activation controlled and the selected overflow tab visible", async () => {

0 commit comments

Comments
 (0)