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

Adds TemplateRenderer #16122

Merged
merged 12 commits into from Jul 9, 2018
Merged

Adds TemplateRenderer #16122

merged 12 commits into from Jul 9, 2018

Conversation

glevitzky
Copy link
Contributor

@glevitzky glevitzky commented Jun 18, 2018

Addresses #15464.

import {getAmpAdTemplateHelper} from './template-validator';

/**
* Render a non-AMP creative into a NameFrame.
Copy link
Contributor

Choose a reason for hiding this comment

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

wrong js doc?

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.

if (analytics) {
templateHelper.insertAnalytics(renderedElement, analytics);
}
this.iframe.contentWindow.document.body./*OK*/innerHTML =
Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed?

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 believe it is. The returned element (renderedElement) is unattached with no parent element.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok. for sake of performance, instead of doing innerHTML, let's insert renderedElement as the first child of body element.

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.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. 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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@googlebot googlebot added cla: no and removed cla: yes labels Jul 2, 2018
@codecov-io
Copy link

codecov-io commented Jul 2, 2018

Codecov Report

Merging #16122 into master will increase coverage by 0.93%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master   #16122      +/-   ##
==========================================
+ Coverage   77.15%   78.09%   +0.93%     
==========================================
  Files         548      552       +4     
  Lines       40029    40326     +297     
==========================================
+ Hits        30885    31491     +606     
+ Misses       9144     8835     -309
Flag Coverage Δ
#integration_tests 35.2% <ø> (+22.68%) ⬆️
#unit_tests 77.16% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 01167e9...0b7d188. Read the comment docs.

@glevitzky
Copy link
Contributor Author

Resolving CLA issue.

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Jul 2, 2018
templateHelper.insertAnalytics(renderedElement, analytics);
}
// This element must exist, or #render() would have thrown.
const templateElement = this.iframe.contentWindow.document
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: indentation

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.

// This element must exist, or #render() would have thrown.
const templateElement = this.iframe.contentWindow.document
.getElementsByTagName('template')[0];
this.iframe.contentWindow.document.body
Copy link
Contributor

Choose a reason for hiding this comment

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

some more indentation nits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, using a new editor. Surprised the linter didn't catch these.

@lannka lannka merged commit 4c54f65 into ampproject:master Jul 9, 2018
}
// This element must exist, or #render() would have thrown.
const templateElement = this.iframe.contentWindow.document
.getElementsByTagName('template')[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

Use querySelector to to avoid a full doc scan even after finding the initial template element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed these and following comments in #16593.

const templateElement = this.iframe.contentWindow.document
.getElementsByTagName('template')[0];
this.iframe.contentWindow.document.body
.removeChild(templateElement);
Copy link
Contributor

Choose a reason for hiding this comment

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

Use replaceChild to do both this and the next line in one step.

const templateElement = this.iframe.contentWindow.document
.getElementsByTagName('template')[0];
this.iframe.contentWindow.document.body
.removeChild(templateElement);
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, can you guarantee that the <template> is a direct child of <body>? If not, use templateElement.parentNode.removeChild(...)

@glevitzky glevitzky mentioned this pull request Jul 9, 2018
10 tasks
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.

None yet

5 participants