Skip to content

Commit 6427199

Browse files
authored
defer stats in loader (#134)
also fix types for stats
1 parent 740e01e commit 6427199

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

app/modules/stats/index.tsx

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,32 @@ global.statCountsCache ??= new LRUCache<string, StatCounts>({
4343
},
4444
});
4545

46-
export async function getStats(): Promise<Stats[] | undefined> {
46+
export async function getStats(): Promise<Stats[]> {
4747
let cacheKey = "ONE_STATS_KEY_TO_RULE_THEM_ALL";
4848
let statCounts = await statCountsCache.fetch(cacheKey);
4949

50-
return statCounts
51-
? [
52-
{
53-
count: statCounts.npmDownloads,
54-
label: "Downloads on npm",
55-
svgId: "stat-download",
56-
},
57-
{
58-
count: statCounts.githubContributors,
59-
label: "Contributors on GitHub",
60-
svgId: "stat-users",
61-
},
62-
{
63-
count: statCounts.githubStars,
64-
label: "Stars on GitHub",
65-
svgId: "stat-star",
66-
},
67-
{
68-
count: statCounts.githubDependents,
69-
label: "Dependents on GitHub",
70-
svgId: "stat-box",
71-
},
72-
]
73-
: undefined;
50+
return [
51+
{
52+
count: statCounts.npmDownloads,
53+
label: "Downloads on npm",
54+
svgId: "stat-download",
55+
},
56+
{
57+
count: statCounts.githubContributors,
58+
label: "Contributors on GitHub",
59+
svgId: "stat-users",
60+
},
61+
{
62+
count: statCounts.githubStars,
63+
label: "Stars on GitHub",
64+
svgId: "stat-star",
65+
},
66+
{
67+
count: statCounts.githubDependents,
68+
label: "Dependents on GitHub",
69+
svgId: "stat-box",
70+
},
71+
];
7472
}
7573

7674
/**

app/pages/splash.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import { getStats } from "~/modules/stats";
77
import { getRootMatchData } from "~/ui/meta";
88

99
export let loader = async () => {
10-
const stats = await getStats();
11-
// replace with something better, just fixing types
12-
if (!stats) {
13-
throw new Error("Failed to load stats");
14-
}
10+
const stats = getStats();
1511
return { stats };
1612
};
1713

@@ -153,7 +149,6 @@ export default function Home() {
153149
<Await resolve={stats} errorElement={null}>
154150
{(stats) => (
155151
<ul className="mt-8 grid grid-cols-1 gap-8 md:grid md:grid-cols-2">
156-
{/* @ts-expect-error -- these types didn't make it into RR7, this needs to be fixed */}
157152
{stats.map(({ svgId, count, label }) => (
158153
<li key={svgId} className="flex gap-4">
159154
<svg

0 commit comments

Comments
 (0)