fix(mobile): pop to home when leaving a host so the back chevron animates backward (#9723)

This commit is contained in:
ye4241 2026-07-26 16:57:25 +08:00 committed by GitHub
parent 81e3c62f19
commit cd4064689d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 7 deletions

View File

@ -4,16 +4,18 @@ import { leaveHostRoute } from './host-route-exit'
function makeRouter() {
return {
replace: vi.fn()
dismissTo: vi.fn()
}
}
describe('leaveHostRoute', () => {
it('returns to home instead of depending on route history', () => {
// Why: dismissTo (not replace) is what makes the chevron animate back like swipe-back, so the
// call shape is the behavior under test, not an implementation detail.
it('dismisses to home instead of depending on route history', () => {
const router = makeRouter()
leaveHostRoute(router)
expect(router.replace).toHaveBeenCalledWith('/')
expect(router.dismissTo).toHaveBeenCalledWith('/')
})
})

View File

@ -1,9 +1,10 @@
type HostRouteExitRouter = {
replace: (href: '/') => void
dismissTo: (href: '/') => void
}
export function leaveHostRoute(router: HostRouteExitRouter): void {
// Why: direct pairing can open /h/:hostId as the root route, and split-view
// detail history is not the host/home screen the header is meant to exit to.
router.replace('/')
// Why: direct pairing can open /h/:hostId as the root route, and split-view detail history is
// not the host/home screen the header is meant to exit to. dismissTo pops to home when it is on
// the stack, so the chevron animates back like swipe-back, and replaces when it is not.
router.dismissTo('/')
}