aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/preact/src/vdom
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/preact/src/vdom')
-rw-r--r--thirdparty/preact/src/vdom/component.js27
-rw-r--r--thirdparty/preact/src/vdom/diff.js25
-rw-r--r--thirdparty/preact/src/vdom/index.js7
3 files changed, 38 insertions, 21 deletions
diff --git a/thirdparty/preact/src/vdom/component.js b/thirdparty/preact/src/vdom/component.js
index bb2e4fa5d..64e7ff81f 100644
--- a/thirdparty/preact/src/vdom/component.js
+++ b/thirdparty/preact/src/vdom/component.js
@@ -154,11 +154,11 @@ export function renderComponent(component, opts, mountAll, isChild) {
let baseParent = initialBase.parentNode;
if (baseParent && base!==baseParent) {
baseParent.replaceChild(base, initialBase);
- }
- if (!cbase && !toUnmount && component._parentComponent) {
- initialBase._component = null;
- recollectNodeTree(initialBase);
+ if (!toUnmount) {
+ initialBase._component = null;
+ recollectNodeTree(initialBase);
+ }
}
}
@@ -170,7 +170,9 @@ export function renderComponent(component, opts, mountAll, isChild) {
if (base && !isChild) {
let componentRef = component,
t = component;
- while ((t=t._parentComponent)) { componentRef = t; }
+ while ((t=t._parentComponent)) {
+ (componentRef = t).base = base;
+ }
base._component = componentRef;
base._componentConstructor = componentRef.constructor;
}
@@ -179,8 +181,11 @@ export function renderComponent(component, opts, mountAll, isChild) {
if (!isUpdate || mountAll) {
mounts.unshift(component);
}
- else if (!skip && component.componentDidUpdate) {
- component.componentDidUpdate(previousProps, previousState, previousContext);
+ else if (!skip) {
+ if (component.componentDidUpdate) {
+ component.componentDidUpdate(previousProps, previousState, previousContext);
+ }
+ if (options.afterUpdate) options.afterUpdate(component);
}
let cb = component._renderCallbacks, fn;
@@ -218,7 +223,11 @@ export function buildComponentFromVNode(dom, vnode, context, mountAll) {
}
c = createComponent(vnode.nodeName, props, context);
- if (dom && !c.nextBase) c.nextBase = dom;
+ if (dom && !c.nextBase) {
+ c.nextBase = dom;
+ // passing dom/oldDom as nextBase will recycle it if unused, so bypass recycling on L241:
+ oldDom = null;
+ }
setComponentProps(c, props, SYNC_RENDER, context, mountAll);
dom = c.base;
@@ -239,6 +248,8 @@ export function buildComponentFromVNode(dom, vnode, context, mountAll) {
* @private
*/
export function unmountComponent(component, remove) {
+ if (options.beforeUnmount) options.beforeUnmount(component);
+
// console.log(`${remove?'Removing':'Unmounting'} component: ${component.constructor.name}`);
let base = component.base;
diff --git a/thirdparty/preact/src/vdom/diff.js b/thirdparty/preact/src/vdom/diff.js
index 691434e98..794a79aaa 100644
--- a/thirdparty/preact/src/vdom/diff.js
+++ b/thirdparty/preact/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);
}
}
}
diff --git a/thirdparty/preact/src/vdom/index.js b/thirdparty/preact/src/vdom/index.js
index 50d4ca2b9..f59fbae21 100644
--- a/thirdparty/preact/src/vdom/index.js
+++ b/thirdparty/preact/src/vdom/index.js
@@ -33,9 +33,10 @@ export function isNamedNode(node, nodeName) {
* @returns {Object} props
*/
export function getNodeProps(vnode) {
- let defaultProps = vnode.nodeName.defaultProps,
- props = clone(vnode.attributes);
+ let props = clone(vnode.attributes);
+ props.children = vnode.children;
+ let defaultProps = vnode.nodeName.defaultProps;
if (defaultProps) {
for (let i in defaultProps) {
if (props[i]===undefined) {
@@ -44,7 +45,5 @@ export function getNodeProps(vnode) {
}
}
- if (vnode.children) props.children = vnode.children;
-
return props;
}