Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit 3b0b12d

Browse files
committed
fix: invalid router configuration causing beforeLoad hook to not fire (#403)
1 parent 34b1869 commit 3b0b12d

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

apps/hub/src/app.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ export const router = createRouter({
3737
},
3838
// Since we're using React Query, we don't want loader calls to ever be stale
3939
// This will ensure that the loader is always called when the route is preloaded or visited
40-
defaultPreload: "intent",
40+
defaultStaleTime: Number.POSITIVE_INFINITY,
4141
defaultPendingComponent: PageLayout.Root.Skeleton,
42+
defaultPreloadStaleTime: 0,
4243
defaultOnCatch: (error) => {
4344
Sentry.captureException(error);
4445
},

apps/hub/src/components/header/header.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
SheetTrigger,
99
} from "@rivet-gg/components";
1010
import { Icon, faBars } from "@rivet-gg/icons";
11-
import { Link, useLocation } from "@tanstack/react-router";
11+
import { Link } from "@tanstack/react-router";
1212
import { Breadcrumbs } from "../breadcrumbs/breadcrumbs";
1313
import { MobileBreadcrumbs } from "../breadcrumbs/mobile-breadcrumbs";
1414
import { Changelog } from "./changelog";
@@ -36,7 +36,6 @@ const UserProfileButton = () => {
3636
};
3737

3838
export function Header() {
39-
const location = useLocation();
4039
return (
4140
<header className="bg-background/60 sticky top-0 z-10 flex items-center gap-4 border-b py-2 backdrop-blur">
4241
<HeaderRouteLoader />

apps/hub/src/lib/guards.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function guardEnterprise({
3232
}
3333
}
3434

35-
export async function guardOssNewie({
35+
export async function guardOssNewbie({
3636
queryClient,
3737
auth,
3838
}: { queryClient: QueryClient; auth: AuthContext }) {
@@ -55,14 +55,15 @@ export async function guardOssNewie({
5555
projectId: projects[0].gameId,
5656
environmentId: namespaces[0].namespaceId,
5757
},
58+
from: "/",
5859
});
5960
}
60-
6161
throw redirect({
6262
to: "/projects/$projectId",
6363
params: {
6464
projectId: projects[0].gameId,
6565
},
66+
from: "/",
6667
});
6768
}
6869

@@ -74,13 +75,15 @@ export async function guardOssNewie({
7475
throw redirect({
7576
to: "/teams/$groupId",
7677
params: { groupId: lastTeam },
78+
from: "/",
7779
});
7880
}
7981

8082
if (groups.length > 0) {
8183
throw redirect({
8284
to: "/teams/$groupId",
8385
params: { groupId: groups[0].groupId },
86+
from: "/",
8487
});
8588
}
8689
}

apps/hub/src/routes/_authenticated/_layout/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Intro } from "@/components/intro";
22
import { DeepDiveSection } from "@/components/sections/deep-dive-section";
33
import { FaqSection } from "@/components/sections/faq-section";
4-
import { guardOssNewie } from "@/lib/guards";
4+
import { guardOssNewbie } from "@/lib/guards";
55
import { H1, NarrowPage, Separator } from "@rivet-gg/components";
66
import { createFileRoute } from "@tanstack/react-router";
77
import { zodSearchValidator } from "@tanstack/router-zod-adapter";
@@ -35,10 +35,11 @@ const searchSchema = z.object({
3535
export const Route = createFileRoute("/_authenticated/_layout/")({
3636
validateSearch: zodSearchValidator(searchSchema),
3737
component: IndexRoute,
38-
beforeLoad: async ({ search, context: { queryClient, auth } }) => {
38+
beforeLoad: ({ search, context: { queryClient, auth } }) => {
3939
if (search.newbie === true) {
4040
return;
4141
}
42-
await guardOssNewie({ queryClient, auth });
42+
return guardOssNewbie({ queryClient, auth });
4343
},
44+
shouldReload: true,
4445
});

0 commit comments

Comments
 (0)