diff --git a/src/jqLite.js b/src/jqLite.js index ba613f218f9e..738f47a9b167 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -364,11 +364,15 @@ function jqLiteInheritedData(element, name, value) { var names = isArray(name) ? name : [name]; while (element.length) { - + var node = element[0]; for (var i = 0, ii = names.length; i < ii; i++) { if ((value = element.data(names[i])) !== undefined) return value; } - element = element.parent(); + + // If dealing with a document fragment node with a host element, and no parent, use the host + // element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM + // to lookup parent controllers. + element = jqLite(node.parentNode || (node.nodeType === 11 && node.host)); } } diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 482c05f4f730..faf1c98cbb8c 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -168,6 +168,19 @@ describe('jqLite', function() { dealoc(ul); }); + + it('should pass through DocumentFragment boundaries via host', function() { + var host = jqLite('
'), + frag = document.createDocumentFragment(), + $frag = jqLite(frag); + frag.host = host[0]; + host.data("foo", 123); + host.append($frag); + expect($frag.inheritedData("foo")).toBe(123); + + dealoc(host); + dealoc($frag); + }); });