Skip to content

Commit

Permalink
make sure a manual yield partial finds the correct parent element
Browse files Browse the repository at this point in the history
  • Loading branch information
evs-chris committed Jul 23, 2019
1 parent 6dbfe3e commit e40a839
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/view/items/Section.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default class Section extends MustacheContainer {
if (this.rendered) this.fragment.unbind().unrender(true);
this.fragment = null;
} else if (this.rendered && !this.yield && value instanceof Context) {
if (this.rendered) this.fragment.unbind().unrender(true);
if (this.rendered && this.fragment) this.fragment.unbind().unrender(true);
this.fragment = null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/view/items/shared/findElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function findElement(start, orComponent = true, name) {
) {
// start is a fragment - look at the owner
if (start.owner) start = start.owner;
else if (start.component)
else if (start.component || start.yield)
// start is a component or yielder - look at the container
start = start.containerFragment || start.component.up;
else if (start.parent)
Expand Down
15 changes: 15 additions & 0 deletions tests/browser/partials.js
Original file line number Diff line number Diff line change
Expand Up @@ -1317,4 +1317,19 @@ export default function() {
r.set('part', 'bar');
t.htmlEqual(fixture.innerHTML, '(bar 1)(bar 2)');
});

test(`manual yield via partial with context context finds correct parent element`, t => {
const r = new Ractive({
target: fixture,
template: `<p>{{#with foo.bar}}<div />{{/with}}</p>{{#if !!.ctx}}<span {{>.bar .ctx}}></span>{{/if}}`,
data: {
foo: { bar: { baz: 'sure' } },
bar: Ractive.parse('data-foo="{{.baz}}"', { attributes: true }).t
}
});

r.set('ctx', r.getContext('div'));

t.htmlEqual(fixture.innerHTML, '<p><div></div></p><span data-foo="sure"></span>');
});
}

0 comments on commit e40a839

Please sign in to comment.