Dynamically add rounded corners in stacked bar chart (amcharts 4)

I was following the guide from the documentation trying to implement the same feature, but can’t make the code work the same way. I am aiming to make series’s corners rounded on the right side if it’s the last series in the bar.

When the chart is rendered initially I see the desired rounded corners, but once I start to toggle series, corner radius properties are not updated dynamically (e.g. the third piece of the bar becomes the last one but it doesn’t start having rounded corners on the right side).

That's how it looks now

I tried to log the currentColumnValueX property and I see, that when I toggle for example Asia series, currentColumnValueX is always equals Asia‘s valueX. That results in the check on the last line of adapter function always being false.

const borderRadiusAdapter = (_, target) => {
  if (!chart) {
    return 0;
  }

  const dataItem = target.dataItem;
  let lastSeries;

  chart.series.each((series) => {
    const isHidden =
      !series.properties.visible || series.isHidden || series.isHiding;
    const shouldProcessSeries =
      Boolean(series.dataFields.valueX) &&
      Boolean(dataItem.dataContext[series.dataFields.valueX]) &&
      !isHidden;
    if (shouldProcessSeries) {
      lastSeries = series;
    }
  });

  const currentColumnValueX = dataItem?.component?.dataFields?.valueX;
  const lastSeriesValueX = lastSeries?.dataFields?.valueX;
  
  // When I toggle Latin America in the legend, currentColumnValueX is always Latin America,
  // whereas lastSeriesValueX is Asia, I just can't understand why Asia is not rerendered, 
  // so it have rounded right side
  console.log('currentColumnValueX', currentColumnValueX)
  console.log('lastSeriesValueX', lastSeriesValueX)
  return lastSeriesValueX && lastSeriesValueX === currentColumnValueX ? 10 : 0;
};

Here’s the codepen with the full implementation.

Could someone tell me, please, what might be the problem?