Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix patch() so that the root is patched instead of recreated #159

Merged
merged 1 commit into from
Sep 9, 2016

Conversation

staltz
Copy link
Member

@staltz staltz commented Sep 4, 2016

Previously, patch(element, vnode) would create a new element every time
for the top-level element, unless the top-level vnode had no id and
className. This is because emptyNodeAt() would create a vnode with sel
equal to the element's tagName, NOT including id and className.

This seems to be just a small fix, however this fix was crucial to get
Web Components (custom elements) working with Cycle.js, because the
custom element's "create" callback was being called infinitely and
recursively, because snabbdom was creating the top-level element every
time, even if the sel of oldVNode and vnode were supposed to be the
same.

Previously, patch(element, vnode) would create a new element every time
for the top-level element, unless the top-level vnode had no id and
className. This is because emptyNodeAt() would create a vnode with sel
equal to the element's tagName, NOT including id and className.

This seems to be just a small fix, however this fix was crucial to get
Web Components (custom elements) working with Cycle.js, because the
custom element's "create" callback was being called infinitely and
recursively, because snabbdom was creating the top-level element every
time, even if the sel of oldVNode and vnode were supposed to be the
same.
@@ -670,7 +681,7 @@ describe('snabbdom', function() {
{remove: function(_, rm) { rm2 = rm; }},
]);
var vnode1 = h('div', [h('a', {hook: {remove: function(_, rm) { rm3 = rm; }}})]);
var vnode2 = h('div', []);
var vnode2 = h('div', []);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my editor that automatically converted the (previously) tab to spaces. But it's anyway good to avoid mixed tabs and spaces.

@TylorS
Copy link
Member

TylorS commented Sep 4, 2016

LGTM 👍

@tusharmath
Copy link

This would potentially fix #158

@paldepind
Copy link
Member

Thank you for the PR. To me this seems clearly better. I'd say the old behavior was pretty much a bug.

@paldepind paldepind merged commit 4475a6f into snabbdom:master Sep 9, 2016
@paldepind
Copy link
Member

paldepind commented Sep 9, 2016

I've just released 0.5.3 with this patch. Thanks again 😄 I'm sorry for the trouble caused. It never occurred to me how the old behavior could cause issues.

@staltz
Copy link
Member Author

staltz commented Sep 9, 2016

Thanks for merging 👍 the synergy between our communities is good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants