Skip to content

Commit

Permalink
fix #152 - death scripts after tempalte injection
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Dec 6, 2017
1 parent 61a8669 commit 5d67ef8
Show file tree
Hide file tree
Showing 12 changed files with 908 additions and 771 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# hyper(html) Changelog

### v2.4.1
* fix a bug with scripts that don't trigger network requests in both Firefox and Safari (see bug #152)

### v2.4.0
* created a `Wire` class to handle via `domdiff` multiple wired nodes.
* brought back multi nodes per wire, a feature lost since **v2.0**
Expand Down
17 changes: 16 additions & 1 deletion cjs/objects/Updates.js
Expand Up @@ -9,7 +9,7 @@ const Path = (m => m.__esModule ? m.default : m)(require('./Path.js'));
const Style = (m => m.__esModule ? m.default : m)(require('./Style.js'));
const Intent = (m => m.__esModule ? m.default : m)(require('./Intent.js'));
const domdiff = (m => m.__esModule ? m.default : m)(require('../shared/domdiff.js'));
const { text } = require('../shared/easy-dom.js');
const { create: createElement, text } = require('../shared/easy-dom.js');
const { Event, WeakSet, isArray, trim } = require('../shared/poorlyfills.js');
const { createFragment, slice } = require('../shared/utils.js');

Expand Down Expand Up @@ -162,6 +162,21 @@ const findAttributes = (node, paths, parts) => {
for (let i = 0; i < len; i++) {
node.removeAttributeNode(remove[i]);
}

// This is a very specific Firefox/Safari issue
// but since it should be a not so common pattern,
// it's probably worth patching regardless.
// Basically, scripts created through strings are death.
// You need to create fresh new scripts instead.
// TODO: is there any other node that needs such nonsense ?
const nodeName = node.nodeName;
if (/^script$/i.test(nodeName)) {
const script = createElement(node, nodeName);
for (let i = 0; i < attributes.length; i++) {
script.setAttributeNode(attributes[i].cloneNode(true));
}
node.parentNode.replaceChild(script, node);
}
};

// when a Promise is used as interpolation value
Expand Down
2 changes: 1 addition & 1 deletion coverage/coverage.json

Large diffs are not rendered by default.

293 changes: 169 additions & 124 deletions coverage/lcov-report/hyperHTML/index.c.js.html

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions coverage/lcov-report/hyperHTML/index.html
Expand Up @@ -22,12 +22,12 @@ <h1>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Statements</span>
<span class='fraction'>579/579</span>
<span class='fraction'>585/585</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Branches</span>
<span class='fraction'>317/317</span>
<span class='fraction'>319/319</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
Expand All @@ -37,7 +37,7 @@ <h1>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Lines</span>
<span class='fraction'>568/568</span>
<span class='fraction'>574/574</span>
</div>
<div class='fl pad1y'>
<span class="strong">3 statements, 1 function, 10 branches</span>
Expand Down Expand Up @@ -66,13 +66,13 @@ <h1>
<td class="file high" data-value="index.c.js"><a href="index.c.js.html">index.c.js</a></td>
<td data-value="100" class="pic high"><div class="chart"><div class="cover-fill cover-full" style="width: 100%;"></div><div class="cover-empty" style="width:0%;"></div></div></td>
<td data-value="100" class="pct high">100%</td>
<td data-value="579" class="abs high">579/579</td>
<td data-value="585" class="abs high">585/585</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="317" class="abs high">317/317</td>
<td data-value="319" class="abs high">319/319</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="94" class="abs high">94/94</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="568" class="abs high">568/568</td>
<td data-value="574" class="abs high">574/574</td>
</tr>

</tbody>
Expand All @@ -81,7 +81,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 05 2017 07:14:58 GMT-0200 (-02)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Wed Dec 06 2017 15:55:34 GMT-0200 (-02)
</div>
</div>
<script src="../prettify.js"></script>
Expand Down
14 changes: 7 additions & 7 deletions coverage/lcov-report/index.html
Expand Up @@ -22,12 +22,12 @@ <h1>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Statements</span>
<span class='fraction'>579/579</span>
<span class='fraction'>585/585</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Branches</span>
<span class='fraction'>317/317</span>
<span class='fraction'>319/319</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
Expand All @@ -37,7 +37,7 @@ <h1>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Lines</span>
<span class='fraction'>568/568</span>
<span class='fraction'>574/574</span>
</div>
<div class='fl pad1y'>
<span class="strong">3 statements, 1 function, 10 branches</span>
Expand Down Expand Up @@ -66,13 +66,13 @@ <h1>
<td class="file high" data-value="hyperHTML/"><a href="hyperHTML/index.html">hyperHTML/</a></td>
<td data-value="100" class="pic high"><div class="chart"><div class="cover-fill cover-full" style="width: 100%;"></div><div class="cover-empty" style="width:0%;"></div></div></td>
<td data-value="100" class="pct high">100%</td>
<td data-value="579" class="abs high">579/579</td>
<td data-value="585" class="abs high">585/585</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="317" class="abs high">317/317</td>
<td data-value="319" class="abs high">319/319</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="94" class="abs high">94/94</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="568" class="abs high">568/568</td>
<td data-value="574" class="abs high">574/574</td>
</tr>

</tbody>
Expand All @@ -81,7 +81,7 @@ <h1>
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 05 2017 07:14:58 GMT-0200 (-02)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Wed Dec 06 2017 15:55:34 GMT-0200 (-02)
</div>
</div>
<script src="prettify.js"></script>
Expand Down

0 comments on commit 5d67ef8

Please sign in to comment.