fix: don't cache failed tweet/gist embeds for 30 days

Move cacheLife into the success/failure branches so a transient fetch
failure is retried after ~1 hour instead of being cached for 30 days.
Also catch thrown fetch errors in Gist so they no longer fail the build.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jakeandClaude Sonnet 5.5 committed 2026-10-03 08:23:37 -04:00
1 parent ae2ab88988
commit a9091eb4b3
2 files changed
+20 -6

No files matched your search

+15 -5
View File
@@ -14,7 +14,6 @@ const Gist = async ({
title?: string;
} & React.ComponentProps<"iframe">) => {
"use cache";
cacheLife("max");
cacheTag("gist", `gist-${id}${file ? `-${file}` : ""}`);
const iframeId = `gist-${id}${file ? `-${file}` : ""}`;
@@ -22,10 +21,21 @@ const Gist = async ({
const iframeTitle = title ?? `GitHub Gist ${id}${file ? ` - ${file}` : ""}`;
const scriptUrl = `https://gist.github.com/${id}.js${file ? `?file=${file}` : ""}`;
const scriptResponse = await fetch(scriptUrl);
let script: string | null = null;
try {
const scriptResponse = await fetch(scriptUrl);
if (scriptResponse.ok) {
script = await scriptResponse.text();
} else {
console.warn(`[gist] failed to fetch js:`, scriptResponse.statusText);
}
} catch (error) {
console.warn(`[gist] failed to fetch js:`, error);
}
if (!scriptResponse.ok) {
console.warn(`[gist] failed to fetch js:`, scriptResponse.statusText);
if (script === null) {
// don't pin a (possibly transient) fetch failure into the page for 30 days -- retry soon
cacheLife("hours");
return (
<p className="text-center">
@@ -41,7 +51,7 @@ const Gist = async ({
);
}
const script = await scriptResponse.text();
cacheLife("max");
// https://github.com/tleunen/react-gist/blob/master/src/index.js#L29
const iframeHtml = `<html><head><base target="_parent"></head><body onload="parent.document.getElementById('${iframeId}').style.height=document.body.scrollHeight + 'px'" style="margin:0"><script>${script}</script></body></html>`;
+5 -1
View File
@@ -8,7 +8,6 @@ import { cn } from "@/lib/utils";
const Tweet = async ({ id, className }: { id: string; className?: string }) => {
"use cache";
cacheLife("max");
cacheTag("tweet", `tweet-${id}`);
let data: TweetType | undefined;
@@ -21,6 +20,9 @@ const Tweet = async ({ id, className }: { id: string; className?: string }) => {
}
if (!data) {
// don't pin a (possibly transient) fetch failure into the page for 30 days -- retry soon
cacheLife("hours");
return (
<div className={cn("my-6 min-h-30 *:mx-auto! *:font-sans!", className)}>
<TweetNotFound />
@@ -28,6 +30,8 @@ const Tweet = async ({ id, className }: { id: string; className?: string }) => {
);
}
cacheLife("max");
return (
<div
className={cn(