Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Alpine Expression Error: Maximum call stack size exceeded

Hello,

I display a chart with Livewire / AlpineJS / ChartJS.

I think it's not a Livewire problem, but it's an AlpineJS problem. As there isn't any AlpineJS category here, I post this in the Livewire category.

In the Livewire component, I retrieve the datas for 2 charts.

class Charts extends Component
{
    public $charts = [];
    public $activeChart = 0;

    public function mount()
    {
        $this->charts[] = (new ChartService)->categories();
        $this->charts[] = (new ChartService)->shops();
    }

    public function render()
    {
        $categoriesChartHeight = 50 + Category::count() * 50;
        $shopsChartHeight =  50 + Shop::count() * 50;

        return view('livewire.charts', compact('categoriesChartHeight', 'shopsChartHeight'));
    }
}

In the view, I display the first chart.

The problem is when I click on the span to toggle to the second chart.

The chart isn't updated and I get this error.

Alpine Expression Error: Maximum call stack size exceeded

If I remove the this.chart.update(); line, I don't get the error any more."

For the moment the only solution I have found is to destroy the chart chart.destroy() and to create a new one with the new data. But doing this, I get a new error if I switch to the other chart before the animation is finished for the first displayed chart.

Uncaught TypeError: Cannot read properties of null (reading 'save')

Can you help me please ?

Thanks a lot.

V

0 likes
2 replies
vincent15000's avatar

Here are some details about the error.

chart__js_auto.js?v=e4f3bc99:1693 Uncaught TypeError: Cannot read properties of null (reading 'save')
    at clipArea (chart__js_auto.js?v=e4f3bc99:1693:7)
    at Chart._drawDataset (chart__js_auto.js?v=e4f3bc99:9010:7)
    at Chart._drawDatasets (chart__js_auto.js?v=e4f3bc99:8992:12)
    at Chart.draw (chart__js_auto.js?v=e4f3bc99:8963:10)
    at chart__js_auto.js?v=e4f3bc99:2985:15
    at Map.forEach (<anonymous>)
    at Animator._update (chart__js_auto.js?v=e4f3bc99:2963:18)
    at chart__js_auto.js?v=e4f3bc99:2954:12
vincent15000's avatar
vincent15000
OP
Best Answer
Level 63

I have solved my problem like this.

Here are the modifications :

  • charts: $wire.entangle('charts'), instead of @js()

  • I don't handle the chart modification in the toggle function, instead I dispatch an event from the toggle function

  • Livewire listens to the event and emit an event to AlpineJS

  • I handle the chart modifications from the AlpineJS event listener

What I wonder is why I cannot directly update the chart inside the toggle function ?

Do you have any idea ?

Please or to participate in this conversation.