Skip to content

Conversation

@dircm
Copy link
Contributor

@dircm dircm commented Nov 28, 2021

This PR adds a decoupling of the entangled input property and the input component used for entering an autocomplete search item.

Problem: Because the input is x-model bound to the entangled input property on the model, on occasion if the user is typing too slowly, the livewire entangled update would interfere with the typed input. This is essentially a race condition between the input value and the livewire representation of the value.

Solution: Decouple the input from the entangled livewire property by adding a new Alpine property (debouncedValue). This property holds the value of the input value via an x-model binding. When the input is updated, the input() function will set the entangled value property and update the livewire component. When livewire sends subsequent updates for value, a $watch function listens for thoes updates and will only set the Alpine debouncedValue property if some conditions are present Thus it ignores livewire updates and breaks the input interference race condition. Livewire updates are processed if the debouncedValue is empty or null to allow for initial state setting (if a preset livewire value is present) and also when setSelected() has been called.

All tests passing but no extra failing tests were added.

@joshhanley joshhanley merged commit c94cfd2 into joshhanley:main Dec 1, 2021
@joshhanley
Copy link
Owner

Thanks @dircm great PR! 😁 Should make the component more stable to use now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants