Uh oh!
There was an error while loading. Please reload this page.
fix(admin): guard dashboard widgets against incomplete API payloads - #20
Open
LiusDev wants to merge 1 commit into
Open
fix(admin): guard dashboard widgets against incomplete API payloads#20LiusDev wants to merge 1 commit into
LiusDev wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes#19
Summary
admin/widgets/revenue-snapshotreturns{"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./_emdash/admindashboard on every brand new install (zero orders yet).{}/[]/0) inRevenueSnapshot,LowStockAlerts,RecentOrders,PendingReviews, andFailedSubscriptionsso 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
emdashitself), 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 typecheckinpackages/core— cleanbunx biome lint packages/core/src/admin/widgets— cleanbun 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