Implementing amp-playbuzz extension (#6106)#6351
Implementing amp-playbuzz extension (#6106)#6351dvoytenko merged 14 commits intoampproject:masterfrom playbuzz:extensions/amp-playbuzz
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
|
I signed it! |
|
/to @dvoytenko, feel free to reassign. |
|
CLAs look good, thanks! |
| */ | ||
|
|
||
| .pb_feed_loading { | ||
| height: 320px; |
There was a problem hiding this comment.
Please use 2sp for indent.
There was a problem hiding this comment.
Hmm. Not seeing the changes. Did you push the latest commit?
| * limitations under the License. | ||
| */ | ||
|
|
||
| .pb_feed_loading { |
There was a problem hiding this comment.
To confirm: are these styles meant to be customized by clients? Or are they strictly internal?
There was a problem hiding this comment.
internal. it's the loader's styles
There was a problem hiding this comment.
Ok. It's our convention to name internal classes with - prefix. But it's up to you.
| } | ||
|
|
||
| .pb_top_content_container { | ||
| opacity: 1; |
There was a problem hiding this comment.
The style above conflicts with this one.
| } | ||
|
|
||
| .pb_feed_placeholder_container { | ||
| position: absolute; |
There was a problem hiding this comment.
Placeholders (attribute placeholder) are automatically sized 100% of the container. Or is this for some other placeholder functionality?
There was a problem hiding this comment.
that's taking care of the internal arrangement of the placeholder + loading indicator
| box-sizing: border-box; | ||
| } | ||
|
|
||
| .pb_ie_fixer { |
There was a problem hiding this comment.
Please add a comment up top of what specifically is fixed in IE with this style.
There was a problem hiding this comment.
actually i tried using css animation before i noticed AMP doesnt allow it
this was a fix for that in IE but since it's no longer relevant i'll remove it
There was a problem hiding this comment.
AMP generally allows CSS animations and we can allow it here as well. Let's come back to it in a follow up PR.
extensions/amp-playbuzz/0.1/utils.js
Outdated
| } | ||
| } | ||
| catch (e) { | ||
| dev().log(err, e); |
There was a problem hiding this comment.
There's no log() method. Can you please double check? Also, generally, it's easier to just use rethrowAsync.
extensions/amp-playbuzz/0.1/utils.js
Outdated
| return {}; | ||
| } | ||
|
|
||
| dev().log(err, data); |
There was a problem hiding this comment.
Ditto: there's no log method. Also, most of methods take tag name as the first argument. E.g. amp-playbuzz.
| generateEmbedSourceUrl_() { | ||
| const params = {}; | ||
| params.itemUrl = this.item_.replace('https://', '//').replace('http://', '//').split('#')[0]; | ||
| params.relativeUrl = params.itemUrl.split('.playbuzz.com')[1]; |
There was a problem hiding this comment.
Please use url.js APIs for this.
There was a problem hiding this comment.
i was looking for something like this! nice!
| `Enable ${EXPERIMENT} experiment`); | ||
|
|
||
| const e = this.element; | ||
| this.item_ = user().assert( |
There was a problem hiding this comment.
What are requirements for this URL? Should it be https? Please use assertHttpsUrl in that case.
There was a problem hiding this comment.
no requirement for https, i just need it to be a valid playbuzz url.
a publisher can just copy his item url (http/https) and pase it into the amp-playbuzz src field and it should work.
that's the reason i'm dropping the scheme and use double slashes // for the beginning (to avoid cors issues)
extensions/amp-playbuzz/0.1/utils.js
Outdated
| const embedUrl = options.itemUrl + | ||
| '?feed=true' + | ||
| '&implementation=amp' + | ||
| '&src=' + options.itemUrl + |
There was a problem hiding this comment.
Looks like you need encodeURIComponent here. Generally, you can just use serializeQueryString API from url.js to do this for you. There are a couple of places below with the same issue.
|
@buzzdan This looks great! I left a few comments. PTAL. |
|
@dvoytenko Thanks for the detailed review! |
|
|
||
| this.applyFillContent(iframe); | ||
| this.element.appendChild(iframe); | ||
| setStyles(this.element, {'height': '300px'}); |
|
|
||
| setStyles(iframe, { | ||
| 'opacity': 0, | ||
| 'min-height': '300px', |
There was a problem hiding this comment.
Please remove all height designators.
| 'min-height': '300px', | ||
| 'height': '300px', | ||
| }); | ||
| setStyles(this.element, {'height': '300px', 'min-height': '300px'}); |
There was a problem hiding this comment.
It shouldn't be getting 100%, but possible if you CSS somewhere resizes it this way. For now, let's focus on user-specified height and let it do the work. We can look if we can/need do default later. In the example above, the responsive layout will automatically resize you embed to take all available width and then will set the height proportional to the width. In that particular case, given layout=responsive width=300 height=300, the height will be equal to the width. If that's not the case, please check your CSS and if you don't see the reason - let me know and I'll check it on my end.
|
@buzzdan Ok, looks good. I think in major things, only height questions are outstanding and scrolling. |
|
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
|
CLAs look good, thanks! |
|
@buzzdan Hi! Saw a big push. Ready for re-review? |
|
@dvoytenko so far i've dealt mostly with the height issue therefore added an overflow element (i needed to, right?), so we can review that part. about the scroll events, they are crucial for our items as it ties in directly with the UX we are trying to provide. |
Gregable
left a comment
There was a problem hiding this comment.
My review is for the validator rules only.
| html_format: AMP | ||
| html_format: AMP4ADS | ||
| tag_name: "SCRIPT" | ||
| spec_name: "amp-playbuzz extension .js script" |
There was a problem hiding this comment.
For new tags, we want to add a requirement that if the .js file is present, a corresponding tag is also present, to avoid javascript being loaded which isn't used, a performance anti-pattern. This is fairly new, so most tags don't have it, but an example would be https://github.com/ampproject/amphtml/blob/master/extensions/amp-reddit/0.1/validator-amp-reddit.protoascii
Can you add here:
also_requires_tag: "amp-playbuzz"
| tag_name: "AMP-PLAYBUZZ" | ||
| also_requires_tag: "amp-playbuzz extension .js script" | ||
| attrs: { | ||
| name: "src" |
There was a problem hiding this comment.
all optional:
Do you want any constraints on this src attribute value to help folks spot errors? Specifically, you could enforce that this is a URL (see https://github.com/ampproject/amphtml/blob/master/extensions/amp-list/0.1/validator-amp-list.protoascii for an example).
Similarly, do you want to require any of the data- attributes shown in your examples? All data- attributes are allowed by default, but this means that small typos don't typically generate errors and can be subtle to catch. You can require a set here if that is your preference.
Overflow element (at least initially) is desirable - yes. In the follow up PRs we can look into this in a bit more detail.
Yes, I'd definitely like to see this. Feel free to ping me on Slack with times. In particular, I have Thur and Fri this week fairly open. My suggestion for now was to merely delay this feature for the first pull request. There are still some steps we need to take to deploy the extension and update validators, so I'm eager to get the initial merge as soon as practical; while other details can worked out next. If you really want to get scroll events on the first merge - then, yes, let's get together at the earliest convenience and take a look if we can speed their inclusion up. |
| import {Layout, isLayoutSizeDefined} from '../../../src/layout'; | ||
| import {removeElement} from '../../../src/dom'; | ||
| import {isExperimentOn} from '../../../src/experiments'; | ||
| // import {setStyles} from '../../../src/style'; |
|
|
||
| /** @override */ | ||
| unlayoutCallback() { | ||
| this.unlisteners_.forEach(unlisten => unlisten()); |
There was a problem hiding this comment.
Also add this.unlisteners_.length = 0;
|
@buzzdan Otherwise, it looks like we are ready pending scroll events. I added couple more comments. PTAL. |
|
|
||
| /** @override */ | ||
| isLayoutSupported(layout) { | ||
| return layout === Layout.RESPONSIVE; |
There was a problem hiding this comment.
Ping on this question. I'm pretty sure you just need isLayoutSizeDefined and it should be ok with default rules.
|
|
||
| return this.iframePromise_ = this.loadPromise(iframe).then(() => { | ||
|
|
||
| this.attemptChangeHeight(this.itemHeight_).catch(() => {/* die */}); |
There was a problem hiding this comment.
There's no a lot of reason to call attemptChangeHeight here. Normally you only need to update height when your embed sends you a request to do so.
Are you just trying to make sure you have some minimal height here? (300px?) If yes - this code can actually reduce the size of your element in this case.
|
@buzzdan Just a couple more comments here, mainly on the initial height. We'll chat tomorrow about scroll events. We can touch base on the height as well. Generally (pending scroll discussion), I can already merge this code and we can clear up additional questions as a follow up. |
| event: 'scroll', | ||
| windowHeight: changeEvent.height, | ||
| scroll: changeEvent.top, | ||
| offsetTop: viewport.getLayoutRect(this.element).top, |
There was a problem hiding this comment.
Please use this.getLayoutBox().top for offsetTop.
There was a problem hiding this comment.
about the layout:
from my tests responsive & fixed-height layouts work as expected and we can support it starting now.
fixed layout would just be broken since the item cant be displayed fully
for some reason fill layout floats over the rest of the elements with position:absolute
(from the docs it seems that its supposed to catch its partent height and width)
flex-item might work with some extra adjusments but for now placeholder seems to be broken with it and the item wouldnt load. i need to look deeper into it.
There was a problem hiding this comment.
fixed layout would just be broken since the item cant be displayed fully
Can't displayed fully horizontally you mean? Because you set your own height vertically...
for some reason fill layout floats over the rest of the elements with position:absolute
(from the docs it seems that its supposed to catch its partent height and width)
It takes the height/width of its offset parent, i.e. a parent with position:relative or position:absolute.
flex-item might work with some extra adjusments but for now placeholder seems to be broken with it and the item wouldnt load. i need to look deeper into it.
Flex-item should work - it's a convenient mechanism of authors who like to use flexbox for layout.
| const scrollingData = { | ||
| event: 'scroll', | ||
| windowHeight: changeEvent.height, | ||
| scroll: changeEvent.top, |
There was a problem hiding this comment.
So, to repeat question here. The intersection observer use is mostly equivalent if this code was:
{
scroll: scrollTop - offsetTop,
offsetTop: 0,
}
The nuance here is that you don't know the exact top scroll position of the parent document and your position within it. But you DO know exactly which part of your embed is visible. Basically this emulates a situation where your embed is always at the very top of the page (offsetTop = 0).
Can you please comment on this? I'd like to get an idea if this is sufficient information for you or if you need more?
There was a problem hiding this comment.
Thanks for the detailed comment, this technology is very interesting.
let me get back to you soon as we're looking into it on our side
There was a problem hiding this comment.
Hey Dima, we need the scrolling events to understand where our iframe's content is relative to the top of the page, and we need this information to be up-to-date. So, understanding that sending a postMessage to the iframe on every scroll is too much, we're sending this postMessage using debounce.
Using intersection observer seems like a really cool idea, since we're getting all the data we need in the callback (and therefore don't have to query for the iframe's offset, for example), but in order to receive this event as often as we need it, we will have to provide the observer with a pretty long threshold array. In this scenario, won't it be a little inefficient?
There was a problem hiding this comment.
Ok. Understood. We'll look into continuous intersection observer idea. In the meantime, I'm approving an exception to use scroll events here.
|
|
||
| /** @override */ | ||
| isLayoutSupported(layout) { | ||
| return layout === Layout.RESPONSIVE; |
There was a problem hiding this comment.
This is still outstanding. I believe you should use isLayoutSizedDefined here since you update height later anyway.
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
|
CLAs look good, thanks! |
* Implementing amp-playbuzz extension (ampproject#6106) * Improved current implementation of amp-playbuzz * Fixed height issue * Fixed CR issues for amp-playbuzz * Change amp-playbuzz height + homemade overflow button (ampproject#6106) * Fixed origin issue * Fixed Height bug + Origin Check * Updated validation files + unlisteners array * Fixed scrolling events before overflow bug * Fixed placeholder strech height bug * Fixed scroll data + layout support + slow preconnect * Removed debouncing from OnChange to receive all events
* Implementing amp-playbuzz extension (ampproject#6106) * Improved current implementation of amp-playbuzz * Fixed height issue * Fixed CR issues for amp-playbuzz * Change amp-playbuzz height + homemade overflow button (ampproject#6106) * Fixed origin issue * Fixed Height bug + Origin Check * Updated validation files + unlisteners array * Fixed scrolling events before overflow bug * Fixed placeholder strech height bug * Fixed scroll data + layout support + slow preconnect * Removed debouncing from OnChange to receive all events
- (ampproject#17012) `amp-access-iframe` (cleanup issue ampproject#13287) - (ampproject#25480) `amp-mega-menu` - (ampproject#25516) `amp-nested-menu` - (ampproject#6947) `amp-playbuzz` (cleanup issue ampproject#6351) - (ampproject#25170) `amp-sidebar-swipe-to-dismiss` - (ampproject#21058) `fixed-elements-in-lightbox` - (ampproject#25512) `swg-gpay-native` - (ampproject#26021) `swg-gpay-api`
Hi everyone,
This is our initial implementation of extension as discussed in #6106
Any feedback would be appreciated
Thanks a lot,
Dan Mordechay
Playbuzz