Skip to content

Commit abba773

Browse files
claudeako
authored andcommitted
fix(widgets): don't emit " " for unset chart-series String props (runtime JSON.parse)
A ColumnChart with a static series passed mx check but failed to render with a client-side JSON.parse('Unexpected end of JSON input'). The object-list-item builder emitted an unset String property as a single space " " instead of "". The chart client feeds customSeriesOptions / customLayout / customConfigurations to JSON.parse behind an empty-guard (value !== "" ? value : "{}"); a lone space passes that guard, so the client runs JSON.parse(" ") and throws. mx check doesn't execute the client, so it stayed green. A Pie (widget-level datasource, no series object-list) was unaffected — the top-level String path already emitted "". Leave an unset String empty, matching Studio Pro and the top-level path, so the client's empty-guard turns it into "{}". Verified: series customSeriesOptions is now "" (was " "), zero space-valued primitives; mx check 0 errors and no CE0463 regression across charts / DataGrid2 / Gallery. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JXnEgoc2NQP1Y2TWMCMXC4
1 parent 455c43a commit abba773

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
-- ============================================================================
2+
-- Bug: chart series customSeriesOptions emitted as " " → runtime JSON.parse error
3+
-- ============================================================================
4+
--
5+
-- Symptom:
6+
-- A ColumnChart (or any chart with a `series`/`line` object-list) passed
7+
-- `mx check` (0 errors) but failed to RENDER at runtime with a client-side
8+
-- `JSON.parse('Unexpected end of JSON input')` in the chart render path. A Pie
9+
-- chart over the same data (widget-level datasource, no series object-list)
10+
-- rendered fine.
11+
--
12+
-- Root cause:
13+
-- The object-list-item builder emitted an unset String property as a single
14+
-- space " " (not ""). The chart client feeds customSeriesOptions /
15+
-- customLayout / customConfigurations straight to JSON.parse with an empty-guard
16+
-- `value !== "" ? value : "{}"`. A lone space passes that guard, so the client
17+
-- runs `JSON.parse(" ")` and throws. (mx check does not execute the client, so
18+
-- it stayed green.) The top-level string path already emitted "".
19+
--
20+
-- Fix:
21+
-- createDefaultWidgetValue (object-list-item path) leaves an unset String empty,
22+
-- matching Studio Pro and the top-level path, so the client's empty-guard turns
23+
-- it into "{}".
24+
--
25+
-- Verify:
26+
-- mxcli exec mdl-examples/bug-tests/chart-series-customseriesoptions-json.mdl -p app.mpr
27+
-- # the series' customSeriesOptions is now "" (was " "); the ColumnChart renders.
28+
-- mx check app.mpr # still 0 errors
29+
-- Requires: Charts .mpk installed in the project's widgets/.
30+
-- ============================================================================
31+
32+
create module ColJSON;
33+
/
34+
create entity ColJSON.Sales ( Region: String, Total: Decimal );
35+
/
36+
create or replace page ColJSON.Home ( layout: Atlas_Core.Atlas_Default ) {
37+
pluggablewidget 'com.mendix.widget.web.columnchart.ColumnChart' col1 {
38+
series s ( dataSet: static, staticDataSource: database from ColJSON.Sales,
39+
staticXAttribute: Region, staticYAttribute: Total, staticName: 'Revenue' )
40+
}
41+
}

mdl/backend/widgetobj/builder.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,9 +1291,14 @@ func createDefaultWidgetValue(entry pages.PropertyTypeIDEntry) bson.D {
12911291
textTemplate = createDefaultClientTemplateBSON(primitiveVal)
12921292
}
12931293
case "String":
1294-
if primitiveVal == "" {
1295-
primitiveVal = " "
1296-
}
1294+
// Leave an unset String property empty (its schema default, "") — do NOT
1295+
// manufacture a single space. Studio Pro stores "" here, and some widgets
1296+
// (chart series `customSeriesOptions`, `customLayout`, `customConfigurations`)
1297+
// feed the value straight to a client-side JSON.parse whose empty-guard is
1298+
// `value !== "" ? value : "{}"`; a lone space passes that guard and makes
1299+
// the widget throw `JSON.parse(" ")` → "Unexpected end of JSON input" at
1300+
// render time (object-list-item path only; the top-level path already
1301+
// leaves it empty).
12971302
}
12981303

12991304
return bson.D{

0 commit comments

Comments
 (0)