Skip to content

Commit 941ea56

Browse files
committed
polling cap and null check
1 parent e63036a commit 941ea56

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/cms/widgets/CloudinaryImageWidget.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,19 @@ const CloudinaryImageWidget: React.FC<CloudinaryWidgetProps> = ({
204204
if (src && !src.endsWith("undefined")) {
205205
setLocalSrc(src);
206206
}
207-
// Poll briefly for the blob to be populated by the CMS proxy
207+
// Poll briefly for the blob to be populated by the CMS proxy.
208+
// Cap attempts so the interval doesn't leak if the value never
209+
// changes (e.g., src was already resolved or stays unresolved).
210+
let attempts = 0;
211+
const MAX_POLL_ATTEMPTS = 20;
208212
const interval = setInterval(() => {
213+
attempts++;
209214
const resolved = getAsset(value, field).toString();
210215
if (resolved && resolved !== src) {
211216
setLocalSrc(resolved);
212217
clearInterval(interval);
218+
} else if (attempts >= MAX_POLL_ATTEMPTS) {
219+
clearInterval(interval);
213220
}
214221
}, 500);
215222
return () => clearInterval(interval);

src/templates/disease-catalog.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ interface QueryResult {
112112
const DiseaseCatalog = ({ data }: QueryResult) => {
113113
const { markdownRemark: post } = data;
114114
const imageFile = post.frontmatter.header?.background;
115-
const backgroundImageUrl = getImageSrcFromFileNode(imageFile!);
115+
const backgroundImageUrl = imageFile
116+
? getImageSrcFromFileNode(imageFile)
117+
: undefined;
116118
return (
117119
<Layout
118120
header={

0 commit comments

Comments
 (0)