amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-lightbox closes without user interaction on Tab switch

Open dritter opened this issue 4 years ago • 2 comments

We encountered a strange Bug with amp-lightbox closes automatically if the user switches Tabs in Chrome.

amp-lightbox--autoclose

Reproducer

See Reproducer in AMP-Playground

If you click on the first slide, the lightbox opens. If you now go to another Tab in Chrome, and come back, the lightbox closes without user interaction. I traced it down to history-impl.js trying to pop the history in

if (toPop.length > 0) {
      for (let i = 0; i < toPop.length; i++) {
        // With the same delay timeouts must observe the order, although
        // there's no hard requirement in this case to follow the pop order.
        this.timer_.delay(() => toPop[i](historyState), 1);
      }
    }

and eventually calling this code in amp-lightbox-0.1.js:

F(a.getAmpDoc(), "history").push(function() {
                return a.close(c)
            }).then(function(U) {
                a.ca = U
            });

Checked mutations of test code

This does NOT happen, if I:

  • remove the amp-carousels
  • change the "close lightbox" link to a button
  • remove the "close lightbox" link
  • remove the on="tap:my-lightbox.close" attribute on the link

Wild Guess

As this only happens if there is a link inside the lightbox that closes it, I think that is the culprit.

Workaround

For anyone who is affected by this bug right now: Change the "Close Lightbox" Link to a button..

Related Bugs

Probably #17442 is related.

Affected AMP Version

At least 2012301722001, but I've seen it earlier..

Affected Browsers

Tested in Chrome 87.0.4280.141, but probably more Browsers are affected by this.

// cc @choumx (sorry) because of his investigation in #17442

dritter avatar Jan 13 '21 19:01 dritter

Even though this looks similar to https://github.com/ampproject/amphtml/issues/32449, this is not fixed with the release of 2101230412006.

dritter avatar Feb 09 '21 07:02 dritter

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 12 '22 00:08 stale[bot]