mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
fix(browser): keep stopped navigation aligned with the visible document
This commit is contained in:
parent
611cd6be5f
commit
fc06dbf1b4
4 changed files with 18 additions and 4 deletions
|
|
@ -30,6 +30,19 @@ test("only a cross-document main-frame navigation supersedes a gated load", asyn
|
|||
}
|
||||
})
|
||||
|
||||
test("interrupting an unissued restore preserves its address; stopping an agent navigation does not propose one", async () => {
|
||||
for (const [method, restoring, keep, expected] of [["back", "https://saved.test", true, "https://saved.test"], ["forward", "https://saved.test", true, "https://saved.test"], ["stop", undefined, true, "https://saved.test"], ["stop", undefined, false, undefined]] as const) {
|
||||
const gate = Promise.withResolvers<void>()
|
||||
const stopped: (string | undefined)[] = []
|
||||
const navigation = navigationTurn(() => gate.promise, () => {}, () => {}, address => stopped.push(address))
|
||||
const visit = navigation.begin(new AbortController().signal, keep)("https://saved.test", () => { throw Error("load was issued") })
|
||||
navigation.interrupt(method, restoring)
|
||||
gate.resolve()
|
||||
await visit
|
||||
expect(stopped).toEqual([expected])
|
||||
}
|
||||
})
|
||||
|
||||
test("a gated history traversal settles the spinner when Chromium has no load to stop", async () => {
|
||||
const gate = Promise.withResolvers<void>()
|
||||
const events: string[] = []
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ export function navigationTurn(
|
|||
// initial CDP setup waiting for a renderer that the replacement command cannot start until setup finishes.
|
||||
if (method === "reload" && pending && restoring && /^https?:\/\//i.test(restoring)) return restoring
|
||||
|
||||
if (method === "stop" && held !== undefined && heldStop) {
|
||||
// A not-yet-issued initial restore has no committed history entry to traverse.
|
||||
if ((method === "stop" || (restoring && (method === "back" || method === "forward"))) && held !== undefined && heldStop) {
|
||||
const address = held
|
||||
spinning = false
|
||||
cancel()
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ test("Stop before issue publishes the restore address without inventing a commit
|
|||
const address = "https://next.test/report"
|
||||
const restore = createDocumentState({ url: address, title: "Report", generation: 4 })
|
||||
|
||||
for (const before of [restore, replay(visit("https://previous.test/")).state]) {
|
||||
for (const before of [restore, replay(visit("https://previous.test/")).state, replay(visit("file:///workspace/report.html")).state]) {
|
||||
const cancelled = replay([
|
||||
{ type: "navigation.started", isMainFrame: true, isSameDocument: false, url: address },
|
||||
{ type: "loading.started" },
|
||||
|
|
@ -82,7 +82,7 @@ test("Stop before issue publishes the restore address without inventing a commit
|
|||
], before).state
|
||||
|
||||
const saved = documentTab(cancelled, history)
|
||||
expect(saved).toMatchObject({ id: history.id, url: address, loading: false })
|
||||
expect(saved).toMatchObject({ id: history.id, url: before.status === "loaded" ? before.url : address, loading: false })
|
||||
expect(saved).not.toHaveProperty("loadError")
|
||||
expect(documentVisible(cancelled)).toBe(documentVisible(before))
|
||||
expect(documentTab(cancelled, history, false)).toEqual(documentTab(before, history, false))
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ export function transitionDocument(state: DocumentState, event: DocumentEvent):
|
|||
|
||||
switch (event.type) {
|
||||
case "navigation.held-stopped":
|
||||
return settle(state, { ...state, retry: event.address, busy: false, pending: undefined }, [PUBLISH])
|
||||
return settle(state, { ...state, retry: state.status === "loaded" ? undefined : event.address, busy: false, pending: undefined }, [PUBLISH])
|
||||
case "disposed":
|
||||
return { state: CLOSED, effects: [] }
|
||||
case "loading.started":
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue