Skip to content

fix: set isLoading: false when id is undefined#193

Open
TatsuyaYamamoto wants to merge 1 commit intovercel:mainfrom
TatsuyaYamamoto:is-loading-logic
Open

fix: set isLoading: false when id is undefined#193
TatsuyaYamamoto wants to merge 1 commit intovercel:mainfrom
TatsuyaYamamoto:is-loading-logic

Conversation

@TatsuyaYamamoto
Copy link

I can't tell if this PR is a fix or a feat.


If id is undefined, useTweet return isLoading: true. However, I think useTweet should return isLoading: false because SWR cannot without id. For this reason, I propose to change a behavior of useTweet.

If this change is reasonable, a behavior of <Tweet /> may also need to be changed.

https://github.com/vercel/react-tweet/blob/main/packages/react-tweet/src/swr.tsx

@vercel
Copy link
Contributor

vercel bot commented Mar 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-tweet-create-react-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 2:45pm
react-tweet-custom-tweet-dub ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 2:45pm
react-tweet-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 2:45pm
react-tweet-vite-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2025 2:45pm

@vercel
Copy link
Contributor

vercel bot commented Mar 21, 2025

@TatsuyaYamamoto is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@lfades
Copy link
Member

lfades commented Sep 21, 2025

@TatsuyaYamamoto The change looks reasonable to me, finish the change and I'll merge it!

@TatsuyaYamamoto
Copy link
Author

@lfades

I'll make changes, but I’m not sure about the new expected behavior of <Tweet/> ..... 🤔
When id is undefined, useTweet return isLoading: false. As a result, <Tweet/> has 2options:

  • Return null, because nothing is being loaded.
  • Return fallback, because id: undefined is considered a loading state.

@Ashutosh0x
Copy link

Good catch on that loading state logic @lfades. Setting isLoading to false when the ID is undefined prevents components from being stuck in a loading loop in dynamic routes. This should definitely improve the error handling and fallback behavior for react-tweet.

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.

3 participants