Skip to content

fix: RecentPostsWidget TypeError with non-array posts - #1185

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/recent-posts-widget-array-check
Open

fix: RecentPostsWidget TypeError with non-array posts#1185
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/recent-posts-widget-array-check

Conversation

@sentry

@sentry sentry Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

This PR addresses a TypeError: r.map is not a function occurring in the RecentPostsWidget when the fetchRecentPosts server function returns a non-array value (e.g., an error object).

Changes Made:

  1. src/components/RecentPostsWidget.tsx: Modified the conditional rendering logic from if (!visiblePosts) to if (!Array.isArray(visiblePosts)). This ensures that if fetchRecentPosts resolves to a non-array value (like an error object), the component correctly renders the RecentPostsSkeleton instead of attempting to call .map() on an invalid type, which caused the crash.
  2. src/utils/blog.functions.ts: Wrapped the body of the fetchRecentPosts handler in a try/catch block. In case of any error during post fetching, it now returns an empty array ([]). This provides a more robust server function that guarantees an array return type, preventing non-array payloads from ever reaching the client-side components.

Why these changes?
The original issue stemmed from fetchRecentPosts potentially returning an object (e.g., { error: "..." }) on failure. The RecentPostsWidget's guard !visiblePosts was insufficient as an object is truthy, and object.length is undefined, bypassing the check. Consequently, RecentPostsList received a non-array and crashed when calling .map(). These changes implement a more precise type check in the widget and a safer return value from the server function, resolving the TypeError and improving resilience.

Fixes TANSTACK-COM-4SC

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
tanstack-com 5a29fad Commit Preview URL

Branch Preview URL
Aug 27 2026, 11:04 PM

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.

0 participants