Skip to content

Commit

Permalink
Attempt to fix LightboxGallery issue (ampproject#25375)
Browse files Browse the repository at this point in the history
I think we're receving badly ordered gestures, which is causing ampproject#22533.

Now, if we receive a subsequent gesture without first receving the `first` geture, we'll early exit. That should solve the bug. I'm also adding error reporting, so we can track down exactly how this is happening.
  • Loading branch information
jridgewell authored and Micajuine Ho committed Dec 27, 2019
1 parent 5617a2a commit 43c4df2
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions extensions/amp-lightbox-gallery/0.1/amp-lightbox-gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ export class AmpLightboxGallery extends AMP.BaseElement {
/** @private @const */
this.boundMeasureMutate_ = this.measureMutateElement.bind(this);

/** @private {boolean} */
this.swipeStarted_ = false;

/** @private @const */
this.swipeToDismiss_ = new SwipeToDismiss(
this.win,
Expand Down Expand Up @@ -633,14 +636,15 @@ export class AmpLightboxGallery extends AMP.BaseElement {
* @param {!SwipeDef} data
*/
swipeGesture_(data) {
// Check if the carousel has been cleared out due to close. It is unclear
// how this is happening, but there are errors where the carousel is null
// at this point.
if (!this.carousel_) {
return;
}

if (data.first) {
if (this.swipeStarted_) {
dev().error(
TAG,
'badly ordered swipe gestures: second first without last'
);
}
this.swipeStarted_ = true;

const {sourceElement} = this.getCurrentElement_();
const parentCarousel = this.getSourceElementParentCarousel_(
sourceElement
Expand All @@ -655,8 +659,17 @@ export class AmpLightboxGallery extends AMP.BaseElement {
return;
}

if (!this.swipeStarted_) {
dev().error(
TAG,
'badly ordered swipe gestures: subsequent without first'
);
return;
}

if (data.last) {
this.swipeToDismiss_.endSwipe(data);
this.swipeStarted_ = false;
return;
}

Expand Down

0 comments on commit 43c4df2

Please sign in to comment.