Skip to content

Commit a242839

Browse files
gaearonclaude
andcommitted
Small cleanups
- Error decoder: key the compiled-MDX cache on the error message instead of the entire codes.json map. - Home page clock: tick on minute boundaries again instead of every 60s from mount. - next.config: drop the @babel/* entries from serverExternalPackages; the server no longer uses Babel. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f047aa2 commit a242839

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

next.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ const nextConfig = {
1818
reactCompiler: true,
1919
cacheComponents: true,
2020
serverExternalPackages: [
21-
'@babel/core',
22-
'@babel/plugin-transform-modules-commonjs',
23-
'@babel/preset-react',
2421
'@mdx-js/mdx',
2522
'gray-matter',
2623
'unist-util-visit',

src/components/Layout/HomeContent.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,18 @@ function CurrentTime() {
9595

9696
useEffect(() => {
9797
const msPerMinute = 60 * 1000;
98+
let timeout;
9899

99100
function updateDate() {
100101
setDate(new Date());
102+
// Update on the minute, like the clock on a phone would.
103+
const now = Date.now();
104+
const nextMinute = (Math.floor(now / msPerMinute) + 1) * msPerMinute;
105+
timeout = setTimeout(updateDate, nextMinute - now);
101106
}
102107

103108
updateDate();
104-
const interval = setInterval(updateDate, msPerMinute);
105-
return () => clearInterval(interval);
109+
return () => clearTimeout(timeout);
106110
}, []);
107111

108112
const currentTime = date?.toLocaleTimeString([], {

src/lib/loadErrorDecoderData.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function loadErrorCodes(): Promise<Record<string, string>> {
3333
*/
3434
async function compileErrorDecoderData(
3535
code: string | null,
36-
errorCodes: Record<string, string>
36+
errorMessage: string | null
3737
): Promise<ErrorDecoderData> {
3838
'use cache';
3939
cacheLife('max');
@@ -50,7 +50,7 @@ async function compileErrorDecoderData(
5050
return {
5151
...compiled,
5252
errorCode: code,
53-
errorMessage: code ? errorCodes[code] : null,
53+
errorMessage,
5454
};
5555
}
5656

@@ -61,7 +61,8 @@ export async function loadErrorDecoderData(
6161
if (code && !errorCodes[code]) {
6262
notFound();
6363
}
64-
return compileErrorDecoderData(code, errorCodes);
64+
// Only the message goes into the cache key, not the whole codes map.
65+
return compileErrorDecoderData(code, code ? errorCodes[code] : null);
6566
}
6667

6768
export async function listErrorCodes(): Promise<string[]> {

0 commit comments

Comments
 (0)