Bug: WidgetEditor loses state on reload — raw DB rows returned without mapping #419
dogghouseinteractive
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
`
Summary
The
GET /_emdash/api/widget-areasendpoint returns raw SQLite rows for widgets without transforming them for the client. This causes theWidgetEditorcomponent to lose all widget state (content, menu selection, component assignment) on every page load, even though the data is saved correctly in the database.Affected version
EmDash v0.1.1 (
@emdash-cms/adminv0.1.1)Steps to reproduce
/_emdash/admin/widgetsRoot cause
The widget areas list endpoint (
src/astro/routes/api/widget-areas/index.ts) returns raw rows from_emdash_widgets:This has two problems:
1.
contentis a JSON string, not a parsed arrayThe
contentcolumn storesJSON.stringify(portableTextBlocks). Without parsing, the client receives a string like"[{"_type":"block",...}]". InWidgetEditor:Array.isArrayreturnsfalsefor a string, so content always initializes to[].2. Column names are snake_case, but
WidgetEditorreads camelCaseSince the camelCase keys don't exist on the raw row object, they all fall back to their defaults (
""or{}).Why saving works
The PUT handler (
src/astro/routes/api/widget-areas/[name]/widgets/[id].ts) correctly maps camelCase input to snake_case columns:So data is written correctly — it's only the read path that's broken.
Comparison with sections (which work correctly)
The sections API has a
rowToSection()helper (src/sections/index.ts) that:JSON.parses thecontentandkeywordscolumnspreview_media_id→previewUrl, etc.)Widgets lack an equivalent mapper.
Suggested fix
Add a
rowToWidget()helper analogous torowToSection(), and use it in the widget areas list and single-widget GET endpoints:Beta Was this translation helpful? Give feedback.
All reactions