Skip to content

Commit eaee8d4

Browse files
ericallamTrigger.dev RepoOps
authored andcommitted
fix(webapp): keep login page errors visible when the timezone is saved
Errors on the login page, such as an expired or invalid magic link, no longer disappear a moment after the page loads in a new browser. Mono-RevId: e4a17f9e652349a0a32df1005947f8a50280534b
1 parent 67fdbbd commit eaee8d4

5 files changed

Lines changed: 28 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: fix
4+
---
5+
6+
Errors on the login page, such as an expired or invalid magic link, no longer disappear a moment after the page loads in a new browser.

‎apps/webapp/app/components/TimezoneSetter.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useFetcher } from "@remix-run/react";
22
import { useEffect, useRef } from "react";
33
import { useTypedLoaderData } from "remix-typedjson";
44
import type { loader } from "~/root";
5+
import { TIMEZONE_ACTION_PATH } from "~/utils/flashedErrorRevalidation";
56

67
export function TimezoneSetter() {
78
const { timezone: storedTimezone } = useTypedLoaderData<typeof loader>();
@@ -19,7 +20,7 @@ export function TimezoneSetter() {
1920
{ timezone: browserTimezone },
2021
{
2122
method: "POST",
22-
action: "/resources/timezone",
23+
action: TIMEZONE_ACTION_PATH,
2324
encType: "application/json",
2425
}
2526
);

‎apps/webapp/app/routes/login._index/route.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import { flags as getGlobalFlags } from "~/v3/featureFlags.server";
3232
import { requestUrl } from "~/utils/requestUrl.server";
3333
import { SSO_SESSION_EXPIRED_REASON } from "~/utils/ssoSession";
3434
import { cn } from "~/utils/cn";
35+
import { keepFlashedErrorOnTimezoneSave } from "~/utils/flashedErrorRevalidation";
36+
37+
export const shouldRevalidate = keepFlashedErrorOnTimezoneSave;
3538

3639
// Client-side email validation for the inline magic-link form. Mirrors
3740
// /login/sso: the form posts cross-route to /login/magic, so conform runs

‎apps/webapp/app/routes/login.magic/route.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ import { logger, tryCatch } from "@trigger.dev/core/v3";
3636
import { env } from "~/env.server";
3737
import { extractClientIp } from "~/utils/extractClientIp.server";
3838
import { magicLinkEmailCookie } from "./magicLinkEmailCookie.server";
39+
import { keepFlashedErrorOnTimezoneSave } from "~/utils/flashedErrorRevalidation";
40+
41+
export const shouldRevalidate = keepFlashedErrorOnTimezoneSave;
3942

4043
export const meta: MetaFunction = ({ matches }) => {
4144
const parentMeta = matches
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { ShouldRevalidateFunction } from "@remix-run/react";
2+
3+
export const TIMEZONE_ACTION_PATH = "/resources/timezone";
4+
5+
/**
6+
* For routes whose loader reads a one-time flashed error from the session. A fetcher submission
7+
* re-runs every loader on the page, and the second run finds the flash already consumed, so the
8+
* error renders and then disappears. The timezone setter submits on a browser's first visit,
9+
* which is exactly when a magic link opened in a new browser lands on these pages.
10+
*/
11+
export const keepFlashedErrorOnTimezoneSave: ShouldRevalidateFunction = ({
12+
formAction,
13+
defaultShouldRevalidate,
14+
}) => (formAction === TIMEZONE_ACTION_PATH ? false : defaultShouldRevalidate);

0 commit comments

Comments
 (0)