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
Adds TemplateRenderer #16122
Conversation
import {getAmpAdTemplateHelper} from './template-validator'; | ||
|
||
/** | ||
* Render a non-AMP creative into a NameFrame. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong js doc?
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
372fff5
to
49b6243
Compare
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. |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Resolving CLA issue. |
55449dd
to
4ddd874
Compare
CLAs look good, thanks! |
templateHelper.insertAnalytics(renderedElement, analytics); | ||
} | ||
// This element must exist, or #render() would have thrown. | ||
const templateElement = this.iframe.contentWindow.document |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: indentation
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some more indentation nits
There was a problem hiding this comment.
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.
} | ||
// This element must exist, or #render() would have thrown. | ||
const templateElement = this.iframe.contentWindow.document | ||
.getElementsByTagName('template')[0]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(...)
Addresses #15464.