Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gray border on image for alt with no src bug on lightbox #12379

Merged
merged 4 commits into from Dec 9, 2017

Conversation

cathyxz
Copy link
Contributor

@cathyxz cathyxz commented Dec 8, 2017

Fixes #12366.
Problem:
Multiple browsers gives images with alt but not src attribute a gray border. On ImageViewer initialization, we set all the aria attributes including alt, but not the src attribute unless the image has loaded. Therefore when we open the lightbox for the first time, before the image loads, safari shows an ugly gray border. This happens every time we scroll to a new image for the first time. Applies to: mobile safari, mobile chrome, mobile firefox, desktop safari.

Proposed solution:
Special case safari to not set the alt attribute until after we set src.

There are multiple hack solutions to this problem, including setting opacity to 0 until we set src, setting a tiny transparent src, but nothing elegant comes to mind. If an immediate better solution comes to mind, I'm very open to suggestions. I think we could also revisit this after reviewing Lightbox for performance because depending on how we refactor the order of doing things, this bug might no longer be applicable by then.

Testing:

  • ios safari
  • ios chrome
  • ios firefox
  • desktop chrome
  • desktop safari
  • android chrome
  • android firefox

@cathyxz cathyxz self-assigned this Dec 8, 2017
@cathyxz cathyxz changed the title Fix safari gray border bug on lightbox Fix gray border on image for alt with no src bug on lightbox Dec 8, 2017
@cathyxz cathyxz removed their assignment Dec 8, 2017
Copy link
Contributor

@cvializ cvializ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice and simple

} else {
// Most browsers show a gray border for images with alt but no src
// If we did not set the src, remove the alt attribute
this.image_.removeAttribute('alt');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it get set initially? Is it only through updateSrc_?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gets set initially in the init function here (this code is in the init function) IFF the image has already loaded. Then in updateSrc it gets set again. The basic idea is that you set the already loaded image src in init, and then you upgrade it to the best fit version from srcSet in updateSrc. updateSrc is also called after every measure(), since measure updates the height and width of the image. But if the image wasn't loaded, then you shouldn't be setting the src here.

But this behavior definitely raises the question of a perf bug... all of these images should have already been loaded by the time you click on them to load the lightbox. Although there are alternate ways of triggering the lightbox, which makes the code here reasonable, there's almost definitely something wrong with the way we're detecting whether an image has loaded here... =.="

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, actually it's because we are not passing in the sourceImage parameter to init. This was an oversight in my original port of the implementation. Testing in progress, fix incoming.

@cathyxz
Copy link
Contributor Author

cathyxz commented Dec 9, 2017

Retested this on all devices--the initial load speed for the first 3 images in carousel is now a lot better. The grey box problem is solved by setting the image to 0 width and height. Using this implementation because this also solves the problem of images with a loaded src being initialized in the wrong position, since at init time, the ImageViewers are placed in invisible slides and the positioning / sizes are all completely off.

@cvializ
Copy link
Contributor

cvializ commented Dec 9, 2017

Excellent, nice job assessing and improving the performance! Double LGTM

@cathyxz cathyxz merged commit cf53b4e into ampproject:master Dec 9, 2017
@cathyxz cathyxz deleted the bugfix/lightbox-box branch December 9, 2017 00:45
@aghassemi
Copy link
Contributor

Good stuff!
LGTM

jpettitt pushed a commit to jpettitt/amphtml that referenced this pull request Dec 11, 2017
…ect#12379)

* Fix safari gray border bug on lightbox

* Add special case for iOS

* Actually this bug applies to most mobile browsers and desktop safari

* Set image source properly, initialize height width to zero
gzgogo pushed a commit to gzgogo/amphtml that referenced this pull request Jan 26, 2018
…ect#12379)

* Fix safari gray border bug on lightbox

* Add special case for iOS

* Actually this bug applies to most mobile browsers and desktop safari

* Set image source properly, initialize height width to zero
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants