Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f3b1d0b

Browse files
committed
fix($compile): workaround for IE11 MutationObserver
IE11 MutationObserver breaks consecutive text nodes into several text nodes. This patch merges consecutive text nodes into a single node before looking for interpolations. Closes #11781
1 parent 288225b commit f3b1d0b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/ng/compile.js

+7
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15451545
}
15461546
break;
15471547
case NODE_TYPE_TEXT: /* Text Node */
1548+
if (msie === 11) {
1549+
// Workaround for #11781
1550+
while (node.parentNode && node.nextSibling && node.nextSibling.nodeType === NODE_TYPE_TEXT) {
1551+
node.nodeValue = node.nodeValue + node.nextSibling.nodeValue;
1552+
node.parentNode.removeChild(node.nextSibling);
1553+
}
1554+
}
15481555
addTextInterpolateDirective(directives, node.nodeValue);
15491556
break;
15501557
case NODE_TYPE_COMMENT: /* Comment */

test/ng/compileSpec.js

+19
Original file line numberDiff line numberDiff line change
@@ -2992,6 +2992,25 @@ describe('$compile', function() {
29922992
}));
29932993

29942994

2995+
it('should handle consecutive text elements as a single text element', inject(function($rootScope, $compile) {
2996+
// No point it running the test, if there is no MutationObserver
2997+
if (!window.MutationObserver) return;
2998+
2999+
// Create and register the MutationObserver
3000+
var observer = new window.MutationObserver(noop);
3001+
observer.observe(document.body, {childList: true, sublist: true});
3002+
3003+
// Run the actual test
3004+
var base = jqLite('<div>&mdash; {{ "This doesn\'t." }}</div>');
3005+
element = $compile(base)($rootScope);
3006+
$rootScope.$digest();
3007+
expect(element.text()).toBe("— This doesn't.");
3008+
3009+
// Unregister the MutationObserver (and hope it doesn't mess up with subsequent tests)
3010+
observer.disconnect();
3011+
}));
3012+
3013+
29953014
it('should support custom start/end interpolation symbols in template and directive template',
29963015
function() {
29973016
module(function($interpolateProvider, $compileProvider) {

0 commit comments

Comments
 (0)