From 874a269db196cbb497c571cf1ed56a6e5f87f15f Mon Sep 17 00:00:00 2001 From: Gianluca Guarini Date: Fri, 10 Feb 2017 17:04:43 +0100 Subject: [PATCH] closes #2251 thanks to @rsbondi patch --- lib/browser/tag/tag.js | 4 ++-- lib/browser/tag/update.js | 4 +++- test/specs/browser/core.spec.js | 19 +++++++++++++++++++ test/tag/virtual-conditional.tag | 21 +++++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 test/tag/virtual-conditional.tag diff --git a/lib/browser/tag/tag.js b/lib/browser/tag/tag.js index 7e41bceeb1..e82d3cf3b3 100644 --- a/lib/browser/tag/tag.js +++ b/lib/browser/tag/tag.js @@ -114,8 +114,8 @@ export default function Tag(impl = {}, conf = {}, innerHTML) { // create a unique id to this tag // it could be handy to use it also to improve the virtual dom rendering speed defineProperty(this, '_riot_id', ++__uid) // base 1 allows test !t._riot_id - - extend(this, { root, opts }, item) + defineProperty(this, 'root', root) + extend(this, { opts }, item) // protect the "tags" and "refs" property from being overridden defineProperty(this, 'parent', parent || null) defineProperty(this, 'tags', {}) diff --git a/lib/browser/tag/update.js b/lib/browser/tag/update.js index 9fcc1adb18..92b876ba79 100644 --- a/lib/browser/tag/update.js +++ b/lib/browser/tag/update.js @@ -1,7 +1,7 @@ import { tmpl } from 'riot-tmpl' import { startsWith, each, contains } from './../common/util/misc' import { isFunction, isUndefined } from './../common/util/check' -import { remAttr, setAttr, createDOMPlaceholder } from './../common/util/dom' +import { remAttr, getAttr, setAttr, createDOMPlaceholder } from './../common/util/dom' import setEventHandler from './setEventHandler' import { initChildTag, @@ -75,6 +75,8 @@ export function updateDataIs(expr, parent) { * @returns { undefined } */ export function updateExpression(expr) { + if (this.root && getAttr(this.root,'virtualized')) return + var dom = expr.dom, attrName = expr.attr, isToggle = contains([SHOW_DIRECTIVE, HIDE_DIRECTIVE], attrName), diff --git a/test/specs/browser/core.spec.js b/test/specs/browser/core.spec.js index c5a1d18e91..6ddb0f0979 100644 --- a/test/specs/browser/core.spec.js +++ b/test/specs/browser/core.spec.js @@ -33,6 +33,7 @@ import '../../tag/runtime-event-listener-switch.tag' import '../../tag/should-update.tag' import '../../tag/observable-attr.tag' import '../../tag/virtual-nested-unmount.tag' +import '../../tag/virtual-conditional.tag' import '../../tag/form-controls.tag' import '../../tag/data-is.tag' import '../../tag/virtual-nested-component.tag' @@ -1182,4 +1183,22 @@ describe('Riot core', function() { tag.unmount() }) + it('virtual tags with conditional will mount their children tags properly', function() { + injectHTML(' + +

{ user.name }

+ +
+ + +
+ + +

hi

+ + +
\ No newline at end of file