Allow opt-in bubble-phase form tracking #1457
Merged
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.
In v4 we switched to document-level listeners in the Form Tracking plugin to avoid needing to periodically re-call
enableFormTrackingwhen new forms have been added to the DOM for them to be tracked (and also less listeners theoretically has better performance).As part of this change, we also switched to using capture-phase events.
This was for two main reasons:
focusevent doesn't actually bubble, so if we weren't using capture phase the tracking just doesn't work for this eventstopImmediatePropagationwhich meant our target/bubble phase listeners never got called and so they could not track some events at all; since capture phase goes first we could track the events before propagation was stopped so this was more reliableThe downside of firing in the earlier phase is that if you require some kind of state to change in the target/bubble phase (e.g. form validation) and you rely on that in your transform/filter functions, those operations will no longer occur in time for you to depend on them.
Such a situation was reported in CSTMR-1776.
This change allows opt-in disabling capture phase for the
change/submitevents to go back to the old bubble-phase behavior. This lets you choose less reliable event detection in exchange for running later if needed, via auseCapture: falseoption.The default remains using capture-phase, and capture-phase is hard-coded for the
focusevent since it would fail to work otherwise.Not sure who is best to review on your team @cksnp so just assigning to you for now. :)