Skip to content

Commit 7c59db4

Browse files
fix: make history pages switch faster (#169)
1 parent 8cc902c commit 7c59db4

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

app/components/Select.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ type SelectProps = {
55
options: string[];
66
selected: string;
77
onChange: (value: string) => void;
8+
onClick?: () => void;
89
};
910

10-
export const Select = ({ isDisabled, options, selected, onChange }: SelectProps) => {
11+
export const Select = ({ isDisabled, options, selected, onChange, onClick }: SelectProps) => {
1112
const onChangeHandler = useCallback(
1213
(e: React.ChangeEvent<HTMLSelectElement>) => {
1314
const value = e.target.value;
@@ -22,9 +23,11 @@ export const Select = ({ isDisabled, options, selected, onChange }: SelectProps)
2223
className="px-4 py-2 rounded-lg border-r-8 border-transparent border outline outline-gray-200 dark:outline-gray-700 bg-white dark:bg-gray-800 text-base focus:outline-none focus:ring-2 focus:ring-[#2f3241] dark:focus:ring-[#9feaf9] transition-all"
2324
disabled={isDisabled}
2425
onChange={onChangeHandler}
26+
onClick={onClick}
27+
value={selected}
2528
>
2629
{options.map((opt) => (
27-
<option key={opt} value={opt} selected={opt === selected}>
30+
<option key={opt} value={opt}>
2831
{opt}
2932
</option>
3033
))}

app/routes/build/release-job.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const loader = async (args: LoaderFunctionArgs) => {
3030
// Guess at three hours for the build time
3131
const estimatedCompletion = new Date(started.getTime() + 1_000 * 60 * 60 * 3);
3232
const timeZone = guessTimeZoneFromRequest(args.request);
33+
args.context.cacheControl = 'private, max-age=30';
3334
return {
3435
...build,
3536
started: prettyDateString(build.started, timeZone),

app/routes/history.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { LoaderFunctionArgs, MetaFunction } from '@remix-run/node';
2-
import { Link, useLoaderData, useSearchParams } from '@remix-run/react';
2+
import { Link, PrefetchPageLinks, useLoaderData, useSearchParams } from '@remix-run/react';
33
import { Calendar, Clock, Info, MoonIcon } from 'lucide-react';
44
import { MouseEvent, useCallback, useState } from 'react';
55
import { getReleasesOrUpdate } from '~/data/release-data';
@@ -86,7 +86,7 @@ export const loader = async (args: LoaderFunctionArgs) => {
8686
calendarData[month][day].stable.push(release.version);
8787
}
8888
}
89-
args.context.cacheControl = 'private, max-age=30';
89+
args.context.cacheControl = 'private, max-age=120';
9090

9191
const currentMonth = currentDate.getMonth();
9292
const currentDayOfMonth = currentDate.getDate();
@@ -107,6 +107,7 @@ const getDaysInMonth = (year: number, month: (typeof months)[number]) => {
107107
};
108108

109109
export default function ReleaseHistory() {
110+
const [preloadAllYears, setPreloadAllYears] = useState(false);
110111
const [, setSearchParams] = useSearchParams();
111112
const {
112113
data: calendarData,
@@ -150,6 +151,9 @@ export default function ReleaseHistory() {
150151
},
151152
[setSearchParams],
152153
);
154+
const onYearSelectClick = useCallback(() => {
155+
setPreloadAllYears(true);
156+
}, []);
153157

154158
const allowedYears = [];
155159
for (let y = MIN_YEAR; y <= new Date().getFullYear(); y++) {
@@ -158,12 +162,22 @@ export default function ReleaseHistory() {
158162

159163
return (
160164
<div className="max-w-4xl mx-auto">
165+
{preloadAllYears
166+
? allowedYears.map((year) => (
167+
<PrefetchPageLinks key={year} page={`/history?year=${year}`} />
168+
))
169+
: null}
161170
<div className="flex flex-col md:flex-row items-start md:items-center justify-between gap-4 mb-8">
162171
<h2 className="text-3xl font-bold text-[#2f3241] dark:text-white flex items-center gap-2">
163172
<Calendar className="w-7 h-7" />
164173
Release History {year}
165174
</h2>
166-
<Select options={allowedYears} selected={`${year}`} onChange={setYear} />
175+
<Select
176+
options={allowedYears}
177+
selected={`${year}`}
178+
onChange={setYear}
179+
onClick={onYearSelectClick}
180+
/>
167181
</div>
168182

169183
<div className="bg-white dark:bg-gray-800 rounded-xl shadow-sm border border-gray-200 dark:border-gray-700 overflow-hidden mb-6">

app/routes/release/compare.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export const loader = async (args: LoaderFunctionArgs) => {
8989
}),
9090
);
9191

92+
args.context.cacheControl = 'private, max-age=300';
93+
9294
return {
9395
fromElectronRelease,
9496
toElectronRelease,

0 commit comments

Comments
 (0)