swipe bug fix

This commit is contained in:
2026-03-28 10:00:52 -04:00
parent f50f2aaba1
commit abd4574ee3
3 changed files with 18 additions and 8 deletions

View File

@@ -455,11 +455,15 @@ export default function Chat() {
setUnreadGroups(prev => { const next = new Map(prev); next.delete(id); return next; });
};
// Establish one history sentinel on mount (mobile only) so back gestures are
// always interceptable without accumulating extra entries.
// Establish two history entries on mount (mobile only):
// floor — marks the true exit point; always stays below the sentinel
// sentinel — intercepted by handlePopState on every back gesture
// Two entries are required so that iOS fires popstate (same-document navigation)
// before exiting, giving the handler a chance to push a new sentinel.
useEffect(() => {
if (window.innerWidth < 768) {
window.history.replaceState({ rc: 'chat' }, '');
window.history.replaceState({ rc: 'floor' }, '');
window.history.pushState({ rc: 'chat' }, '');
}
}, []);
@@ -486,8 +490,11 @@ export default function Chat() {
return;
}
// Already at root (Messages list, no chat open) — let the browser handle
// it so the next gesture actually exits the PWA. Don't re-push.
// Already at root (Messages list, no chat open) — we just popped the sentinel
// and are now on the floor entry. Step one more back so the browser exits the
// PWA (or navigates to the previous URL). Without this explicit go(-1), iOS
// leaves the user stranded on the invisible floor state.
window.history.go(-1);
};
window.addEventListener('popstate', handlePopState);
return () => window.removeEventListener('popstate', handlePopState);