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
Separate the initial creative size and the current creative size #14238
Conversation
@@ -476,11 +482,15 @@ export class SafeframeHostApi { | |||
(expandWidth > this.creativeSize_.width || | |||
expandHeight > this.creativeSize_.height))) { | |||
dev().error(TAG, 'Invalid expand values.'); | |||
this.sendResizeResponse( | |||
/* SUCCESS? */ false, SERVICE.EXPAND_RESPONSE); |
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 don't see any tests for the new sendResizeResponse
behavior
(here and 2x below)
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
height: creativeSize['height'], | ||
width: creativeSize['width'], | ||
}; | ||
|
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 don't think it matters much, but I'd expect getInitialGeometry
to use initialCreativeSize_
and not creativeSize_
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.
good point, changed
this.initialCreativeSize_ = { | ||
height: creativeSize['height'], | ||
width: creativeSize['width'], | ||
}; |
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 looks like before this PR we had:
creativeSize_
: initial creative size, what wecollapse()
tothis.iframe_.height/width
: current creative size
And now we have:
initialCreativeSize_
: initial creative size, what wecollapse()
tocreativeSize
: current creative size
It's not clear to me from the PR description and the changes here what this PR fixes. Why do we need a new variable instead of just using this.iframe_.height/width
for current size? Is there a bug that this fixes, or a new capability it adds?
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.iframe_.height/width is a string for starters, so having something that can actually be a number is nice. But I can change if needed.
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.
And the bug was that I erroneously thought that iframe.height was auto-updating as the height actually changes, which it does not.
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.
Can this go in the PR description then?
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.
(Including that this fixes a bug, and a little about what the bug was)
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
@@ -476,11 +482,15 @@ export class SafeframeHostApi { | |||
(expandWidth > this.creativeSize_.width || | |||
expandHeight > this.creativeSize_.height))) { | |||
dev().error(TAG, 'Invalid expand values.'); | |||
this.sendResizeResponse( | |||
/* SUCCESS? */ false, SERVICE.EXPAND_RESPONSE); |
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.
PR description should include the new sendResizeResponse
s
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
@@ -494,10 +504,12 @@ export class SafeframeHostApi { | |||
handleCollapseRequest_() { | |||
// Only collapse if expanded. | |||
if (this.isCollapsed_ || !this.isRegistered_) { | |||
this.sendResizeResponse( | |||
/* SUCCESS? */ false, SERVICE.COLLAPSE_RESPONSE); |
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.
Looks like this one is still missing a test?
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
@@ -160,6 +160,12 @@ export class SafeframeHostApi { | |||
/** @private {?({width, height}|../../../src/layout-rect.LayoutRectDef)} */ | |||
this.creativeSize_ = creativeSize; | |||
|
|||
/** @private {?({width, height}|../../../src/layout-rect.LayoutRectDef)} */ | |||
this.initialCreativeSize_ = { | |||
height: creativeSize['height'], |
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.
Why access via quotes? Can this just be this.initialCreativeSize_ = Object.assign({}, this.creativeSize);
Also note that creative size can be null here... is that expected?
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.
Replaced, that's better. And that's fine
…/amphtml into frizz-sf-update-creative-size
Fixes bug that I erroneously thought that iframe.height was auto-updating as the height actually changes, which it does not. iframe.height is a string also, so making new class variables that track current iframe size, original iframe size, and current slot size. This bug had the effect of breaking multiple resize requests in a row.
this.creativeSize_ was not sufficient for tracking sizes of the safeframe, need initialCreativeSize vs creativeSize which is current.
Also, send failure messages for some failure cases we were not already sending for: