diff --git a/components/third-party/gist.tsx b/components/third-party/gist.tsx index e077dad7..ccd89cce 100644 --- a/components/third-party/gist.tsx +++ b/components/third-party/gist.tsx @@ -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 (

@@ -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 = ``; diff --git a/components/third-party/tweet.tsx b/components/third-party/tweet.tsx index 07aa62c4..480a3c0a 100644 --- a/components/third-party/tweet.tsx +++ b/components/third-party/tweet.tsx @@ -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 (

@@ -28,6 +30,8 @@ const Tweet = async ({ id, className }: { id: string; className?: string }) => { ); } + cacheLife("max"); + return (