Repository navigation
fix(site/src): let swipe-back reach the chat list from a notification - #31299
Conversation
This comment has been minimized.
This comment has been minimized.
|
Chat: Review posted | View chat Review history
deep-review v0.13.0 | Round 1 | Last posted: Round 1, 5 findings (2 P3, 2 P4, 1 Nit), COMMENT. Review Finding inventoryFinding inventory: PR #31299Findings
Contested and acknowledgedRound logRound 1Netero: 1 P4, 1 Note. No P0, proceed to panel. Full panel (round 1). Specialists: ging-ts (.ts), ging-react (.tsx), nami (frontend), melody (history.state crosses into React Router's format). Core: pariston, mafuuu. Pool: bisky (tests), gon and leorio (once-per-PR floor). Wildcard: razor (random). 10 reviewers, above the 6 to 8 focused target because of the 4 required specialists plus the Gon and Leorio floor. Cross-check: CRF-3 settled at P3 (Gon P2 rested partly on the rationale sentence being a restatement; it is the why. The run-before-router requirement is stated at the only call site, router.tsx:568. Keep-argument: an exported function's doc omits a precondition whose violation desyncs the router index). CRF-4 at P3 (higher of Gon P3, Leorio P4). Leorio's PR-description P4 merged into CRF-1 (same fix). Leorio's WebKit-function Note asks for a change, posted as CRF-5 P4. CRF-7 keep-argument: restating comments in a shared util cost every reader; dropped because the second sentence carries information the type does not. CRF-8 keep-argument: restating lines drift when the helper changes; dropped because the rewrite loses the explanation of the URL and display-mode fakes. No useBlocker on chat routes today (useUnsavedChangesPrompt callers are settings forms), so CRF-1 consequence is latent; kept at P4. Pariston: iOS device not tested (PR states it); if iOS opens start_url first, the change is a no-op. Reviewed against e17851d..38cc870. About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
0e360d6 to
87b44de
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Note to self, squash commit message: |
A push notification click opens the chat as the only history entry of the installed app window. There is no browser back button there, so the iOS edge swipe had nothing to go back to, while a chat opened from the chat list could swipe back to it. When a standalone window starts on a chat with no other entry, the first entry becomes the chat list and the chat is pushed on top. WebKit's back swipe skips entries that JavaScript pushes without user interaction but stops at the window's first entry, so pushing the list as well would leave the swipe on the same chat.
The chat list history entry needs the same "running as an installed app" check that the iOS attachment share sheet already had, so both now use one definition in utils/platform.
On iOS, a notification click opens the chat in a window stacked on a blank about:blank window. A back swipe that leaves that window on its first history entry closes it, which leaves only the blank page with no way back (CODAGT-1474). A device capture showed this for every swipe that landed on the first entry, on main too, and never for other entries. The window now starts on the chat list and opens the chat once the list has painted, so the swipe shows the list instead of a blank page. When a back step lands on the first entry, the same location is pushed again so the window always has a back entry.
Device testing showed that pushing the chat list again when a back step lands on a notification window's first entry does not keep iOS from closing the window, so drop that guard. A notification click can now also launch the chat list with the chat in the query (/agents?chat=<id>), or name the chat after boot through requestNotificationChat. Either way the chat opens on top of the list once the list has painted, the same as for a chat launched directly.
On iOS, a notification click that the service worker answers with clients.openWindow() opens the installed app in a second window over a blank one. A back swipe to that window's first page closes it and leaves the blank one on screen until the app is force-closed. Give notifications a Declarative Web Push navigate URL. Safari then opens the URL itself without notificationclick, and the installed app loads it in its own window, including when it is already running. Browsers without Declarative Web Push ignore the member and keep using the notificationclick handler.
Device testing showed that clients.openWindow() opens the installed iOS app in the closing second window for the start URL too, with or without the chat in the query, so nothing launches the chat list with a chat to open. Remove the ?chat= handoff and requestNotificationChat. The Declarative Web Push launch opens the chat URL directly, which openChatListFirst handles.
Name the WebKit rule that makes pushing the chat list as well land the back swipe on the chat, so a reader can check it without the PR.
With an expired session, the router sends a notification-opened chat to sign in with the current location as the redirect. openChatListFirst had already replaced that location with the chat list, so signing in landed on the list instead of the chat. Skip the rewrite when the server rendered the page without a signed-in user.
87b44de to
24b950f
Compare
…ndows A device test on an ephemeral deployment, whose proxy serves the deployed service worker, showed the chat list entry turning the back swipe into a blank screen. Without a navigate URL the click goes through clients.openWindow(), and iOS closes that window when a swipe reaches its first entry. The same happens on iOS before 18.4, which lacks Declarative Web Push, and for notifications the previous service worker showed. The service worker now marks the navigate URL with a notification query parameter, and openChatListFirst only rewrites marked windows and removes the marker. Windows opened with clients.openWindow() keep their single entry, as on main.
e01f44b to
da10389
Compare
| */ | ||
| export const notificationLaunchParam = "notification"; | ||
|
|
||
| let pendingChatPath: string | null = null; |
There was a problem hiding this comment.
Suggestion (non-blocking): keep the pending chat in the URL instead of module state.
pendingChatPath is mutable state that lives outside both React and the router. The comment above hasPendingChatPath is a symptom of that: the React Compiler assumes module-level values don't change, so the hook needs accessor functions to read the variable fresh. It also means a reload during the paint wait drops the chat, because the first entry is then plain /agents.
The router already tracks the URL, so the pending chat can live there.
1. openChatListFirst(): write the agent ID into a query parameter on the first entry instead of setting pendingChatPath:
const pendingChatParam = "notification-chat";
// replaces the last two lines of openChatListFirst()
url.searchParams.set(pendingChatParam, chatMatch.params.agentId);
window.history.replaceState(null, "", `/agents${url.search}${url.hash}`);2. useOpenNotificationChat(): read the parameter from the router location. Once the list has painted, replace the entry to drop the parameter, then push the chat:
export function useOpenNotificationChat(isListLoading: boolean): void {
const navigate = useNavigate();
const { search, hash } = useLocation();
const searchParams = new URLSearchParams(search);
const agentId = searchParams.get(pendingChatParam);
searchParams.delete(pendingChatParam);
const listSearch = searchParams.size > 0 ? `?${searchParams}` : "";
useEffect(() => {
if (!agentId) {
return;
}
let frame = 0;
const open = () => {
frame = requestAnimationFrame(() => {
frame = requestAnimationFrame(async () => {
await navigate(`/agents${listSearch}`, { replace: true });
await navigate(`/agents/${agentId}${listSearch}${hash}`);
});
});
};
const timer = isListLoading ? setTimeout(open, 1500) : undefined;
if (!isListLoading) {
open();
}
return () => {
clearTimeout(timer);
cancelAnimationFrame(frame);
};
}, [agentId, listSearch, hash, isListLoading, navigate]);
}Notes:
- Await the replace before the push. Two back-to-back
navigate()calls on a data router can interrupt each other. If the replace is dropped,/agents?notification-chat=...stays under the chat, and swiping back to it opens the chat again. - The replace goes through
history.replaceState, just like the current pre-router rewrite, so WebKit still treats the first entry as browser-created and the back swipe can reach it. - The
window.location.pathname === "/agents"check is no longer needed. If the user opens another chat before the timer fires, the parameter leaves the URL,agentIdbecomesnull, and the effect cleanup cancels the pending frame or timer. - After a reload,
notificationLaunchParamis already gone, soopenChatListFirst()returns early and the hook still opens the chat from the parameter. - The cost is a query parameter that's briefly visible on the list URL, and the hash sits on the list entry until the replace runs. The signed-out path is unchanged.
notificationWindow.test.tsxwould need its intermediate expectations updated: afteropenChatListFirst()the search includesnotification-chat, and the final history should be one replace followed by one push.
There was a problem hiding this comment.
I'd keep the module variable. The pending chat should open once, for the launch that set it. A module variable lasts exactly one page load. A URL parameter stays in the window's first history entry, and the hook acts on it again whenever that entry comes back.
I ran your hook next to the current one in jsdom, with the router setup from notificationWindow.test.tsx. In both runs I open Settings while the list is still loading:
- Back from Settings: the current hook stays on
/agents. Yours pops to/agents?notification-chat=<id>, replaces it with/agentsand pushes the chat, so the notification chat opens a second time. - The Settings back button: it links to the
fromstate that the Settings button saved,/agents?notification-chat=<id>. The current hook stays on/agents. Yours pushes that URL, replaces it and pushes the chat, so the chat opens a second time here too.
It also makes /agents?notification-chat=<id> open the chat from any link. A browser tab on that URL ends on the chat with your hook and on /agents with the current one. Today only a notification launch sets this up: openChatListFirst requires the launch marker, standalone display, a single history entry and a signed-in visitor.
You're right that a reload during the wait drops the chat. The wait ends when the list loads, or at most 1.5 s after the layout mounts. After the reload the window shows the chat list, the screen the back swipe leads to. The accessor functions are what this costs, and that's cheaper than opening the chat twice.
🤖 Posted using
/amend-reviewskill via Coder Agents.
On iOS, a chat opened from a push notification in the installed Agents app could not be swiped back to the chat list. The service worker answered the click with
clients.openWindow(), which iOS shows as a second window over a blankabout:blankone. That window starts on the chat as its only history entry, so the edge swipe had nothing to go back to, and a back swipe that lands on its first entry closes it within about half a second, leaving the blank window with Safari's toolbar until the app is force-closed.The push handler now gives notifications a Declarative Web Push
navigateURL (NotificationOptions.idl). Safari opens that URL itself instead of firingnotificationclick(WKWebsiteDataStore.mm), and the installed app loads it in its own window. With the app in the background, the tap now loads the chat in the running app. Browsers without Declarative Web Push ignore the member, as Chromium did in a local check, and keep using thenotificationclickhandler.When Safari opens the app on a chat for a notification, as the window's only entry, that entry becomes the chat list, and the chat is pushed on top once the list has painted (
notificationWindow.ts), so the swipe returns to the list. The service worker marks thenavigateURL with?notification=1so the page can tell these windows apart, and the page removes the marker. Windows fromclients.openWindow()keep their single entry, as onmain: iOS closes such a window when a swipe reaches its first entry, so a list there turns the swipe into the blank screen. Those windows still occur on iOS before 18.4, which has no Declarative Web Push, and for notifications that the previous service worker showed. When the server rendered the page for a signed-out visitor, the window is left alone so the sign-in redirect keeps the chat. The list replaces the first entry instead of being pushed because WebKit's back swipe skips entries pushed without user activation down to the first entry (itemStartingAtIndexSkippingItemsAddedByJSWithoutUserGesture).isStandaloneDisplayMode()moves fromchatAttachments.tstoutils/platform.tsfor the second caller.Verified on an iPhone (Safari 27.0.1) against an ephemeral deployment of this branch, with real push notifications: from a force-closed app and from the app in the background, the tap opened the chat, the swipe went back to the list, and the app kept working. That run predates the
?notification=1marker, which only unit tests cover. Testing on a frontend-mode ephemeral deployment needs the branch's worker: its proxy serves dogfood's/serviceWorker.js, so a notification tap there takes theclients.openWindow()path and stays onmain's behavior. Not verified: Safari on macOS also handlesnavigateitself, so where the service worker used to reuse an open Agents tab, Safari may open a new one.Fixes CODAGT-1474
Decision log
The device runs used a temporary diagnostics build (not in this PR) that recorded history and page lifecycle events to storage that survives a force-close, plus test notifications that opened the app in each variant.
openWindow()of the chat, chat list made the first entry (this PR's first version)popstate; iOS still closed the window about 570 ms lateropenWindow('/agents'), the manifeststart_url, with the chat handed over through Cache Storage or?chat=navigateURLclients.openWindow()hands the host app the choice of web view (WebsiteDataStore::openWindowFromServiceWorkeronly checks that the returned view is loading). The host is closed source, which is why the variants were measured instead of read.web_push: 8030). The service worker shows every notification, and thenavigatemember gives the same click handling without a server change.navigateto iOS by user agent. iPadOS reports a Mac user agent, and Safari on macOS handlesnavigateby design.Not changed: the chat top bar's mobile Back arrow pushes
/agentsinstead of going back, so swiping back from that list returns to the chat.maindoes the same.WebKit back-swipe probe
iOS picks the swipe target with
goBackItemSkippingItemsWithoutUserGesture()(ViewGestureController::itemForSwipeDirection), and so does WebKitGTK's toolbar back button (WebPageProxy::goBack). Playwright'spage.goBack()andhistory.back()do not, so this probe clicks the MiniBrowser toolbar withxdotool. In Playwright WebKit 26.6, scenario D goes back to/a(the skipping is active), C to/list, and E to its first entry,/chat.