Amphtml: amp-apester-media: Element mutation outside mutation phase

Created on 16 Feb 2018  Â·  9Comments  Â·  Source: ampproject/amphtml

amp-apester-media inserts its iframe inside #layoutCallback, but because it's inside a Promise's then chain, it's outside of a mutation phase.

layoutCallback() {
  this.element.classList.add('amp-apester-container');
  // This is inside the mutation phase

  return this.queryMedia_().then(response => {
    // We're no longer inside mutation phase, due to promise's
    // async resolution.
    this.element.appendChild(iframe);
  });
}
Soon Bug runtime

All 9 comments

This issue doesn't have a category which makes it harder for us to keep track of it. Please add an appropriate category.

/cc @mrsufgi @OmriKeret

Hi guys,
I will gladly fix it with our next PR (ETA - end of next week).

@aghassemi Is it soon enough?

That's fine.

Hi @aghassemi @jridgewell,
I’ve encountered a dead end, wondered if you could suggest the AMP way of solving it.
In order to construct the unit we need to know what media to display and in order to figure it out we do an api call (“queryMedia_()“).
I could initiate the call earlier but I won’t be sure that it’s finished before the layout callback.
WDYT?

@OmriKeret

Would something like this work? (pseudo-code)

layoutCallback() {


var media;
return queryMedia(response => {
 media = ...;
 return vsync.mutatePromise( () => {
    this.element.appendChild(iframe);
    return this.loadPromise(iframe);
  });
}).then( () => {
  return vsync.mutatePromise( () => {
    state.element.classList.add('i-amphtml-apester-iframe-ready');
    this.togglePlaceholder(false);
    ...
    changeHeight
    ... etc..
 });
});


}

Thanks @aghassemi looks perfect.
fix is included in the following PR: #13741

This issue hasn't been updated in awhile. @aghassemi Do you have any updates?

fixed by #13741

Was this page helpful?
0 / 5 - 0 ratings

Related issues

devanes picture devanes  Â·  3Comments

radiovisual picture radiovisual  Â·  3Comments

choumx picture choumx  Â·  3Comments

gmajoulet picture gmajoulet  Â·  3Comments

choumx picture choumx  Â·  3Comments