Open OvermindDL1 opened 7 years ago
Wow this is a lot of information. :) Could you explain me how to reproduce this bug please ?
Basically I was just setting activated-action-id
to a variable that usually contained zero in the <dom-repeat>
loop as I was displaying a list of things. At that point on any that were 0 stopped swiping, and any attempts to swipe did nothing. I traced it into the _fireEvent where _mute was NaN
and followed it back from there. :-)
When
activatedActionId
is set to a falsey value like "" or 0 then as per the_onActivatedActionIdChange
function (line 421 as of the current release version):It is setting
this._mute = 1
, then sincenewValue
is falsey it then setsthis._mute++
, which is settingthis._mute
to be 2, then callsthis.reset(false)
, and reset calls:And _snapBack calls:
Which since
animate
is false it will call the else branch, which callsthis._cleanupAfterTransition()
, which is:Which does a few things, but ending up with
this._mute--
, which will setthis._mute
back to 1, so nowthis._mute
is left at 1. Now later when the element is swiped away, which ends up calling this same function but withthis._willBeSwipedAway
set to true, sothis._fireEvent('swiped-away')
gets called, and it is:Where
this._mute
is still1
, thus this event is skipped and never fired, ever again. The issue appears resolved by going back to the first_onActivatedActionIdChange
function definition of:And just wiping out the
this._mute++;
line entirely, that will leavethis._mute
as 1 in the reset call, which ends up setting it back to 0 whenthis._mute--
is run in the_cleanupAfterTransition
function, thus restoring the state.However, this reveals another bug,
this._mute
is never initialized unlessactivatedActionId
is set, meaning that it is by defaultundefined
. When_cleanupAfterTransition
is called on every swipe it will in turn callthis._mute--
on an undefined value, thus settingthis._mute
to beNaN
, which will allow the events to be fired when_fireEvent
is called regardless. But by settingactivatedActionId
it makesthis._mute
= 0 by the end of its call (or 1 without the above fix in some cases), so when it is swiped or reset it decrementsthis._mute
via thethis._mute--
call inside_cleanupAfterTransition
, which makes it <0, thus in the_fireEvent
function:Then
!-1
via the!this._mute
check (or lower value) will be false and the events stop firing again and never fire again untilactivatedActionId
is set again, of which it will then only fire once more and never again until it is set yet again.This second issue 'should' be fixed properly by always setting a default value to
this._mute
on construction and fixing up the code elsewhere, however a quick-fix that will always work (in my testing) is to just changethis._mute--;
in function_cleanupAfterTransition
into beingthis._mute = this._mute>0 ? this._mute-1 : 0;
since it being the only place doing the decrementing means that it needs to make sure it does not go below 0 and it will always default set it to 0 otherwise.