Skip to content

Commit

Permalink
don't try to create links for undefined data during attach - fixes #3278
Browse files Browse the repository at this point in the history
  • Loading branch information
evs-chris committed Oct 16, 2018
1 parent 92f7942 commit efe6c29
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/model/RootModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,14 @@ function attachImplicits(model, fragment) {

// look for virtual children to relink and cascade
for (const k in model.childByKey) {
if (model.value != null && k in model.value) {
attachImplicits(model.childByKey[k], fragment);
} else if (!model.childByKey[k]._link || model.childByKey[k]._link.isDetached()) {
const mdl = resolveReference(fragment, k);
if (mdl) {
model.childByKey[k].link(mdl, k, { implicit: true });
if (model.value) {
if (k in model.value) {
attachImplicits(model.childByKey[k], fragment);
} else if (!model.childByKey[k]._link || model.childByKey[k]._link.isDetached()) {
const mdl = resolveReference(fragment, k);
if (mdl) {
model.childByKey[k].link(mdl, k, { implicit: true });
}
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions tests/browser/methods/attachChild.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,33 @@ export default function() {

t.equal(fixture.innerHTML, '');
});

test(`attaching a non-isolated child with undefined data should not result in incorrect links (#3278)`, t => {
const done = t.async();

const r = new Ractive({
template: '<#anchor />',
target: fixture
});

const cmp = new Ractive({
template: '{{baz}}',
data: { foo: undefined },
computed: {
baz() {
return this.get('foo.bar');
}
},
isolated: false,
onrender() {
setTimeout(() => {
this.set({ foo: { bar: 'asdf' } });
t.equal(fixture.innerHTML, 'asdf');
done();
}, 14);
}
});

r.attachChild(cmp, { target: 'anchor' });
});
}

0 comments on commit efe6c29

Please sign in to comment.