-
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
Collapse empty ads #1265
Collapse empty ads #1265
Conversation
f136819
to
134eb1a
Compare
@@ -283,6 +283,10 @@ export function installAd(win) { | |||
* @private | |||
*/ | |||
noContentHandler_() { | |||
if (!this.placeholder_) { | |||
this.element.style.height = 0; |
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.
display: none
please.
It should only do this when resizing is allowed. @dvoytenko can point you at the relevant code.
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.
- Yes, I don't see why we shouldn't do
display:none
. - Malte is correct, all DOM mutations here should go via
this.deferMutate(callback)
. It ensures that (a) the changes are done in the mutate phase and (b) they don't interfere with scrolling. toggleFallback(true)
combined withdisplay = none
orheight = 0
makes no sense.
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.
Let's clear up this issues. Another problem is that just setting display to none (or height to 0) directly won't be able to adjust scroll position. If that's desirable, we'd need to do a bit more work here.
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.
Made it display:none
also the noContentHandler_
method is called with defer mutate so i dont think ill have to do it here again.
this.deferMutate(this.noContentHandler_.bind(this));
@dvoytenko any tips on how to adjust scroll position?
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.
Thinking this through again. The only way to adjust scroll position is to go back to, initially, setting height to 0. Not directly, but rather via this.changeHeight
API. What we need to do is schedule display:none
via deferMutate
right after changeHeight
has completed. We currently don't have that option - so we need to add it. E.g. we need to add an optional callback to changeHeight
API that will be called as soon as it has completed. So, it will look like this:
this.changeHeight(0, () => {
this.deferMutate(() => display = 'none');
})
However, one more thing,
if (!this.placeholder_) {
this.element.style.display = 'none';
} else {
this.toggleFallback(true);
}
I still don't think that this is correct. Placeholder and fallback are not necessarily related. There's some confusion going on here. For instance, if there's no placeholder, but there's fallback, should we still hide the whole element?
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.
Nice co-incidence - i was just pinging you about this
we have a fallback and a placeholder implemented
the md file does not say anything about the fallback
but the fallback is the only thing that is displayed when there is no ad content
I am going to update the MD file to reflect usage for fallback
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.
@dvoytenko updated the code to have optional callbacks on change height - let me know if this is correct - ill update the tests and get this in.
99fdbd1
to
565f479
Compare
* }} | ||
* @private | ||
*/ | ||
let ChangeHeightRequest; |
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.
ChangeHeightRequestDef
- see "Def" suffix.
All looks good. I left a couple of minor comments. The big thing, however, we need to confirm how we work with placeholder here. My sense is that fallback and placeholder are interoperable here and we need some basic priority mechanism for them. |
this.element.removeChild(this.iframe_); | ||
this.toggleFallback(true); | ||
if (!this.fallback_) { | ||
this.changeHeight(0, () => { |
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.
Does the height and the display:none
happen in the same instant?
Does this do nothing if resize is not allowed?
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.
Does the height and the display:none happen in the same instant?
No it does not -
Does this do nothing if resize is not allowed?
changed it to use requestChangeHeight , which only changes height if allowed.
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.
It would be important to do it in the same instant to reduce the number of style recalcs and layouts to 1. Setting display to none is a much cheaper op than setting height to 0, because the former doesn't require layouting the children.
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.
Ping on this.
bdf9405
to
fd8210a
Compare
* }} | ||
* @private | ||
*/ | ||
let ChangeHeightRequestDef; |
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.
Done - Where do i see "Def" suffix info?
ea23b34
to
facc71b
Compare
PTAL |
this.toggleFallback(true); | ||
if (!this.fallback_) { | ||
this./*REVIEW*/changeHeightIfAllowed(0, () => { | ||
this.deferMutate(() => this.element.style.display = 'none'); |
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.
As Malte requested - he wanted to do it in the same mutate context. If so - let's do.
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.
Done
Couple more comments. |
ca0a6a7
to
b98882d
Compare
LGTM after issue with naming is resolved. |
b98882d
to
d80720d
Compare
@@ -64,13 +64,23 @@ Optional attribute to pass configuration to the ad as an arbitrarily complex JSO | |||
|
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.
Add a sentence:
The amp-ad
tag will be collapsed (set to display: none
) if the ad sends a message that the ad slot cannot be filled and AMP determines that this operation can be performed without affecting the user's scroll position.
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.
Done
d80720d
to
4368721
Compare
@@ -283,8 +283,17 @@ export function installAd(win) { | |||
* @private | |||
*/ | |||
noContentHandler_() { | |||
this.element.removeChild(this.iframe_); | |||
this.toggleFallback(true); | |||
if (!this.fallback_) { |
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.
Add comment explaining what happens
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.
Done
LGTM |
4368721
to
b2fe74a
Compare
Collapse empty ads (When possible)
#1089