Skip to content

Commit

Permalink
closes #2251 thanks to @rsbondi patch
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Feb 10, 2017
1 parent fd0eb05 commit 874a269
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/browser/tag/tag.js
Expand Up @@ -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', {})
Expand Down
4 changes: 3 additions & 1 deletion 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,
Expand Down Expand Up @@ -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),
Expand Down
19 changes: 19 additions & 0 deletions test/specs/browser/core.spec.js
Expand Up @@ -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'
Expand Down Expand Up @@ -1182,4 +1183,22 @@ describe('Riot core', function() {
tag.unmount()
})

it('virtual tags with conditional will mount their children tags properly', function() {
injectHTML('<virtual-conditional></virtual-conditional')
var tag = riot.mount('virtual-conditional')[0]

riot.util.tmpl.errorHandler = function () {
throw new Error('It should render without errors')
}

expect(tag.childMountCount).to.be.equal(0)
tag.user = { name: 'foo' }

tag.update()
expect(tag.childMountCount).to.be.equal(1)

riot.util.tmpl.errorHandler = null

})

})
21 changes: 21 additions & 0 deletions test/tag/virtual-conditional.tag
@@ -0,0 +1,21 @@
<virtual-conditional>
<virtual if={ user != null }>
<p>{ user.name }</p>
<virtual-conditional-child></virtual-conditional-child>
</virtual>

<script>
this.childMountCount = 0
this.user = null
</script>
</virtual-conditional>

<virtual-conditional-child>
<p>hi</p>

<script>
this.on('mount', function() {
this.parent.childMountCount ++
})
</script>
</virtual-conditional-child>

0 comments on commit 874a269

Please sign in to comment.