jwstegemann / fritz2

Easily build reactive web-apps in Kotlin based on flows and coroutines.
https://www.fritz2.dev
MIT License
636 stars 25 forks source link

beforeUnmount not called recursively #782

Closed metin-kale closed 10 months ago

metin-kale commented 11 months ago

Hello,

the beforeUnmount feature is very usefull to do some cleanup before unmounting, but it is not reliably working.

In a simple example with one Store and one Store<*>.render it is working without problems, but when nesting render-Blocks, it is only called for the outer MountPoint.

Example:

   val outerStore = storeOf(Id.next())
   val innerStore = storeOf(Id.next())
   input {
        type("Button")
        value("Update Outer Store")
    }.clicks.map { Id.next() } handledBy outerStore.update
    input {
        type("Button")
        value("Update Inner Store")
    }.clicks.map { Id.next() } handledBy innerStore.update

    outerStore.data.render {
        p { +it }
        afterMount { _, _ -> console.log("outer afterMount") }
        beforeUnmount { _, _ -> console.log("outer beforeUnmount") }

        innerStore.data.render {
            p { +it }
            afterMount { _, _ -> console.log("inner afterMount") }
            beforeUnmount { _, _ -> console.log("inner beforeUnmount") }
        }
    }`

If i click the first button (Update Outer Store) i get following logs:

outer beforeUnmount
inner afterMount
outer afterMount

afterMount is called for both, but beforeUnmount is only called for the outer MountPoint. I would expect it to be called recursively on all levels.