The issue you're experiencing, where the resend method is triggered twice, is likely due to multiple event listeners or actions being bound to the same event. This can happen in Livewire components if there are multiple elements or actions that inadvertently trigger the same method.
Here are a few steps to troubleshoot and resolve the issue:
-
Check for Duplicate Event Listeners: Ensure that there are no duplicate event listeners or bindings in your Livewire component that might be causing the method to fire twice.
-
Inspect the Blade Template: Make sure that the
wire:clickdirective is not being applied to multiple elements unintentionally. Double-check your Blade template to ensure that theresendmethod is only being called once per user action. -
Prevent Default Behavior: You are already using
wire:click.prevent, which is good. This prevents the default action of the click event, but ensure that there are no other JavaScript or Livewire interactions that might be causing the method to trigger twice. -
Check for JavaScript Interference: If you have any custom JavaScript that interacts with the Livewire component, ensure that it is not causing the method to be called multiple times.
-
Livewire Component Lifecycle: Ensure that the Livewire component is not being re-rendered in a way that causes the method to be called twice. This can happen if there are multiple Livewire components on the page that might be interacting with each other.
-
Debugging: Add additional logging or debugging statements to see if there are any patterns or specific conditions under which the method is called twice.
Here's a refined version of your Blade component to ensure it's set up correctly:
<x-icon-link
wire:click.prevent="resend({{ $teamUser->id }})"
icon="envelope"
class="cursor-pointer !text-accent hover:!text-accent-dark"
wire:loading.attr="disabled"
/>
If after checking all these points the issue persists, consider isolating the problem by creating a minimal version of the component and method to see if the issue still occurs. This can help identify if the problem is with the specific setup or something else in your application.