fix(tweet-card): guard against tweets with missing entity arrays#80
Conversation
react-tweet's enrichTweet iterates each entity array (hashtags, symbols, urls, user_mentions) without checking for undefined. The Twitter syndication API can omit an array for some tweets, throwing "entities is not iterable" during render and crashing the whole page (homepage testimonials had no surrounding error boundary). Normalize tweet.entities into a safeTweet with empty-array defaults before calling enrichTweet.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Walkthrough
ChangesTweet Entity Normalization
🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
smoothui.devhomepage crashed with "This page couldn't load" — client errorUncaught TypeError: r is not iterable(minified).Real error:
entities is not iterableatpackages/smoothui/components/tweet-card/index.tsx→enrichTweet(tweet).react-tweet@3.3.0's
getEntitiesrunsfor (const entity of tweet.entities.X)with no undefined guard. The Twitter syndication API can omit an entity array (e.g.symbols/user_mentions) for some tweets, which throws during render. The homepage testimonials (WhatTheySay → MediaPlayer → ClientTweetCard → SmoothTweet) callenrichTweetdirectly with no surrounding error boundary, so the whole page died.Fix
Normalize
tweet.entitiesinto asafeTweetwith empty-array defaults before callingenrichTweet. Defensive against any partial or deleted tweet, not just the current offender.Verification
Reproduced locally in dev (Next 16.2.6): homepage hit the root error boundary. After the fix, homepage loads, 7 tweets render, 0 not-found, no console error.
tscclean for the file.Summary by CodeRabbit
Bug Fixes