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

Commit e86f10b

Browse files
committed
fix: invalid router configuration causing beforeLoad hook to not fire
1 parent 34b1869 commit e86f10b

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,24 @@ 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 }) {
3939
const { cluster } = await queryClient.fetchQuery(bootstrapQueryOptions());
4040

41+
console.log("AAAA?");
4142
const { games: projects, groups } = await queryClient.fetchQuery(
4243
projectsQueryOptions(),
4344
);
45+
console.log("CCC?");
4446

4547
if (cluster === "oss" && projects.length === 1) {
4648
const {
4749
game: { namespaces },
4850
} = await queryClient.fetchQuery(projectQueryOptions(projects[0].gameId));
4951

52+
console.log("DDDD?");
5053
// In case the project has no namespaces, or we failed to fetch the project, redirect to the project page
5154
if (namespaces.length > 0) {
5255
throw redirect({
@@ -55,32 +58,40 @@ export async function guardOssNewie({
5558
projectId: projects[0].gameId,
5659
environmentId: namespaces[0].namespaceId,
5760
},
61+
from: "/",
5862
});
5963
}
6064

65+
console.log("EEEE?");
6166
throw redirect({
6267
to: "/projects/$projectId",
6368
params: {
6469
projectId: projects[0].gameId,
6570
},
71+
from: "/",
6672
});
6773
}
6874

6975
const lastTeam = ls.get(
7076
`rivet-lastteam-${auth.profile?.identity.identityId}`,
7177
);
7278

79+
console.log("FFFF?");
7380
if (lastTeam) {
7481
throw redirect({
7582
to: "/teams/$groupId",
7683
params: { groupId: lastTeam },
84+
from: "/",
7785
});
7886
}
7987

88+
console.log("GGGG?", groups[0].groupId);
89+
8090
if (groups.length > 0) {
8191
throw redirect({
8292
to: "/teams/$groupId",
8393
params: { groupId: groups[0].groupId },
94+
from: "/",
8495
});
8596
}
8697
}

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)