Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): allow consecutive mobile parent returns (#1050)

Generf9d2102890bc
diff --git a/scripts/ci/e2e-shards.mjs b/scripts/ci/e2e-shards.mjs
index 07c19f532..153464d61 100644
--- a/scripts/ci/e2e-shards.mjs
+++ b/scripts/ci/e2e-shards.mjs
@@ -84,6 +84,7 @@ export const SPEC_SECONDS = {
"60-desktop-default-user-bar-width.spec.ts": 83.700,
"63-mobile-notification-chat-route.spec.ts": DEFAULT_SPEC_SECONDS,
"64-billing-contact.spec.ts": 6,
+ "64-mobile-parent-return.spec.ts": DEFAULT_SPEC_SECONDS,
"65-analytics-document-boundary.spec.ts": DEFAULT_SPEC_SECONDS,
"66-public-static-resource-cache.spec.ts": DEFAULT_SPEC_SECONDS,
}
diff --git a/scripts/ci/e2e-shards.test.ts b/scripts/ci/e2e-shards.test.ts
index 925646b05..60c986018 100644
--- a/scripts/ci/e2e-shards.test.ts
+++ b/scripts/ci/e2e-shards.test.ts
@@ -75,20 +75,23 @@ describe("planE2eShards", () => {
expect(first).toEqual(second)
expect(Object.keys(SPEC_SECONDS).sort()).toEqual(specs)
- expect(first).toHaveLength(16)
+ expect(first).toHaveLength(17)
expect([...assigned].sort()).toEqual(specs)
expect(new Set(assigned).size).toBe(specs.length)
expect(SPEC_SECONDS["18-new-divider-scroll.spec.ts"]).toBe(DEFAULT_SPEC_SECONDS)
expect(SPEC_SECONDS["55-message-scroll-characterization.spec.ts"]).toBe(DEFAULT_SPEC_SECONDS)
expect(SPEC_SECONDS["66-public-static-resource-cache.spec.ts"]).toBe(DEFAULT_SPEC_SECONDS)
+ expect(SPEC_SECONDS["64-mobile-parent-return.spec.ts"]).toBe(DEFAULT_SPEC_SECONDS)
+ expect(first.find((shard) => shard.files.includes("64-mobile-parent-return.spec.ts"))?.files)
+ .toEqual(["64-mobile-parent-return.spec.ts"])
expect(first.find((shard) => shard.files.includes("66-public-static-resource-cache.spec.ts"))?.files)
.toEqual(["66-public-static-resource-cache.spec.ts"])
expect(specSeconds).toEqual([
- 165, 165, 165, 165, 165, 165, 155.638, 154.234, 155.283,
+ 165, 165, 165, 165, 165, 165, 165, 155.638, 154.234, 155.283,
156.095, 155.905, 156.323, 155.711, 153.963, 154.488, 156.138,
])
expect(predictedSeconds).toEqual([
- 240, 240, 240, 240, 240, 240, 230.638, 229.234, 230.283,
+ 240, 240, 240, 240, 240, 240, 240, 230.638, 229.234, 230.283,
231.095, 230.905, 231.323, 230.711, 228.963, 229.488, 231.138,
])
expect(first.every((shard) => (
diff --git a/src/web/src/components/community/shell/mobile-page.dom.test.tsx b/src/web/src/components/community/shell/mobile-page.dom.test.tsx
index a35c0249d..0acfd5f36 100644
--- a/src/web/src/components/community/shell/mobile-page.dom.test.tsx
+++ b/src/web/src/components/community/shell/mobile-page.dom.test.tsx
@@ -30,7 +30,7 @@ function fixture() {
resolveAndPush: vi.fn(async () => true), cancelPendingNavigation: vi.fn(),
}
const frame = { ...normalizeCommunityHref(navigation.publishedHref), revision: 0 }
- function Fixture({ active = true, children = <input aria-label="Page draft" /> }: { active?: boolean; children?: ReactNode }) {
+ function Fixture({ active = true, parentPath = "/c/me", children = <input aria-label="Page draft" /> }: { active?: boolean; parentPath?: string; children?: ReactNode }) {
runtime = useCommunityRuntime()
const registry = useMemo(() => ({ register: (next: MobilePageBack) => {
request = next
@@ -38,7 +38,7 @@ function fixture() {
} }), [])
return <CommunityRouteContext value={{ breakpoint, navigation, frame, ownerDeleteRouteScope: undefined }}>
<MobilePageBackContext value={registry}>
- <MobilePage active={active} parentPath="/c/me">{children}</MobilePage>
+ <MobilePage active={active} parentPath={parentPath}>{children}</MobilePage>
</MobilePageBackContext>
</CommunityRouteContext>
}
@@ -57,9 +57,17 @@ function holdExit(popup: HTMLElement) {
}
describe("mobile page dismissal", () => {
- it.each([{ userAgent: "iPhone", start: 8 }, { userAgent: "Android WebView", start: 80 }])("follows an inline $userAgent page touch inside a vertical scroller, cancels, then commits one parent Back", async ({ userAgent, start }) => {
+ it.each([
+ { userAgent: "iPhone", start: 8 },
+ { userAgent: "Android WebView", start: 80 },
+ ].flatMap(device => ["none", "parent", "forward"].map(pending => ({ ...device, pending }))))("follows an inline $userAgent page touch (pending=$pending) with the current navigation authority", async ({ userAgent, start, pending }) => {
vi.spyOn(navigator, "userAgent", "get").mockReturnValue(userAgent)
const task = fixture()
+ if (pending !== "none") {
+ task.navigation.navigationPending = true
+ task.navigation.pendingHref = task.navigation.publishedHref
+ task.navigation.entryIntent = { href: task.navigation.publishedHref, resume: pending === "parent" }
+ }
render(<task.Fixture><div style={{ overflowY: "auto" }} data-testid="page-scroll"><div data-testid="page-touch">Page body</div></div></task.Fixture>)
const area = screen.getByTestId("page-touch")
const popup = area.closest<HTMLElement>('[data-slot="mobile-page"]')!
@@ -81,6 +89,12 @@ describe("mobile page dismissal", () => {
touch("touchstart", start, 100)
touch("touchmove", 170, 300)
touch("touchmove", 220, 500)
+ if (pending === "forward") {
+ expect(popup).not.toHaveAttribute("data-swiping")
+ expect(popup).toHaveAttribute("data-open")
+ expect(task.replace).not.toHaveBeenCalled()
+ return
+ }
expect(popup).toHaveAttribute("data-swiping")
expect(popup.style.transform).toContain("50px")
touch("touchcancel", 220, 700)
@@ -293,4 +307,30 @@ describe("mobile page dismissal", () => {
expect(popup.closest('[data-mobile-page-active="false"]')).toHaveAttribute("inert")
expect(task.back()).toBeUndefined()
})
+
+ it("retires a closing callback when the page becomes an inactive background", async () => {
+ const task = fixture()
+ const view = render(<task.Fixture />)
+ const popup = screen.getByLabelText("Page draft").closest<HTMLElement>('[data-slot="mobile-page"]')!
+ const animation = holdExit(popup)
+ act(() => { task.back() })
+ await waitFor(() => expect(animation.animations).toHaveBeenCalled())
+ view.rerender(<task.Fixture active={false} />)
+ await act(async () => animation.finish())
+ expect(task.replace).not.toHaveBeenCalled()
+ expect(task.back()).toBeUndefined()
+ })
+
+ it("retires a closing callback when the verified parent changes", async () => {
+ const task = fixture()
+ const view = render(<task.Fixture />)
+ const popup = screen.getByLabelText("Page draft").closest<HTMLElement>('[data-slot="mobile-page"]')!
+ const animation = holdExit(popup)
+ act(() => { task.back() })
+ await waitFor(() => expect(animation.animations).toHaveBeenCalled())
+ view.rerender(<task.Fixture parentPath="/c/channels/s1" />)
+ await act(async () => animation.finish())
+ expect(task.replace).not.toHaveBeenCalled()
+ expect(popup).toHaveAttribute("data-open")
+ })
})
diff --git a/src/web/src/components/community/shell/mobile-page.tsx b/src/web/src/components/community/shell/mobile-page.tsx
index 1c75ca454..9f8d4aa80 100644
--- a/src/web/src/components/community/shell/mobile-page.tsx
+++ b/src/web/src/components/community/shell/mobile-page.tsx
@@ -6,6 +6,7 @@ import { MobilePageBackContext } from "@/contexts/community/mobile-page-back"
import { useCommunityWsStore } from "@/stores/community/ws"
import { useCommunityRuntime } from "@/stores/community/runtime"
import { requestNativeBack } from "@/components/ui/native-back-layer"
+import { hasPendingParentReturn } from "./use-community-navigation-controller"
import { SwipeRoot, SwipePortal, SwipeViewport, SwipePopup } from "@/components/ui/swipe-container"
export function MobilePage({ children, parentPath, active = true, backgroundVisible = true }: {
@@ -19,33 +20,36 @@ export function MobilePage({ children, parentPath, active = true, backgroundVisi
const accessEpoch = useCommunityWsStore((state) => state.accessEpoch)
const runtime = useCommunityRuntime()
const [open, setOpen] = useState(breakpoint !== "mobile")
- const pending = useRef<(() => boolean) | null>(null)
+ const pending = useRef<{ parentPath: string; isCurrent: () => boolean } | null>(null)
const departed = useRef(false)
const mobile = breakpoint === "mobile"
+ const parentReturnPending = hasPendingParentReturn(navigation)
const request = useCallback((target: string) => {
if (!active || !mobile || target !== parentPath) return false
if (pending.current) return true
if (requestNativeBack(document) !== "none") return false
- const current = navigation.captureIntent()
- pending.current = () => runtime.lifecycle.get().active && runtime.ws.get().accessEpoch === accessEpoch
- && window.matchMedia("(max-width: 639px)").matches && current()
+ const current = navigation.captureIntent(parentReturnPending && navigation.pendingHref
+ ? { pendingCommitHref: navigation.pendingHref } : undefined)
+ pending.current = { parentPath, isCurrent: () => runtime.lifecycle.get().active && runtime.ws.get().accessEpoch === accessEpoch
+ && window.matchMedia("(max-width: 639px)").matches && current() }
setOpen(false)
return true
- }, [accessEpoch, active, mobile, navigation, parentPath, runtime])
+ }, [accessEpoch, active, mobile, navigation, parentPath, parentReturnPending, runtime])
useLayoutEffect(() => {
if (mobile && departed.current && (navigation.pendingHref === parentPath || navigation.publishedHref === parentPath)) return
+ if (mobile && active && pending.current?.parentPath === parentPath && pending.current.isCurrent()) return
departed.current = false
pending.current = null
setOpen(true)
- return () => { pending.current = null }
- }, [mobile, active, frame.revision, navigation.pendingHref, navigation.publishedHref, accessEpoch, parentPath])
+ }, [mobile, active, frame.revision, navigation.entryIntent, navigation.pendingHref, navigation.publishedHref, accessEpoch, parentPath])
+ useLayoutEffect(() => () => { pending.current = null }, [])
useLayoutEffect(() => {
if (!mobile || !active) return
return registry?.register(request)
}, [active, mobile, registry, request])
return <div inert={!active} aria-hidden={!active || undefined} data-mobile-page-active={active}
hidden={!active && (!mobile || !backgroundVisible)} className="flex min-h-0 min-w-0 flex-1 flex-col max-sm:absolute max-sm:inset-0">
- <SwipeRoot kind="page" open={open} swipeEnabled={mobile && active && !navigation.navigationPending}
+ <SwipeRoot kind="page" open={open} swipeEnabled={mobile && active && (!navigation.navigationPending || parentReturnPending)}
onOpenChange={(next, details) => {
if (next) return
if (details.reason !== "swipe" || !request(parentPath)) details.cancel()
@@ -54,7 +58,7 @@ export function MobilePage({ children, parentPath, active = true, backgroundVisi
if (next) return
const valid = pending.current
pending.current = null
- if (valid?.()) {
+ if (valid?.parentPath === parentPath && valid.isCurrent()) {
departed.current = true
navigation.replace(parentPath, { resume: true })
}
diff --git a/src/web/src/components/community/shell/shell-frame.dom.test.ts b/src/web/src/components/community/shell/shell-frame.dom.test.ts
index e2e2c478a..99d4b2068 100644
--- a/src/web/src/components/community/shell/shell-frame.dom.test.ts
+++ b/src/web/src/components/community/shell/shell-frame.dom.test.ts
@@ -196,7 +196,7 @@ const returnPost = `${returnRoot}/post`
vi.mock("@/components/community/channels/channel-route", () => ({
ChannelRoute: ({ channelId, routeCommitted }: { channelId: string; routeCommitted: boolean }) => {
- const parentPath = channelId === "post" ? returnForum : returnRoot
+ const parentPath = channelId === "post" ? returnForum : channelId === "thread" ? `${returnRoot}/text` : returnRoot
return createElement(MobilePage, { parentPath },
createElement("div", { "data-testid": `return-leaf-${channelId}`, "data-route-committed": String(routeCommitted) },
createElement("button", { onClick: () => mocks.registerUiHandlers.mock.calls.at(-1)![0].goBackMobile(parentPath) }, `Back ${channelId}`)))
@@ -263,17 +263,19 @@ function holdReturnExit(popup: HTMLElement) {
return { finish, animations }
}
-function renderPostReturnLifecycle({ strict = false } = {}) {
+function renderPostReturnLifecycle({ strict = false, child = "post", parent = "forum" } = {}) {
+ const childHref = `${returnRoot}/${child}`
+ const parentHref = `${returnRoot}/${parent}`
mocks.lifecycle = true
mocks.breakpoint.current = "mobile"
- mocks.currentHref.current = returnPost
- mocks.selectedHref.current = returnPost
- mocks.projectedChannel.current = { id: "post", serverId: "s1", parentChannelId: "forum" }
+ mocks.currentHref.current = childHref
+ mocks.selectedHref.current = childHref
+ mocks.projectedChannel.current = { id: child, serverId: "s1", parentChannelId: parent }
vi.spyOn(window, "matchMedia").mockImplementation(media => ({
media, matches: media === "(max-width: 639px)", onchange: null,
addListener() {}, removeListener() {}, addEventListener() {}, removeEventListener() {}, dispatchEvent: () => false,
}))
- let frameHref = returnPost
+ let frameHref = childHref
let context!: ReturnType<typeof useCommunityRouteFrame>
let runtime!: ReturnType<typeof useCommunityRuntime>
function Capture() {
@@ -294,28 +296,32 @@ function renderPostReturnLifecycle({ strict = false } = {}) {
commit(href: string, { frame = true, published = true } = {}) {
if (frame) { frameHref = href; mocks.selectedHref.current = href }
if (published) mocks.currentHref.current = href
- mocks.projectedChannel.current = frameHref === returnPost
- ? { id: "post", serverId: "s1", parentChannelId: "forum" }
- : frameHref === returnForum ? { id: "forum", serverId: "s1", parentChannelId: null } : undefined
+ mocks.projectedChannel.current = frameHref === childHref
+ ? { id: child, serverId: "s1", parentChannelId: parent }
+ : frameHref === parentHref ? { id: parent, serverId: "s1", parentChannelId: null } : undefined
renderer.rerender(node())
},
}
}
-async function returnToProjectedForum(options: { strict?: boolean } = {}) {
+async function returnToProjectedForum(options: { strict?: boolean; child?: string; parent?: string } = {}) {
+ const child = options.child ?? "post"
+ const parent = options.parent ?? "forum"
+ const childHref = `${returnRoot}/${child}`
+ const parentHref = `${returnRoot}/${parent}`
const task = renderPostReturnLifecycle(options)
- const exit = holdReturnExit(screen.getByTestId("return-leaf-post").closest<HTMLElement>("[data-slot='mobile-page']")!)
- fireEvent.click(screen.getByRole("button", { name: "Back post" }))
+ const exit = holdReturnExit(screen.getByTestId(`return-leaf-${child}`).closest<HTMLElement>("[data-slot='mobile-page']")!)
+ fireEvent.click(screen.getByRole("button", { name: `Back ${child}` }))
expect(mocks.replace).not.toHaveBeenCalled()
await waitFor(() => expect(exit.animations).toHaveBeenCalled())
await act(async () => exit.finish())
- await waitFor(() => expect(screen.getByTestId("return-leaf-forum")).toBeVisible())
- expect(screen.getByTestId("return-leaf-forum")).toHaveAttribute("data-route-committed", "false")
- expect(task.context.frame.href).toBe(returnPost)
- expect(task.context.navigation.publishedHref).toBe(returnPost)
- expect(task.context.navigation.pendingHref).toBe(returnForum)
+ await waitFor(() => expect(screen.getByTestId(`return-leaf-${parent}`)).toBeVisible())
+ expect(screen.getByTestId(`return-leaf-${parent}`)).toHaveAttribute("data-route-committed", "false")
+ expect(task.context.frame.href).toBe(childHref)
+ expect(task.context.navigation.publishedHref).toBe(childHref)
+ expect(task.context.navigation.pendingHref).toBe(parentHref)
expect(task.context.navigation.navigationPending).toBe(true)
- expect(mocks.replace.mock.calls.map(args => args[0])).toEqual([returnForum])
+ expect(mocks.replace.mock.calls.map(args => args[0])).toEqual([parentHref])
return task
}
@@ -860,44 +866,86 @@ describe("ShellFrame orchestration", () => {
})
describe("accepted mobile parent return", () => {
- it.each(["button", "system"] as const)("does not reopen the old post when %s Back repeats before parent publication", async (entry) => {
- const task = await returnToProjectedForum()
- repeatBack(entry, "forum")
- expect(mocks.replace.mock.calls.slice(1).map(args => args[0])).not.toContain(returnPost)
- expect(mocks.replace.mock.calls.map(args => args[0])).toEqual([returnForum])
- expect(task.context.navigation.pendingHref).toBe(returnForum)
+ it.each([
+ { entry: "button", child: "post", parent: "forum" },
+ { entry: "system", child: "post", parent: "forum" },
+ { entry: "button", child: "thread", parent: "text" },
+ { entry: "system", child: "thread", parent: "text" },
+ ] as const)("continues $child through its displayed $parent on $entry Back before parent publication", async ({ entry, child, parent }) => {
+ const task = await returnToProjectedForum({ child, parent })
+ const exit = holdReturnExit(screen.getByTestId(`return-leaf-${parent}`).closest<HTMLElement>("[data-slot='mobile-page']")!)
+ repeatBack(entry, parent)
+ repeatBack(entry, parent)
+ await waitFor(() => expect(exit.animations).toHaveBeenCalled())
+ await act(async () => exit.finish())
+ expect(mocks.replace.mock.calls.map(args => args[0])).toEqual([`${returnRoot}/${parent}`, returnRoot])
+ expect(task.context.navigation.pendingHref).toBe(returnRoot)
+ expect(screen.getByRole("button", { name: "Outside action" })).toBeVisible()
+ task.commit(`${returnRoot}/${parent}`)
+ expect(task.context.navigation.pendingHref).toBe(returnRoot)
expect(task.context.navigation.navigationPending).toBe(true)
- expect(screen.queryByTestId("return-leaf-post")).toBeNull()
- task.commit(returnForum)
+ expect(screen.queryByTestId(`return-leaf-${child}`)).toBeNull()
+ expect(screen.getByTestId(`return-leaf-${parent}`)).not.toBeVisible()
+ task.commit(returnRoot)
await waitFor(() => expect(task.context.navigation.navigationPending).toBe(false))
- expect(task.context.frame.href).toBe(returnForum)
- expect(screen.queryByTestId("return-leaf-post")).toBeNull()
- expect(screen.getByTestId("return-leaf-forum")).toBeVisible()
+ expect(task.context.frame.href).toBe(returnRoot)
})
- it("keeps the accepted parent return through StrictMode lifecycle replay", async () => {
+ it("continues the accepted parent return through StrictMode lifecycle replay", async () => {
const task = await returnToProjectedForum({ strict: true })
+ const exit = holdReturnExit(screen.getByTestId("return-leaf-forum").closest<HTMLElement>("[data-slot='mobile-page']")!)
repeatBack("button", "forum")
- expect(mocks.replace.mock.calls.map(args => args[0])).toEqual([returnForum])
- expect(task.context.navigation.pendingHref).toBe(returnForum)
- task.commit(returnForum)
+ await waitFor(() => expect(exit.animations).toHaveBeenCalled())
+ await act(async () => exit.finish())
+ expect(mocks.replace.mock.calls.map(args => args[0])).toEqual([returnForum, returnRoot])
+ task.commit(returnRoot)
await waitFor(() => expect(task.context.navigation.navigationPending).toBe(false))
- expect(screen.getByTestId("return-leaf-forum")).toBeVisible()
+ expect(screen.getByRole("button", { name: "Outside action" })).toBeVisible()
})
- it.each(["frame-first", "publication-first"] as const)("coalesces repeated Back until the complete parent return, %s", async (order) => {
+ it.each(["frame-first", "publication-first", "during-exit"] as const)("preserves the next Back when the previous parent commits %s", async (order) => {
const task = await returnToProjectedForum()
task.commit(returnForum, { frame: order === "frame-first", published: order === "publication-first" })
expect(task.context.navigation.navigationPending).toBe(true)
expect(task.context.navigation.pendingHref).toBe(returnForum)
+ const popup = screen.getByTestId("return-leaf-forum").closest<HTMLElement>("[data-slot='mobile-page']")!
+ const exit = holdReturnExit(popup)
repeatBack("button", "forum")
+ await waitFor(() => expect(exit.animations).toHaveBeenCalled())
expect(mocks.replace.mock.calls.map(args => args[0])).toEqual([returnForum])
task.commit(returnForum)
await waitFor(() => expect(task.context.navigation.navigationPending).toBe(false))
- expect(screen.getByTestId("return-leaf-forum")).toBeVisible()
+ expect(popup).toHaveAttribute("data-closed")
+ await act(async () => exit.finish())
+ expect(mocks.replace.mock.calls.map(args => args[0])).toEqual([returnForum, returnRoot])
+ expect(task.context.navigation.pendingHref).toBe(returnRoot)
expect(screen.queryByTestId("return-leaf-post")).toBeNull()
})
+ it("coalesces a repeated destination from the departed page without cancelling the displayed parent", async () => {
+ const task = await returnToProjectedForum()
+ act(() => mocks.registerUiHandlers.mock.calls.at(-1)![0].goBackMobile(returnForum))
+ expect(mocks.replace.mock.calls.map(args => args[0])).toEqual([returnForum])
+ expect(task.context.navigation.pendingHref).toBe(returnForum)
+ expect(screen.getByTestId("return-leaf-forum")).toBeVisible()
+ })
+
+ it.each(["newer intent", "retired owner", "retired access"] as const)("retires a second closing return after a %s", async (boundary) => {
+ const task = await returnToProjectedForum()
+ const exit = holdReturnExit(screen.getByTestId("return-leaf-forum").closest<HTMLElement>("[data-slot='mobile-page']")!)
+ repeatBack("button", "forum")
+ await waitFor(() => expect(exit.animations).toHaveBeenCalled())
+ task.commit(returnForum)
+ act(() => {
+ if (boundary === "newer intent") task.context.navigation.push(`${returnRoot}/other`)
+ else if (boundary === "retired owner") task.retireOwner()
+ else task.retireAccess()
+ })
+ await act(async () => exit.finish())
+ expect(mocks.replace.mock.calls.map(args => args[0])).toEqual([returnForum])
+ expect(task.context.navigation.pendingHref).not.toBe(returnRoot)
+ })
+
it("returns from a fully committed forum to the semantic server list", async () => {
const task = await returnToProjectedForum()
task.commit(returnForum)
diff --git a/src/web/src/components/community/shell/shell-frame.tsx b/src/web/src/components/community/shell/shell-frame.tsx
index 7d5675b32..de6c2cd45 100644
--- a/src/web/src/components/community/shell/shell-frame.tsx
+++ b/src/web/src/components/community/shell/shell-frame.tsx
@@ -299,8 +299,7 @@ const [committedFrame, setCommittedFrame] = useAtom(useCreateAtom(initialCommitt
}, [breakpoint, checkpoint.surface, dismissUserBarExtension, userBarExtension.active])
const parentReturnPending = hasPendingParentReturn(navigation)
const dismissNativeBackShellOverlay = useCallback(() => {
- if (navigation.navigationPending) {
- if (parentReturnPending) return true
+ if (navigation.navigationPending && !parentReturnPending) {
replacePath(committedFrame.href)
return true
}
@@ -318,10 +317,12 @@ const [committedFrame, setCommittedFrame] = useAtom(useCreateAtom(initialCommitt
if (!target) return
if (breakpoint === "mobile") {
if (requestNativeBack(document) !== "none" || dismissNativeBackShellOverlay()) return
+ if (parentReturnPending && navigation.pendingHref
+ && normalizeCommunityHref(target).href === normalizeCommunityHref(navigation.pendingHref).href) return
if (pageBack.current?.(target)) return
navigation.replace(target, { resume: true })
} else navigation.replace(target)
- }, [breakpoint, dismissNativeBackShellOverlay, mobileParentPath, navigation])
+ }, [breakpoint, dismissNativeBackShellOverlay, mobileParentPath, navigation, parentReturnPending])
useNativeMobileBack({
dismissShellOverlay: dismissNativeBackShellOverlay,
diff --git a/src/web/src/test/e2e-ui/64-mobile-parent-return.spec.ts b/src/web/src/test/e2e-ui/64-mobile-parent-return.spec.ts
new file mode 100644
index 000000000..de06b61bd
--- /dev/null
+++ b/src/web/src/test/e2e-ui/64-mobile-parent-return.spec.ts
@@ -0,0 +1,105 @@
+import type { Page, Request, Route } from "@playwright/test"
+import { test, expect } from "./_fixtures/case-fixture"
+import type { CaseResources } from "./_fixtures/case-fixture"
+import { tid } from "./_fixtures/testids"
+
+async function holdParentRoute(page: Page, pathname: string, resources: CaseResources) {
+ let release!: () => void
+ const gate = new Promise<void>(resolve => { release = resolve })
+ const pattern = (url: URL) => url.pathname === pathname
+ let held = 0
+ const pending = new Set<Request>()
+ const continuations: Promise<void>[] = []
+ const settled = (request: Request) => { pending.delete(request) }
+ page.on("requestfinished", settled)
+ page.on("requestfailed", settled)
+ const handler = (route: Route) => {
+ held += 1
+ const request = route.request()
+ pending.add(request)
+ const continuation = (async () => {
+ await gate
+ if (pending.has(request)) await route.continue()
+ })()
+ continuations.push(continuation)
+ return continuation
+ }
+ await page.route(pattern, handler)
+ let finishing: Promise<void> | undefined
+ const finish = () => finishing ??= (async () => {
+ release()
+ await Promise.all(continuations)
+ await page.unroute(pattern, handler)
+ await expect.poll(() => pending.size).toBe(0)
+ page.off("requestfinished", settled)
+ page.off("requestfailed", settled)
+ })()
+ resources.own(finish, async cleanup => cleanup())
+ return { held: () => held, release: finish }
+}
+
+for (const parentType of ["forum", "text"] as const) {
+ for (const input of ["button", "system"] as const) {
+ test(`mobile ${parentType} parent accepts ${input} Back before the previous return commits`, async ({ caseActors, caseResources }, testInfo) => {
+ const actors = await caseActors(["alice"])
+ const { seedServer, seedChannel, seedMessage, seedThread, seedForumThread } = actors.seed
+ const serverId = await seedServer("alice", `Parent return ${parentType} ${input}`)
+ const parentId = await seedChannel("alice", serverId, "return-parent", parentType)
+ const childId = parentType === "forum"
+ ? await seedForumThread("alice", parentId, "Return child", "Child reply")
+ : await seedThread("alice", await seedMessage("alice", parentId, "Thread opener"), "Return child")
+ const rootPath = `/c/channels/${serverId}`
+ const childPath = `${rootPath}/${childId}`
+ const parentPath = `${rootPath}/${parentId}`
+ const { page } = await actors.asUser("alice")
+ await page.setViewportSize({ width: 390, height: 844 })
+ await page.emulateMedia({ reducedMotion: "reduce" })
+
+ if (parentType === "forum" && input === "button") {
+ await page.goto(rootPath, { waitUntil: "commit" })
+ await page.getByTestId(tid.forumSidebarThread(childId)).click()
+ } else await page.goto(childPath, { waitUntil: "commit" })
+
+ const foreground = page.locator('[data-mobile-page-active="true"]')
+ const back = foreground.getByRole("banner").getByRole("button", { name: "Back", exact: true })
+ await expect(back).toBeVisible()
+ const [childResponse, parentResponse] = await Promise.all([
+ page.request.get(new URL(`/api/community/channels/${childId}`, page.url()).href),
+ page.request.get(new URL(`/api/community/channels/${parentId}`, page.url()).href),
+ ])
+ expect(childResponse.status()).toBe(200)
+ expect(parentResponse.status()).toBe(200)
+ const channel = await childResponse.json() as {
+ id: string; serverId: string; parentChannelId: string
+ }
+ const parent = await parentResponse.json() as { id: string; type: string }
+ expect(channel).toMatchObject({ id: childId, serverId, parentChannelId: parentId })
+ expect(parent).toMatchObject({ id: parentId, type: parentType })
+
+ const parentRoute = await holdParentRoute(page, parentPath, caseResources)
+ await back.click({ noWaitAfter: true })
+ await expect.poll(parentRoute.held).toBeGreaterThan(0)
+ await expect(foreground.locator(`[data-community-target-href="${parentPath}"]`)).toBeVisible()
+ expect(new URL(page.url()).pathname).toBe(childPath)
+
+ if (input === "button") await back.click({ noWaitAfter: true })
+ else await page.evaluate(() => window.dispatchEvent(new Event("alook:native-back", { cancelable: true })))
+
+ const parentRow = page.getByTestId(tid.channelRow(parentId))
+ await expect(parentRow).toBeVisible()
+ await expect(page.locator(`[data-mobile-page-active="true"] [data-community-target-href="${childPath}"]`)).toBeHidden()
+ const screenshot = testInfo.outputPath("list-before-parent-release.png")
+ await page.screenshot({ path: screenshot })
+ await testInfo.attach("list-before-parent-release", { path: screenshot, contentType: "image/png" })
+ await parentRoute.release()
+ await expect.poll(() => new URL(page.url()).pathname).toBe(rootPath)
+ await expect(parentRow).toBeVisible()
+ await expect(foreground).toBeHidden()
+ await testInfo.attach("parent-return-result", {
+ body: JSON.stringify({ parentType, input, metadataStatuses: [childResponse.status(), parentResponse.status()], heldParentRequests: parentRoute.held(), finalPath: rootPath,
+ channel: { id: channel.id, serverId: channel.serverId, parentChannelId: channel.parentChannelId }, parent: { id: parent.id, type: parent.type } }),
+ contentType: "application/json",
+ })
+ })
+ }
+}