From fc67ef2b2269653e84aafae474b7214b88a94b73 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 21 Jul 2026 15:56:46 +0000 Subject: [PATCH] fix(widgets): don't emit " " for unset chart-series String props (runtime JSON.parse) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Claude-Session: https://claude.ai/code/session_01JXnEgoc2NQP1Y2TWMCMXC4 --- .../chart-series-customseriesoptions-json.mdl | 41 +++++++++++++++++++ mdl/backend/widgetobj/builder.go | 11 +++-- 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 mdl-examples/bug-tests/chart-series-customseriesoptions-json.mdl diff --git a/mdl-examples/bug-tests/chart-series-customseriesoptions-json.mdl b/mdl-examples/bug-tests/chart-series-customseriesoptions-json.mdl new file mode 100644 index 000000000..c8d613eef --- /dev/null +++ b/mdl-examples/bug-tests/chart-series-customseriesoptions-json.mdl @@ -0,0 +1,41 @@ +-- ============================================================================ +-- Bug: chart series customSeriesOptions emitted as " " → runtime JSON.parse error +-- ============================================================================ +-- +-- Symptom: +-- A ColumnChart (or any chart with a `series`/`line` object-list) passed +-- `mx check` (0 errors) but failed to RENDER at runtime with a client-side +-- `JSON.parse('Unexpected end of JSON input')` in the chart render path. A Pie +-- chart over the same data (widget-level datasource, no series object-list) +-- rendered fine. +-- +-- Root cause: +-- The object-list-item builder emitted an unset String property as a single +-- space " " (not ""). The chart client feeds customSeriesOptions / +-- customLayout / customConfigurations straight to JSON.parse with an empty-guard +-- `value !== "" ? value : "{}"`. A lone space passes that guard, so the client +-- runs `JSON.parse(" ")` and throws. (mx check does not execute the client, so +-- it stayed green.) The top-level string path already emitted "". +-- +-- Fix: +-- createDefaultWidgetValue (object-list-item path) leaves an unset String empty, +-- matching Studio Pro and the top-level path, so the client's empty-guard turns +-- it into "{}". +-- +-- Verify: +-- mxcli exec mdl-examples/bug-tests/chart-series-customseriesoptions-json.mdl -p app.mpr +-- # the series' customSeriesOptions is now "" (was " "); the ColumnChart renders. +-- mx check app.mpr # still 0 errors +-- Requires: Charts .mpk installed in the project's widgets/. +-- ============================================================================ + +create module ColJSON; +/ +create entity ColJSON.Sales ( Region: String, Total: Decimal ); +/ +create or replace page ColJSON.Home ( layout: Atlas_Core.Atlas_Default ) { + pluggablewidget 'com.mendix.widget.web.columnchart.ColumnChart' col1 { + series s ( dataSet: static, staticDataSource: database from ColJSON.Sales, + staticXAttribute: Region, staticYAttribute: Total, staticName: 'Revenue' ) + } +} diff --git a/mdl/backend/widgetobj/builder.go b/mdl/backend/widgetobj/builder.go index ee9448d19..d2febccd8 100644 --- a/mdl/backend/widgetobj/builder.go +++ b/mdl/backend/widgetobj/builder.go @@ -1291,9 +1291,14 @@ func createDefaultWidgetValue(entry pages.PropertyTypeIDEntry) bson.D { textTemplate = createDefaultClientTemplateBSON(primitiveVal) } case "String": - if primitiveVal == "" { - primitiveVal = " " - } + // Leave an unset String property empty (its schema default, "") — do NOT + // manufacture a single space. Studio Pro stores "" here, and some widgets + // (chart series `customSeriesOptions`, `customLayout`, `customConfigurations`) + // feed the value straight to a client-side JSON.parse whose empty-guard is + // `value !== "" ? value : "{}"`; a lone space passes that guard and makes + // the widget throw `JSON.parse(" ")` → "Unexpected end of JSON input" at + // render time (object-list-item path only; the top-level path already + // leaves it empty). } return bson.D{