From 79d0e9b600d11cc94f5e436c263e23ef6b843541 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Tue, 18 Aug 2026 17:27:03 +0300 Subject: [PATCH] Fix crash on browsers not supporting CookieStore --- app/features/timezone/timezone-cookie.ts | 38 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/app/features/timezone/timezone-cookie.ts b/app/features/timezone/timezone-cookie.ts index 6717eb787..7a6fc240d 100644 --- a/app/features/timezone/timezone-cookie.ts +++ b/app/features/timezone/timezone-cookie.ts @@ -22,20 +22,32 @@ const ianaTimezone = z * timezone, so it has to be written client-side before the server can know it. */ export function writeViewerTimezoneCookie() { - const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; - if (!timezone) return; + try { + const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; + if (!timezone) return; - void cookieStore - .set({ - name: COOKIE_NAME, - value: timezone, - path: "/", - expires: Date.now() + TEN_YEARS_IN_MS, - sameSite: "lax", - }) - .catch((error) => - logger.error("Failed to store the timezone cookie", error), - ); + if (typeof cookieStore === "undefined") { + // biome-ignore lint/suspicious/noDocumentCookie: the Cookie Store API is only available in WebKit from iOS/Safari 18.4; this fallback keeps older iPhones working + document.cookie = `${COOKIE_NAME}=${timezone}; path=/; max-age=${ + TEN_YEARS_IN_MS / 1000 + }; samesite=lax`; + return; + } + + void cookieStore + .set({ + name: COOKIE_NAME, + value: timezone, + path: "/", + expires: Date.now() + TEN_YEARS_IN_MS, + sameSite: "lax", + }) + .catch((error) => + logger.error("Failed to store the timezone cookie", error), + ); + } catch (error) { + logger.error("Failed to store the timezone cookie", error); + } } /**