-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 attributes diff on DOM node #677
Conversation
src/vdom/diff.js
Outdated
@@ -124,6 +124,8 @@ function idiff(dom, vnode, context, mountAll, componentRoot) { | |||
props = out[ATTR_KEY] || (out[ATTR_KEY] = {}), | |||
vchildren = vnode.children; | |||
|
|||
for (let a=out.attributes, i=a.length; i--; ) props[a[i].name] = a[i].value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll need to wrap this in a check for props. If the propcache already exists on an element, skipping attribute checks is a fairly major performance gain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine doing this post-merge if you want.
Added the Periodic Weather PWA with the lastest of Preact to the list! ☀️
@developit code updated to loop over attributes only when not cached : https://github.com/developit/preact/pull/677/files#diff-a0896fa5d65b1d80ca4d496badbae50fR127 |
props = out[ATTR_KEY]; | ||
} | ||
else { | ||
props = out[ATTR_KEY] = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll probably consolidate this post-merge, but it's good!
Hi @developit, is there a planned release with this fix ? |
Yup, 8.2 out soon. |
@developit would love that release! |
Me too, heh. |
Expected behaviour
Diff should remove attributes when they are no longer present in the next html state (see unit test)
Actual behaviour
It behaves as expected when the merged node is created using
h
.It preserves removed attributes when the merged node comes from the DOM.
Possible solutions