Skip to content

fix(tweet-card): guard against tweets with missing entity arrays#80

Merged
educlopez merged 1 commit into
mainfrom
fix/tweet-card-entities-guard
Jun 1, 2026
Merged

fix(tweet-card): guard against tweets with missing entity arrays#80
educlopez merged 1 commit into
mainfrom
fix/tweet-card-entities-guard

Conversation

@educlopez

@educlopez educlopez commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Problem

smoothui.dev homepage crashed with "This page couldn't load" — client error Uncaught TypeError: r is not iterable (minified).

Real error: entities is not iterable at packages/smoothui/components/tweet-card/index.tsxenrichTweet(tweet).

react-tweet@3.3.0's getEntities runs for (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) call enrichTweet directly with no surrounding error boundary, so the whole page died.

Fix

Normalize tweet.entities into a safeTweet with empty-array defaults before calling enrichTweet. 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. tsc clean for the file.

Summary by CodeRabbit

Bug Fixes

  • Fixed tweet card crashes when API responses omit optional data fields
  • Improved component resilience by normalizing incoming data to ensure all required structures are properly initialized
  • Enhanced overall application stability when rendering tweets from syndication sources with variable data completeness

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.
@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
smoothui Ready Ready Preview, Comment Jun 1, 2026 9:23am

Request Review

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c5438921-b98c-44c2-9828-76d11dd656da

📥 Commits

Reviewing files that changed from the base of the PR and between eba92bf and 0d489e8.

📒 Files selected for processing (1)
  • packages/smoothui/components/tweet-card/index.tsx

Walkthrough

SmoothTweet component adds defensive normalization to handle incomplete entity data from the syndication API. Before calling enrichTweet, it now constructs a safeTweet object that guarantees all entity arrays (hashtags, symbols, urls, user_mentions, media) are defined, defaulting to empty arrays when missing.

Changes

Tweet Entity Normalization

Layer / File(s) Summary
Safe tweet entity arrays wrapper
packages/smoothui/components/tweet-card/index.tsx
SmoothTweet now wraps the incoming tweet with a safeTweet that guarantees hashtags, symbols, urls, user_mentions, and media arrays are always defined (defaulting to empty arrays) before passing to enrichTweet, preventing crashes from missing syndication API entity arrays.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(tweet-card): guard against tweets with missing entity arrays' directly and clearly describes the main change: adding defensive guards for missing entity arrays in tweet data.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tweet-card-entities-guard

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@educlopez educlopez merged commit 6928c0f into main Jun 1, 2026
7 of 8 checks passed
@educlopez educlopez deleted the fix/tweet-card-entities-guard branch June 1, 2026 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant