Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Commit

Permalink
Make sure <template> polyfill runs before custom elements
Browse files Browse the repository at this point in the history
Fixes Polymer/polymer-cli#856
  • Loading branch information
dfreedm committed Oct 18, 2017
1 parent 7905fc5 commit 936a28b
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 176 deletions.
6 changes: 6 additions & 0 deletions src/post-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

let customElements = window['customElements'];
let HTMLImports = window['HTMLImports'];
let Template = window['HTMLTemplateElement'];

// global for (1) existence means `WebComponentsReady` will file,
// (2) WebComponents.ready == true means event has fired.
window.WebComponents = window.WebComponents || {};
Expand All @@ -22,6 +24,10 @@ if (customElements && customElements['polyfillWrapFlushCallback']) {
let flushCallback;
let runAndClearCallback = function runAndClearCallback() {
if (flushCallback) {
// make sure to run the HTMLTemplateElement polyfill before custom elements upgrade
if (Template['bootstrap']) {
Template['bootstrap'](window.document);
}
let cb = flushCallback;
flushCallback = null;
cb();
Expand Down
11 changes: 3 additions & 8 deletions tests/template-and-CE.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
<html>
<head>
<title>Template with HTMLImports Test</title>
<script src="../node_modules/@webcomponents/template/template.js"></script>
<script src="../node_modules/@webcomponents/custom-elements/custom-elements.min.js"></script>
<script src="../webcomponents-loader.js"></script>
<script src="../../web-component-tester/browser.js"></script>
</head>
<body>
Expand Down Expand Up @@ -51,12 +50,8 @@
}
}

// The template polyfill is asynchronous, so on IE11 we shouldn't
// try to upgrade before it's done its thing.
document.addEventListener('DOMContentLoaded', function() {
window.customElements.define('x-child', XChild);
window.customElements.define('x-after', XAfter);
});
window.customElements.define('x-child', XChild);
window.customElements.define('x-after', XAfter);

suite('template and custom elements', function() {
test('elements within templates not upgraded', function() {
Expand Down
10 changes: 1 addition & 9 deletions tests/template-and-imports.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@
<html>
<head>
<title>Template with HTMLImports Test</title>
<script src="../../template/template.js"></script>
<script src="../../html-imports/src/html-imports.js"></script>
<script>
// WCT = {
// waitFor: function(callback) {
// this.HTMLImports.whenReady(callback);
// }
// };
</script>
<script src="../webcomponents-loader.js"></script>
<script src="../../web-component-tester/browser.js"></script>
</head>
<body>
Expand Down
30 changes: 15 additions & 15 deletions webcomponents-hi-ce.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion webcomponents-hi-ce.js.map

Large diffs are not rendered by default.

118 changes: 59 additions & 59 deletions webcomponents-hi-sd-ce.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion webcomponents-hi-sd-ce.js.map

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions webcomponents-hi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 936a28b

Please sign in to comment.