That's normal because once JS is loaded, the variables are not updated.
But you are using Livewire. Why don't you handle this variable with Livewire instead of JS ?
You can also use AlpineJS, it works fine with Livewire (Livewire uses it).
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
My LiveWire component is checking if task was completed => when it is completed it will insert variable into a page.
<script>
var taskResult = [ ... ];
</script>
Task is completed before I load page => variable is inserted on the first load => variable is accessible by JS.
Task not completed on initial load => Livewire refreshes component a few times => task is now completed => inserts variable into HTML => this variable is NOT accessible by JS function although I see that variable is inserted into HTML code.
Please or to participate in this conversation.