Skip to content

fix: bubble chart crash on window resize with named series in manual config#1267

Merged
HardeepAsrani merged 1 commit intodevelopmentfrom
fix/issue-485
Mar 10, 2026
Merged

fix: bubble chart crash on window resize with named series in manual config#1267
HardeepAsrani merged 1 commit intodevelopmentfrom
fix/issue-485

Conversation

@HardeepAsrani
Copy link
Member

Summary

When a manual config defines series with string keys (e.g. named series), override() permanently mutates chart.settings.series to a plain object. On resize, the numeric-index conversion incorrectly processed those string keys, producing a sparse array with length=0 that caused Google Charts to crash with "can't access property color, b is null".

Will affect visual aspect of the product

YES/NO

Screenshots

Test instructions

  • Make sure bubble chart works as before but without the resize issue.

Check before Pull Request is ready:

Closes https://github.com/Codeinwp/visualizer-pro/issues/485#issue-2423310972.

…config

When a manual config defines series with string keys (e.g. named series),
override() permanently mutates chart.settings.series to a plain object.
On resize, the numeric-index conversion incorrectly processed those string
keys, producing a sparse array with length=0 that caused Google Charts to
crash with "can't access property color, b is null".
@HardeepAsrani HardeepAsrani added the pr-checklist-skip Allow this Pull Request to skip checklist. label Mar 9, 2026
@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label Mar 9, 2026
@pirate-bot
Copy link
Contributor

Plugin build for 4a5e321 is ready 🛎️!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a Google Bubble chart crash triggered on window resize when manual chart configs define series with string keys (named series), by preventing incorrect object-to-array conversion of chart.settings.series.

Changes:

  • Detects whether chart.settings.series keys are numeric before converting it into an array.
  • Leaves string-keyed series objects untouched to avoid creating sparse/empty arrays that can crash Google Charts on resize.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +37 to +41
if ( seriesKeys.every( function( k ) { return ! isNaN( k ); } ) ) {
var chartSeries = [];
var chartSeriesValue = Object.values( chart.settings.series );
$.each( seriesKeys, function( index, element ) {
chartSeries[ element ] = chartSeriesValue[ index ];
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The numeric-key detection uses ! isNaN( k ), but isNaN performs coercion and will treat values like '1.5', '1e2', '', or '00' as “numeric”. Some of these are not valid array indices in JS (e.g. '1.5' / '00' become non-index properties), which can recreate the same sparse/length=0 behavior this change is trying to prevent. Consider using a stricter check for non-negative integer indices (e.g. /^(0|[1-9]\d*)$/ or Number.isInteger( Number(k) ) && String( Number(k) ) === k) and optionally casting element to a number when assigning into chartSeries.

Suggested change
if ( seriesKeys.every( function( k ) { return ! isNaN( k ); } ) ) {
var chartSeries = [];
var chartSeriesValue = Object.values( chart.settings.series );
$.each( seriesKeys, function( index, element ) {
chartSeries[ element ] = chartSeriesValue[ index ];
if ( seriesKeys.every( function( k ) { return /^(0|[1-9]\d*)$/.test( k ); } ) ) {
var chartSeries = [];
var chartSeriesValue = Object.values( chart.settings.series );
$.each( seriesKeys, function( index, element ) {
chartSeries[ Number( element ) ] = chartSeriesValue[ index ];

Copilot uses AI. Check for mistakes.
Comment on lines 33 to +44
if ( undefined !== chart.settings && undefined !== chart.settings.series && undefined === chart.settings.series.length ) {
var chartSeries = [];
var chartSeriesValue = Object.values( chart.settings.series );
$.each( Object.keys( chart.settings.series ), function( index, element ) {
chartSeries[element] = chartSeriesValue[index];
} );
chart.settings.series = chartSeries;
var seriesKeys = Object.keys( chart.settings.series );
// Only convert when keys are numeric indices (PHP JSON-encoded array).
// String keys (e.g. named series from manual config) must be left as-is.
if ( seriesKeys.every( function( k ) { return ! isNaN( k ); } ) ) {
var chartSeries = [];
var chartSeriesValue = Object.values( chart.settings.series );
$.each( seriesKeys, function( index, element ) {
chartSeries[ element ] = chartSeriesValue[ index ];
} );
chart.settings.series = chartSeries;
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change fixes a user-facing crash on resize; the repo has Playwright e2e coverage for chart creation/embedding, but there doesn’t appear to be a regression test for resizing a Google Bubble chart with a manual config that defines named (string-keyed) series. Adding an e2e test that renders such a chart and triggers a viewport resize would help prevent this from coming back.

Copilot uses AI. Check for mistakes.
@HardeepAsrani HardeepAsrani merged commit 5101ede into development Mar 10, 2026
13 of 14 checks passed
@HardeepAsrani HardeepAsrani deleted the fix/issue-485 branch March 10, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-checklist-complete The Pull Request checklist is complete. (automatic label) pr-checklist-skip Allow this Pull Request to skip checklist.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants