Skip to content
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

Fix Measuring Child AMP Elements #9279

Closed

Conversation

jridgewell
Copy link
Contributor

@jridgewell jridgewell commented May 11, 2017

AMP elements will not be measured until their ancestor AMP elements have been built. This excludes placeholders, which are laid out independent of their ancestor.

Fixes #9267, likely others.

@jridgewell
Copy link
Contributor Author

jridgewell commented May 11, 2017

Preview at http://output.jsbin.com/soniwap/quiet (Hard refresh, should always show images)

@jridgewell jridgewell changed the title Measure child amp element Fix Measuring Child AMP Elements May 11, 2017
css/amp.css Outdated
@@ -271,7 +271,7 @@ i-amphtml-sizer {
color: transparent !important;
}

.i-amphtml-notbuilt > * {
.i-amphtml-notbuilt:not(.i-amphtml-layout-container ) > * {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove trailing space before )

}
// If this ancestor isn't built yet, that means we don't know what kind
// of styles will be applied to this element. We must wait.
if (!ancestor.isBuilt()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only true for non-container ancestors. With containers, we want to measure as soon as we can. We non-containers, we already all good, right? It will measure to 0 and then re-measure to the right value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With containers, we want to measure as soon as we can

Fixed.

We non-containers, we already all good, right? It will measure to 0 and then re-measure to the right value.

Unfortunately not. If the non-container isn't built yet, it will measure to 0 and never re-remeasure (because it thinks it has a proper measure). That's the bug.

@@ -147,6 +147,9 @@ export class Resource {
/** @private {!AmpElement|undefined|null} */
this.owner_ = undefined;

/** @private {!AmpElement|undefined|null} */
this.ampAncestor_ = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be discussed a bit more. But CSS changes seem rather clear to me. Can we merge them first and split this part into another PR? I'd like to get a bit deeper on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

const resource = Resource.forElementOptional(ancestor);
// If there's an AMP ancestor that's still not stubbed (has a Resource),
// we don't know what to do yet.
if (!resource) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe, unfortunately, we do have a very few amp- tags that are not custom elements. Could you pls double-check via validator? Though validator wouldn't give the full picture since some extensions might create them via createElement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I.e.

const paddingBar = this.win.document.createElement(

This code is probably benign, since no one ads stuff into this element from what I can tell. But others might not be so lucky.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhouyx: Is that supposed to be publicly stylable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed, #9283. Will update so those aren't considered.

@jridgewell jridgewell force-pushed the measure-child-amp-element branch from f531e71 to 4e676ef Compare May 11, 2017 22:55
@jridgewell jridgewell force-pushed the measure-child-amp-element branch from 574da7e to 55d9a0e Compare May 11, 2017 23:42
const tag = element.tagName;
// Use prefix to recognize AMP element. This is necessary because stub
// may not be attached yet.
return startsWith(tag, 'AMP-') &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is checking element.classList.contain('i-amphtml-element') not sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the original comment

We can tell whether the parent has been stubbed by whether a resource has been attached to it.

That means we have to be able to tell regardless of where the element is in the CustomElement lifecycle. And an element has to have been stubbed (#connectedCallback, the first step) to have the i-amphtml-element class.

@jridgewell jridgewell force-pushed the measure-child-amp-element branch from 55d9a0e to 219428c Compare May 12, 2017 18:54
@ampprojectbot
Copy link
Member

This issue seems to be in Pending Triage for awhile. Please triage this to an appropriate milestone.

@aghassemi
Copy link
Contributor

Thanks for the pull request. Since this PR has been stale for a while, I am closing it. Please feel free to reopen as needed.

@aghassemi aghassemi closed this May 17, 2018
@miladmhp
Copy link

@aghassemi I Have the same issue with AMP image loading, sometimes images loaded for a long time, or even I just have seen a white box instead of the image. And with just resize the page even for 1 px, all images have been load immediately, It seems to need a shock to load images:).
Please help me in solving this, I'm Confused.

@aghassemi
Copy link
Contributor

@miladmhp Could you please file an issue with a repro Url?

@jridgewell jridgewell deleted the measure-child-amp-element branch October 25, 2018 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants