AMP shadow does not render viewport dependent content in horizontal scroller
What's the issue?
If amp shadow is used to build a horizontal article slider with a regular scrollable container it will not load and render amp components that have to be inside the viewport to be rendered, like amp-img and amp-video, if the container is during the initial setup two viewports off canvas from the initial scroll position.
For example: In a slider with four slides the first two will show viewport dependent content while the last two won't.
However: starting on the last slides scroll position during setup will result in the last two slides working while the first two are now broken.
Resizing the window will result in amp-img and amp-video loading their content.
How do we reproduce the issue?
- Open: https://p2er.github.io/amp-articleslider/ampshadow-slider.html#slide-1
- Scroll sidewards (right) to see images and videos rendered on first and second slide, while missing in third and fourth
- Open https://p2er.github.io/amp-articleslider/ampshadow-slider.html#slide-4
- Scroll sidewards (left) to see images and videos rendered on fourth and third slide, while missing in second and first
What browsers are affected?
Tested on Chrome, Safari and Firefox.
Which AMP version is affected?
Powered by AMP ⚡ HTML shadows – Version 1500510703681
Suggestions?
If resizing solves the problem, it seems as if the location recalculation cycle is properly handled on scrolling in parent container. As a quick fix it would be OK if one could call the same update a resize does manually on the amp shadow doc. For example on slide index change.
@p2er Do you use visibility state as in https://github.com/ampproject/amphtml/blob/master/spec/amp-shadow-doc.md#visibility-state-visibilitystate ? I believe that should do the trick. The newly entering doc will start in prerender mode and once transition is done, it will go into visible mode.
LMK
I don't use visibility state in the demo to keep it simple, but actually tried that approach in my version. Would you like me to implement the visibility state change trigger on slide selection. Unfortunately it did not solve the problem for me, because the next article would still be rendered outside of the visible area to be present while swiping the content into viewport.
5
We have the same problem here. Is there a workaround?
You must set the visibility state when the shadow document enters the viewport. If the document is not in the viewport when setVisibilityState is called, then the resource manager will not schedule layout for the document's components.
I don't believe this will happen passively e.g. if the shadow docs are side by side in a scroll container. The shell document will need to track when the document is truly visible, then call setVisibilityState. Can you try to make this change and let us know if that resolves your issue?
@cvializ we tried to call the setVisibilityState but unfortunately it is not working. You could have a look on our demo page: http://mhnd.shz.de/mario/artikelscroller/swiper_test/ Also the video in the not visible part of the first page is not activated when comming to the viewport.
@mario-lorenzen you are aware that the swiper lib you are using is relying on css transforms to move the content into view. AMP viewport calculations are determined by the actual location of the DOM element, wich would still be at the initial location after your transition, as far as I know.
The trick for me was to use a regular scrolling container, move the content into view and animate the scrolling to achieve your desired effect instead CSS transitions.
You could use https://developer.mozilla.org/de/docs/Web/API/Element/scrollIntoView and https://github.com/iamdustan/smoothscroll as polyfill if you want to rely on default behaviour.
I personally did prefer greensock and it's scroll to plugin: https://greensock.com/ScrollToPlugin Allows animation complete callbacks. Thats where I changed the visibility state.
@p2er: We are aware that we are using css transitions in order to scroll the content. Unfortunately it is necessary for the final product since we want to scoll each article separetely. As you said the problem seems to be the AMP viewport that doesn`t recognize that it is been scrolled by css transition. Is there a chance to set up the position of the viewport manually?
This issue hasn't been updated in awhile. @cvializ Do you have any updates?
/to @danielrozenberg
This issue hasn't been updated in awhile. @danielrozenberg Do you have any updates?
Duplicate of #11983