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

FireBlade's avatar

Alpinejs click handler runs twice

app.blade.php

<head>
<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>
</head>
<body>

post.blade.php

<div x-data="{ }">
  <button @click="console.log('Click!')">Click it!</button>
</div>

Why is this code running twice when I click ONCE ?

0 likes
11 replies
Sinnbeck's avatar

@FireBlade Yes. How can we recreate it? :) Or is the page live somewhere so we can inspect the dom?

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Ah I was able to recreate it. Just load alpine twice. So it seems you are loading it twice somehow. Either via 2 scripts (in different places) or perhaps also in your compiled app.js ?

Loaded once by jsfiddle, and I also load it on the page: https://jsfiddle.net/vj1rfugs/

2 likes
FireBlade's avatar

@Sinnbeck I have deleted this line in the head section of app.blade.php and it looks good now :

<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>

Alipine looks to be auto include under resources/js/app.js. Thanks a lot

Snapey's avatar

perhaps you have more than one clickable element?

1 like
princevora's avatar

I was also having the same issue, my functions were calling a twice, there was a silly problem. I searched for the alpine package import in my laravel project i found that my one of the laravel package had already imported the alpine library and i had imported it in my html's head when i removed one of the imports it was working fine

Please or to participate in this conversation.