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

Commit 8a96f31

Browse files
committed
fix(jqLite): traverse host property for DocumentFragment in inheritedData()
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. Closes #6637
1 parent d3aa14b commit 8a96f31

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/jqLite.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,15 @@ function jqLiteInheritedData(element, name, value) {
364364
var names = isArray(name) ? name : [name];
365365

366366
while (element.length) {
367-
367+
var node = element[0];
368368
for (var i = 0, ii = names.length; i < ii; i++) {
369369
if ((value = element.data(names[i])) !== undefined) return value;
370370
}
371-
element = element.parent();
371+
372+
// If dealing with a document fragment node with a host element, and no parent, use the host
373+
// element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM
374+
// to lookup parent controllers.
375+
element = jqLite(node.parentNode || (node.nodeType === 11 && node.host));
372376
}
373377
}
374378

test/jqLiteSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ describe('jqLite', function() {
168168

169169
dealoc(ul);
170170
});
171+
172+
it('should pass through DocumentFragment boundaries via host', function() {
173+
var host = jqLite('<div></div>'),
174+
frag = document.createDocumentFragment(),
175+
$frag = jqLite(frag);
176+
frag.host = host[0];
177+
host.data("foo", 123);
178+
host.append($frag);
179+
expect($frag.inheritedData("foo")).toBe(123);
180+
181+
dealoc(host);
182+
dealoc($frag);
183+
});
171184
});
172185

173186

0 commit comments

Comments
 (0)