Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This reverts the changes made in #3097 and #3033. It adds one small change to the original behavior to clear the throttle timeout on blur.
Relates to: #3097
Relates to: #3033
Relates to: #2318
Relates to: #3076
In #2318 a "bug" was shown where a range input with phx-throttle resets after the DOM is patched. This led me to first try to always run the event callback on blur (#3033) and later optimized this approach to ensure the last event that was throttled gets emitted at the end of the throttle timeout (#3097). This last one also accidentally introduced a bug where a singular event with phx-throttle would be dispatched again after the throttle timeout (#3105). Also, these changes that are basically only relevant for cases like range inputs complicated the already complicated debounce/throttle code even more.
This PR adjusts the throttle code in a minimal approach to allow the use cases where the user wants to get the latest value on blur when throttle is used. In these cases, simply adding a
phx-blur={JS.dispatch("change")}
is the way to go: