You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
$watch can fire after being unwatched when Livewire's morph removes its element #4902
When an Alpine component using $watch (or Livewire's $wire.$watch) is removed from the page, a change to a value it was watching can still run the watch callback once, even though the component is already gone.
In a Livewire app this shows up when a component is removed by a morph (e.g. a wire:key change, an @if toggling off, a list item disappearing) in the same request that also updated a property the component was watching with $wire.$watch (like resetting it). The callback still fires one extra time for an Alpine component that's already been removed from the page, which can throw errors.
A workaround would be to store a destroyed state set to true in the hooked destroy() function, and check it in every watched callback, but I think this can be fixed directly in the package.
Code snippets to reproduce the issue
Click the button. It removes the inner element and after that it changes foo. calls becomes 1.
Activity