Skip to content

Commit

Permalink
fixup! Event: Increase robustness of an inner native event in leverag…
Browse files Browse the repository at this point in the history
…eNative
  • Loading branch information
mgol committed Apr 28, 2024
1 parent 0582060 commit 1952220
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,24 @@ function leverageNative( el, type, isSetup ) {
var result,
saved = dataPriv.get( this, type );

// This controller function is invoked under multiple circumstances,
// differentiated by the stored value in `saved`:
// 1. For an outer synthetic `.trigger()`ed event (detected by
// `event.isTrigger & 1` and non-array `saved`), it records arguments
// as an array and fires an [inner] native event to prompt state
// changes that should be observed by registered listeners (such as
// checkbox toggling and focus updating), then clears the stored value.
// 2. For an [inner] native event (detected by `saved` being
// an array), it triggers an inner synthetic event, records the
// result, and preempts propagation to further jQuery listeners.
// 3. For an inner synthetic event (detected by `event.isTrigger & 1` and
// array `saved`), it prevents double-propagation of surrogate events
// but otherwise allows everything to proceed (particularly including
// further listeners).
// Possible `saved` data shapes: `[...], `{ value }`, `false`.
if ( ( event.isTrigger & 1 ) && this[ type ] ) {

// Interrupt processing of the outer synthetic .trigger()ed event
// Detect `saved` of shape `{ value }` and `false`.
if ( !saved.length ) {

// Store arguments for use when handling the inner native event
Expand Down Expand Up @@ -559,9 +573,8 @@ function leverageNative( el, type, isSetup ) {
event.stopPropagation();
}

// If this is a native event triggered above, everything is now in order
// Fire an inner synthetic event with the original arguments
// Exclude `saved` of shape `{ value }` and `false`.
// If this is a native event triggered above, everything is now in order.
// Fire an inner synthetic event with the original arguments.
} else if ( saved.length ) {

// ...and capture the result
Expand Down

0 comments on commit 1952220

Please sign in to comment.