From 6e5fb04d3f3f9a6cd43ac20896d73321dd079f96 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 8 Nov 2016 15:07:07 +0100 Subject: Squashed 'thirdparty/preact/' changes from b2d90cc..ba094e2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ba094e2 Run only local tests for pull requests (#390) e9fc3c2 Fix CI build (#386) 70a5ca3 This adds a link to preact-i18nline. (#382) 5dffd85 Merge branch 'pr-fix-build-for-windows' of https://github.com/Download/preact f14edf7 kilobits => kilobytes (#383) c193547 Test for #292 284e4aa 6.4.0 24eab2f Prevent accidental duplicate recycling of elements when swapping the base element of a component. Fixes #373. 76c5ef7 fix lint error 8008886 When swapping the base of a composed child component, update its parent's base reference. Fixes #349. fd4f21f Add an equality check prior to setting `.nodeValue` on text nodes, since Firefox (and maybe others) don't do this internally by default. Fixes #368 - thanks @zbinlin! 1555e2b Add CDNJS version badge in readme (#365) 79c8bae Disable React Developer Tools integration tests under IE (#362) 84f4eeb Refactor `linkState()` a bit to drop around 40 bytes. Coincidentally, that's the exact size of the hooks just added for DevTools... 👌 22bbfcb Little tweaks 👯 f8b326e Document how to use the React DevTools with Preact (#354) 1f4a8eb Correct "preact/devtools" type definitions (#355) 68f22eb Add React Developer Tools integration (#339) 2a7a027 Add ref and allow objects in className (#316) 4a59cca fix readme todomvc link (#345) 37ca4e0 Fixes build for Windows #343 cf93387 6.3.0 ff05818 Make `VNode.children` *always* be an Array, even when there are no children. 9b095f4 Added link to preact-layout (#342) git-subtree-dir: thirdparty/preact git-subtree-split: ba094e27b602cb16aded7dcad95f71e44b7b0476 --- src/vdom/diff.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'src/vdom/diff.js') diff --git a/src/vdom/diff.js b/src/vdom/diff.js index 691434e98..794a79aaa 100644 --- a/src/vdom/diff.js +++ b/src/vdom/diff.js @@ -6,6 +6,7 @@ import { buildComponentFromVNode } from './component'; import { setAccessor } from '../dom/index'; import { createNode, collectNode } from '../dom/recycler'; import { unmountComponent } from './component'; +import options from '../options'; /** Diff recursion count, used to track the end of the diff cycle. */ @@ -20,6 +21,7 @@ let isSvgMode = false; export function flushMounts() { let c; while ((c=mounts.pop())) { + if (options.afterMount) options.afterMount(c); if (c.componentDidMount) c.componentDidMount(); } } @@ -52,7 +54,9 @@ function idiff(dom, vnode, context, mountAll) { if (isString(vnode)) { if (dom) { if (dom instanceof Text && dom.parentNode) { - dom.nodeValue = vnode; + if (dom.nodeValue!=vnode) { + dom.nodeValue = vnode; + } return dom; } recollectNodeTree(dom); @@ -66,7 +70,8 @@ function idiff(dom, vnode, context, mountAll) { let out = dom, nodeName = vnode.nodeName, - prevSvgMode = isSvgMode; + prevSvgMode = isSvgMode, + vchildren = vnode.children; if (!isString(nodeName)) { nodeName = String(nodeName); @@ -86,11 +91,13 @@ function idiff(dom, vnode, context, mountAll) { } // fast-path for elements containing a single TextNode: - if (vnode.children && vnode.children.length===1 && typeof vnode.children[0]==='string' && out.childNodes.length===1 && out.firstChild instanceof Text) { - out.firstChild.nodeValue = vnode.children[0]; + if (vchildren && vchildren.length===1 && typeof vchildren[0]==='string' && out.childNodes.length===1 && out.firstChild instanceof Text) { + if (out.firstChild.nodeValue!=vchildren[0]) { + out.firstChild.nodeValue = vchildren[0]; + } } - else if (vnode.children || out.firstChild) { - innerDiffNode(out, vnode.children, context, mountAll); + else if (vchildren && vchildren.length || out.firstChild) { + innerDiffNode(out, vchildren, context, mountAll); } let props = out[ATTR_KEY]; @@ -232,15 +239,15 @@ export function recollectNodeTree(node, unmountOnly) { function diffAttributes(dom, attrs, old) { for (let name in old) { if (!(attrs && name in attrs) && old[name]!=null) { - setAccessor(dom, name, null, old[name], isSvgMode); + setAccessor(dom, name, old[name], old[name] = undefined, isSvgMode); } } // new & updated if (attrs) { for (let name in attrs) { - if (!(name in old) || attrs[name]!==(name==='value' || name==='checked' ? dom[name] : old[name])) { - setAccessor(dom, name, attrs[name], old[name], isSvgMode); + if (name!=='children' && name!=='innerHTML' && (!(name in old) || attrs[name]!==(name==='value' || name==='checked' ? dom[name] : old[name]))) { + setAccessor(dom, name, old[name], old[name] = attrs[name], isSvgMode); } } } -- cgit v1.2.3