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

Commit fccce96

Browse files
smdvdsnNarretz
authored andcommitted
fix($compile): workaround for IE11 MutationObserver
Backport #11796 to 1.2 branch. IE11 MutationObserver breaks consecutive text nodes into several text nodes. This patch merges consecutive text nodes into a single node before looking for interpolations. Also had to modify npm-shrinkwrap.json because i@0.3.2 was unpublished from npm. Closes #11781 Closes #12613
1 parent b041b66 commit fccce96

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

npm-shrinkwrap.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ng/compile.js

+7
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10881088
}
10891089
break;
10901090
case 3: /* Text Node */
1091+
if (msie === 11) {
1092+
// Workaround for #11781
1093+
while (node.parentNode && node.nextSibling && node.nextSibling.nodeType === 3 /* Text Node */) {
1094+
node.nodeValue = node.nodeValue + node.nextSibling.nodeValue;
1095+
node.parentNode.removeChild(node.nextSibling);
1096+
}
1097+
}
10911098
addTextInterpolateDirective(directives, node.nodeValue);
10921099
break;
10931100
case 8: /* Comment */

test/ng/compileSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -2214,6 +2214,23 @@ describe('$compile', function() {
22142214
'</select>');
22152215
}));
22162216

2217+
it('should handle consecutive text elements as a single text element', inject(function($rootScope, $compile) {
2218+
// No point it running the test, if there is no MutationObserver
2219+
if (!window.MutationObserver) return;
2220+
2221+
// Create and register the MutationObserver
2222+
var observer = new window.MutationObserver(noop);
2223+
observer.observe(document.body, {childList: true, subtree: true});
2224+
2225+
// Run the actual test
2226+
var base = jqLite('<div>&mdash; {{ "This doesn\'t." }}</div>');
2227+
element = $compile(base)($rootScope);
2228+
$rootScope.$digest();
2229+
expect(element.text()).toBe("— This doesn't.");
2230+
2231+
// Unregister the MutationObserver (and hope it doesn't mess up with subsequent tests)
2232+
observer.disconnect();
2233+
}));
22172234

22182235
it('should support custom start/end interpolation symbols in template and directive template',
22192236
function() {

0 commit comments

Comments
 (0)