Repository: jwstegemann/fritz2
Issue: Problem with nested `render`s which contains conditions

Here is the code to reproduce:
```kotlin
fun main() {
    val switch = storeOf(false)
    val data = storeOf("Hello World!")

    render {
        switch(store = switch) {
            label("Switch")
        }
        hr {}
        switch.data.render {
            if (it) {
                data.data.render { text ->
                    if (text.isNotBlank()) p { +text }
                }
            }
        }
    }
}
```

Changed files:
core/src/jsMain/kotlin/dev/fritz2/dom/tag.kt, core/src/jsMain/kotlin/dev/fritz2/binding/store.kt, core/src/jsTest/kotlin/dev/fritz2/dom/tag.kt

diff --git a/core/src/jsMain/kotlin/dev/fritz2/binding/store.kt b/core/src/jsMain/kotlin/dev/fritz2/binding/store.kt
index 30bf9f30..45341076 100644
--- a/core/src/jsMain/kotlin/dev/fritz2/binding/store.kt
+++ b/core/src/jsMain/kotlin/dev/fritz2/binding/store.kt
@@ -205,6 +205,18 @@ open class RootStore<T>(
      */
     override val job: Job = Job()
 
+    /**
+     * Emits a [Flow] with the current data of this [RootStore].
+     * The [Flow] internal data is only changed, when the value differs from the last one to avoid calculations
+     * and updates that are not necessary.
+     *
+     * Actual data therefore is derived by applying the updates on the internal channel one by one to get the next value.
+     */
+    override val data: Flow<T> = state.asStateFlow()
+
+    /**
+     * Represents the current data of this [RootStore].
+     */
     override val current: T
         get() = state.value
 
@@ -221,13 +233,6 @@ open class RootStore<T>(
         }
     }
 
-    /**
-     * the current value of a [RootStore] is derived be applying the updates on the internal channel one by one to get the next value.
-     * the [Flow] only emits a new value, when the value is differs from the last one to avoid calculations and updates that are not necessary.
-     * This has to be a SharedFlow, because the updated should only be applied once, regardless how many depending values or ui-elements or bound to it.
-     */
-    override val data = state.asStateFlow()
-
     /**
      * a simple [SimpleHandler] that just takes the given action-value as the new value for the [Store].
      */
diff --git a/core/src/jsMain/kotlin/dev/fritz2/dom/tag.kt b/core/src/jsMain/kotlin/dev/fritz2/dom/tag.kt
index 8f1259b8..107ab941 100644
--- a/core/src/jsMain/kotlin/dev/fritz2/dom/tag.kt
+++ b/core/src/jsMain/kotlin/dev/fritz2/dom/tag.kt
@@ -14,7 +14,6 @@ import kotlinx.coroutines.flow.*
 import org.w3c.dom.Element
 import org.w3c.dom.HTMLElement
 import org.w3c.dom.Node
-import kotlin.collections.set
 
 /**
  * Occurs when more then one root [Tag] is defined in a [render] context.
@@ -65,7 +64,7 @@ open class Tag<out E : Element>(
                     job, parent.domNode.unsafeCast<HTMLElement>()
                 ) {
                     override fun <E : Element, W : WithDomNode<E>> register(element: W, content: (W) -> Unit): W {
-                        content(element)
+                        parent.register(element, content)
                         add(element)
                         return element
                     }
@@ -86,7 +85,7 @@ open class Tag<out E : Element>(
                     if (alreadyRegistered) {
                         throw MultipleRootElementsException("You can have only one root-tag per html-context!")
                     } else {
-                        content(element)
+                        parent.register(element, content)
                         alreadyRegistered = true
                         return element
                     }
diff --git a/core/src/jsTest/kotlin/dev/fritz2/dom/tag.kt b/core/src/jsTest/kotlin/dev/fritz2/dom/tag.kt
index 5faaa414..4228a294 100644
--- a/core/src/jsTest/kotlin/dev/fritz2/dom/tag.kt
+++ b/core/src/jsTest/kotlin/dev/fritz2/dom/tag.kt
@@ -1,5 +1,6 @@
 package dev.fritz2.dom
 
+import dev.fritz2.binding.storeOf
 import dev.fritz2.dom.html.render
 import dev.fritz2.identification.uniqueId
 import dev.fritz2.test.initDocument
@@ -109,4 +110,47 @@ class TagTests {
         }
     }
 
+    @Test
+    fun testRenderWithCondition() = runTest {
+        initDocument()
+
+        val outerId = uniqueId()
+        val innerId = uniqueId()
+
+        val switch = storeOf(false)
+        val data = storeOf("Test")
+
+        render {
+            div(id = outerId) {
+                switch.data.render {
+                    if (it) {
+                        data.data.render { text ->
+                            if (text.isNotBlank()) div(id = innerId) { +text }
+                        }
+                    }
+                }
+            }
+        }
+
+        delay(300)
+
+        val outer = document.getElementById(outerId) as HTMLDivElement
+        fun inner() = document.getElementById(innerId) as HTMLDivElement
+
+        assertEquals(0, outer.childElementCount, "outer element has a children")
+
+        for(i in 0..2) {
+            switch.update(true)
+            delay(200)
+
+            assertEquals(1, outer.childElementCount, "[$i] outer element has no children")
+            assertEquals("Test", inner().textContent, "[$i] inner has no text")
+
+            switch.update(false)
+            delay(200)
+
+            assertEquals(0, outer.childElementCount, "[$i] outer element has no children")
+        }
+    }
+
 }
\\ No newline at end of file