From 2e43bf4f7b81551d00256edc5ccbfd3fa1567894 Mon Sep 17 00:00:00 2001 From: Barney Carroll Date: Sun, 27 Nov 2016 15:16:55 +0000 Subject: [PATCH] Add vnode caching warning under hyperscript documentation --- docs/hyperscript.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/hyperscript.md b/docs/hyperscript.md index af1067e9..e28781d1 100644 --- a/docs/hyperscript.md +++ b/docs/hyperscript.md @@ -408,3 +408,9 @@ var BetterListComponent = { } } ``` + +#### Avoid creating vnodes outside views + +When a redraw encounters a vnode which is strictly equal to the one in the previous render, it will be skipped and its contents will not be updated. While this may seem like an opportunity for performance optimisation, it should be avoided because it prevents dynamic changes in that node's tree - this leads to side-effects such as downstream lifecycle methods failing to trigger on redraw. In this sense, Mithril vnodes are immutable: new vnodes are compared to old ones; mutations to vnodes are not persisted. + +The component documentation contains [more detail and an example of this anti-pattern](components.md#avoid-creating-component-instances-outside-views).