Skip to content

fix(admin): guard dashboard widgets against incomplete API payloads - #20

Open
LiusDev wants to merge 1 commit into
emdashCommerce:mainfrom
LiusDev:fix/admin-widgets-empty-payload-crash
Open

fix(admin): guard dashboard widgets against incomplete API payloads#20
LiusDev wants to merge 1 commit into
emdashCommerce:mainfrom
LiusDev:fix/admin-widgets-empty-payload-crash

Conversation

@LiusDev

Copy link
Copy Markdown

Fixes#19

Summary

  • On a fresh/empty store, the admin widgets' plugin API responses come back with their "empty" fields (empty object/array, zero count) missing entirely rather than present-but-empty — e.g. admin/widgets/revenue-snapshot returns {"data":{}} instead of {"data":{"sevenDay":{},"thirtyDay":{}}}. See Admin dashboard white-screens on a fresh/empty store (Object.entries on undefined in widgets) #19 for the full repro and what I could trace of the root cause.
  • None of the five dashboard widgets guarded against this, so whichever rendered first threw synchronously and, since the error boundary wraps the whole admin app, white-screened the entire /_emdash/admin dashboard on every brand new install (zero orders yet).
  • This PR defaults each field to its empty value ({} / [] / 0) in RevenueSnapshot, LowStockAlerts, RecentOrders, PendingReviews, and FailedSubscriptions so they render their normal empty state instead of crashing.

This is a defensive client-side fix — it doesn't address wherever the payload actually gets thinned out (likely outside this repo, in emdash itself), but it makes the dashboard resilient regardless of where that turns out to live, and widgets probably shouldn't assume every field is always present either way.

Test plan

  • bun run typecheck in packages/core — clean
  • bunx biome lint packages/core/src/admin/widgets — clean
  • Reproduced the crash on a freshly seeded local store (bun run bootstrap) and confirmed each of the five widgets renders its empty state after this change, verified against a production build (astro build + astro preview, not dev mode) of a DashCommerce starter site

On a fresh/empty store (zero orders, zero low-stock products, zero
past-due subscriptions), every plugin API route this data flows
through gets a response whose "empty" fields (empty object/array,
zero count) come back missing entirely rather than present-but-empty
— observed as `{"data":{}}` for admin/widgets/revenue-snapshot instead
of `{"data":{"sevenDay":{},"thirtyDay":{}}}`.
None of the five admin dashboard widgets guarded against this, so
whichever widget rendered first threw synchronously:
- RevenueSnapshot: `Object.entries(data.sevenDay)` — TypeError:
Cannot convert undefined or null to object
- LowStockAlerts / RecentOrders: `rows.length` — TypeError: Cannot
read properties of undefined (reading 'length')
- FailedSubscriptions: `data.items.map` when `data.count` was also
missing (so the `count === 0` short-circuit never triggered)
- PendingReviews: `count` rendered as `undefined` instead of `0`
Because the error boundary wraps the whole admin app, this reliably
white-screened the entire /_emdash/admin dashboard on any brand new
DashCommerce store — reproduced locally on a freshly seeded db and on
a Cloudflare Workers deploy, both with zero real orders yet.
Default each field to its empty value ({}/[]/0) so every widget
renders its normal empty state instead of crashing the page.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for freeto 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.

Admin dashboard white-screens on a fresh/empty store (Object.entries on undefined in widgets)

1 participant

@LiusDev