-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Remove native srcset experiment and update fallback logic #16404
Remove native srcset experiment and update fallback logic #16404
Conversation
test/functional/test-amp-img.js
Outdated
@@ -317,7 +279,7 @@ describe('amp-img', () => { | |||
}); | |||
}); | |||
|
|||
it('should fallback only once', () => { | |||
it('should fallback once and remove fallback once image loads', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I combined this with the next test because the behavior here changed. Since we no longer set src
based on the result of parseSrcset
, the only thing that determines whether an image should show or hide its fallback is whether or not the image loaded, i.e. the result of loadPromise
.
806282e
to
83f18dd
Compare
@@ -188,18 +139,13 @@ export class AmpImg extends BaseElement { | |||
/** @override */ | |||
layoutCallback() { | |||
this.initialize_(); | |||
let promise = this.updateImageSrc_(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic block was refactored into the load
and error
listeners on the right.
} | ||
|
||
this.img_.setAttribute('src', src); | ||
hideFallbackImg_() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is directly taken from the then block of then original updateImageSrc
and should be unchanged.
// Would show the placeholder underneath a transparent fallback | ||
this.togglePlaceholder(false); | ||
}); | ||
if (this.allowImgLoadFallback_) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the if condition here to encompass the listener in a single function.
83f18dd
to
67fdf73
Compare
f0b81d1
to
76420b3
Compare
Codecov Report
@@ Coverage Diff @@
## master #16404 +/- ##
==========================================
+ Coverage 77.15% 78.18% +1.03%
==========================================
Files 547 552 +5
Lines 39934 40344 +410
==========================================
+ Hits 30812 31544 +732
+ Misses 9122 8800 -322
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need docs changes. /cc @bpaduch
Can we remove all the other SrcSet
uses yet?
Based on the history on the original issue and the @bpaduch are there other references to |
I think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm satisfied with the code.
/to @bpaduch to look over the docs.
</head> | ||
<body> | ||
<h1>amp-image</h1> | ||
<!-- <h2>Unsupported formats</h2> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uncomment
ping @bpaduch can we merge? |
@cathyxz: Go ahead, we can review docs later. |
Filed #16625 to track docs update. Waiting for Travis (there have been a couple of flakes on this PR today). |
This PR deletes the experiment specific code for
amp-img-native-srcset
so that we're running nativesrcset
permanently instead of doing our ownsrcset
logic (closes #11575). The experiment / prod/canary-config.json files now have to be edited as a separate PR per new build rules. Turns out that it broke the fallback image logic (which was dependent on checking whether the src should change on resize), so I refactoredupdateImageSrc
into two listeners for onload
anderror
. Annotations inline.Testing:
In Summary
loadPromise(this.img_)
rejects), no more checking for whether selectedsrc
equalsthis.img_.src
.loadPromise
for this check. Namely, that there can be a race condition between the resize which callslayoutCallback
and tries to check for error / load in order to toggle the fallback, and the load / error event itself. This causes problematic behavior on Firefox/Safari/Chrome where they don't show the fallback image.load
anderror
on the underlying<img>
.Not Addressed in this PR
Further details on the different behaviors of
srcset
per browser at: go/amp-img-srcset