From a18903bbd5069a145a02faa48a2f71ec0723e4b3 Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Sat, 29 Aug 2026 07:45:00 +0000 Subject: [PATCH] Reuse the open PWA window when an emailed link launches the app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sign-in mail links back at our own origin — api/auth/magic builds the URL from origin() — so on a device where the app handles its own links, clicking it is an in-scope launch of p0dcasters. The manifest named no launch_handler, which leaves the browser on `auto`, and `auto` answers every launch with a new app window. For a magic link that is the worst shape the bug takes. The session cookie is set in whichever window opened the link, so you end up signed in inside a window you did not open while the one you were already using sits there signed out, looking like the link failed. `navigate-existing` hands the launch to the window used most recently and navigates it, so the link lands where you are already looking and the cookie is set in the window you were using. `auto` follows it for a browser that does not know the first value, and for when nothing is open yet. No service worker change is needed here: public/sw.js precaches nothing and never caches the manifest, so there is no stale copy for a version bump to evict. Safari and Firefox ignore launch_handler and keep their current behaviour. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_013FR5zDT4DGJAmwDb6oVZ6n --- src/app/manifest.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/app/manifest.ts b/src/app/manifest.ts index e252769..19b1d82 100644 --- a/src/app/manifest.ts +++ b/src/app/manifest.ts @@ -29,6 +29,18 @@ export default function manifest(): MetadataRoute.Manifest { start_url: "/", scope: "/", display: "standalone", + // An emailed sign-in link points back here, so on a device where the app + // handles its own links every click is an in-scope launch. The default + // ("auto") answers each one with a brand new app window, which for a magic + // link is the worst version of the bug: you end up signed in inside a + // window you did not open, while the one you were already using sits there + // signed out. navigate-existing hands the launch to the window that was + // used most recently and navigates it, so the link lands where the reader + // is already looking. "auto" trails it for browsers that do not know the + // first value, and for when there is no window open yet. + launch_handler: { + client_mode: ["navigate-existing", "auto"], + }, background_color: "#fbfaf7", theme_color: "#fbfaf7", categories: ["entertainment", "news", "music"],