Skip to content

Commit 063a333

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 angular#11781
1 parent 1268b17 commit 063a333

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/ng/compile.js

+7
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15401540
}
15411541
break;
15421542
case NODE_TYPE_TEXT: /* Text Node */
1543+
if (msie === 11) {
1544+
// Workaround for #11781
1545+
while (node.parentNode && node.nextSibling && node.nextSibling.nodeType === NODE_TYPE_TEXT) {
1546+
node.nodeValue = node.nodeValue + node.nextSibling.nodeValue;
1547+
node.parentNode.removeChild(node.nextSibling);
1548+
}
1549+
}
15431550
addTextInterpolateDirective(directives, node.nodeValue);
15441551
break;
15451552
case NODE_TYPE_COMMENT: /* Comment */

test/ng/compileSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -2762,6 +2762,23 @@ describe('$compile', function() {
27622762
}));
27632763

27642764

2765+
it('should handle consecutive text elements as a single text element', inject(function($rootScope, $compile) {
2766+
window.addMutationObserver = function() {
2767+
if (!window.MutationObserver) {
2768+
return;
2769+
}
2770+
new window.MutationObserver(function() {}).observe(document.body, {
2771+
childList: true,
2772+
subtree: true
2773+
});
2774+
};
2775+
var base = jqLite('<div>&mdash; {{ "This doesn\'t." }}</div>');
2776+
element = $compile(base)($rootScope);
2777+
$rootScope.$digest();
2778+
expect(element.text()).toBe("— This doesn't.");
2779+
}));
2780+
2781+
27652782
it('should support custom start/end interpolation symbols in template and directive template',
27662783
function() {
27672784
module(function($interpolateProvider, $compileProvider) {

0 commit comments

Comments
 (0)