From 0a943b8e1b936b62a0dca35cc32ccaf367d27dca Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Tue, 26 Jun 2018 13:36:50 +0300 Subject: [PATCH] fix($compile): work around Firefox `DocumentFragment` bug DOM nodes passed to `compilationGenerator()` will eventually be wrapped in `jqLite`, when the compilation actually happens. In Firefox 60+, there seems to be a `DocumentFragment`-related bug that sometimes causes the `childNodes` to be empty at the time the compilation happens. This commit works around this bug by eagerly wrapping `childNodes` in `jqLite`. NOTE: The wrapped nodes have references to their `DocumentFragment` container. This is "by design", since we want to be able to traverse the nodes via `nextSibling` (in order to correctly handle multi-element directives). Once the nodes are compiled, they will be either moved to a new container element or the `jqLite` wrapper is release making them eligible for garbage collection. In both cases, the original `DocumentFragment` container should be eligible for garbage collection too. Fixes #16607 --- src/ng/compile.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index a257c0b5f096..9e22776dbe65 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -2620,11 +2620,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { for (var slotName in slots) { if (slots[slotName]) { // Only define a transclusion function if the slot was filled - slots[slotName] = compilationGenerator(mightHaveMultipleTransclusionError, slots[slotName].childNodes, transcludeFn); + var slotCompileNodes = jqLite(slots[slotName].childNodes); + slots[slotName] = compilationGenerator(mightHaveMultipleTransclusionError, slotCompileNodes, transcludeFn); } } - $template = $template.childNodes; + $template = jqLite($template.childNodes); } $compileNode.empty(); // clear contents