Prevent invalid binding in re-written templates #814

Merged
merged 1 commit into from Mar 19, 2013

Projects

None yet

2 participants

@mbest
Member
mbest commented Jan 25, 2013

With string templates, if the HTML is invalid in some way, the browser will attempt to fix it, often by removing invalid elements. If that invalid element has a binding, Knockout still tries to do that binding on whichever element is after it.

We fixed a particular consequence of this in #660, but should probably fix the problem more generally. Likely this will mean that we track the tagName of the binding's element and ensure that the binding is applied to an element with the same name.

@mbest mbest Prevent binding to missing nodes in case of malformed template (#814)
Reverts change from 8bb9b39 that worked around a specific instance of this problem.
1dfd516
@mbest mbest referenced this pull request Mar 16, 2013
Closed

March 2013 iteration #877

@SteveSanderson
Contributor

The reason for removing text node support - is it just that KO now only ever passes elements (not text nodes) to setTextContent?

That is, the only case where previously we might pass a text node was when a template markup was malformed and a text binding was being applied incorrectly to a text node instead of the intended element?

Contributor

Actually, ignore this question. After re-reading the notes for #660, it's pretty clear why you did this (i.e., it's exactly as I described above). And the existing spec Should not throw errors if trying to apply text to a non-rendered node covers the new behavior.

@SteveSanderson SteveSanderson merged commit a703974 into master Mar 19, 2013
@SteveSanderson
Contributor

Looks good - thanks!

@mbest mbest deleted the 814-prevent-invalid-binding branch Mar 19, 2013
@mikekidder mikekidder added a commit to mikekidder/knockout that referenced this pull request Apr 17, 2013
@mbest @mikekidder mbest + mikekidder Prevent binding to missing nodes in case of malformed template (#814)
Reverts change from 8bb9b39 that worked around a specific instance of this problem.
3e0e2bf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment