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

Schedule nested amp placeholder for managed scheduling #2954

Merged
merged 5 commits into from May 5, 2016

Conversation

mkhatib
Copy link
Contributor

@mkhatib mkhatib commented Apr 20, 2016

Fixes #2828

As @dvoytenko mentioned in the issue #2828 resources should only auto schedule the nested placeholders and not nested elements - these are still left to the owner element to schedule.

You can demo this on this deployment and see nested placeholder of amp-anim inside amp-carousel being scheduled correctly.

@@ -1327,6 +1327,13 @@ export class Resources {
// Breadth-first search.
if (element.classList.contains('-amp-element')) {
callback(this.getResourceForElement(element));
// Also schedule amp-element that is a placeholder for the element.
const placeholder = element.getPlaceholder();
const hasAmpPlaceholder = (!element.classList.contains('-amp-layout') &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move the -amp-layout check earlier, to avoid doing a DOM lookup for a placeholder that we may not need.

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.

@jridgewell
Copy link
Contributor

Code LGTM, but I don't know this code well enough to give final approval. @dvoytenko?

@mkhatib mkhatib assigned dvoytenko and unassigned jridgewell Apr 21, 2016
@mkhatib
Copy link
Contributor Author

mkhatib commented Apr 21, 2016

Thanks @jridgewell assigned for @dvoytenko to give the final LGTM

// Also schedule amp-element that is a placeholder for the element.
if (!element.classList.contains('-amp-layout')) {
const placeholder = element.getPlaceholder();
if (placeholder && placeholder.classList.contains('-amp-element')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Almost. But I believe it should be:

if (placeholder) {
  this.discoverResourcesForElement_(placeholder, callback);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense no need to double check the recursive call will do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, could you please rephrase this sentence?

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 misunderstood your comment initially but got it after you explained the required test part. Done.

@dvoytenko
Copy link
Contributor

Very close. Just one correction. PTAL and add a test for that nuance.

@mkhatib
Copy link
Contributor Author

mkhatib commented May 3, 2016

Added the test PTAL

@@ -1327,6 +1327,13 @@ export class Resources {
// Breadth-first search.
if (element.classList.contains('-amp-element')) {
callback(this.getResourceForElement(element));
// Also schedule amp-element that is a placeholder for the element.
if (!element.classList.contains('-amp-layout')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why if (!element.classList.contains('-amp-layout'))? Generally, elements themselves decide when placeholder is visible or not. It's typical that placeholder is hidden after layout, but not guaranteed. Otherwise we'd simply support it via global CSS. I think there's no risk of re-discovering placeholder here in all cases. If it's currently hidden - it won't be processed.

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 think it was just to avoid discovering it multiple times as you mentioned, but explanation sounds good to me! Dropped it.

@dvoytenko
Copy link
Contributor

@mkhatib One more comment. PTAL.

@mkhatib
Copy link
Contributor Author

mkhatib commented May 4, 2016

Thanks @dvoytenko! Done

@dvoytenko
Copy link
Contributor

LGTM!

@mkhatib mkhatib merged commit 39daf66 into ampproject:master May 5, 2016
@mkhatib mkhatib deleted the nested-scheduling branch May 5, 2016 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants