Skip to content

Commit

Permalink
fix mountpoint in portals (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
metin-kale committed Jan 3, 2024
1 parent 3c42185 commit d5c1d52
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/src/jsMain/kotlin/dev/fritz2/core/mount.kt
Expand Up @@ -88,7 +88,7 @@ internal abstract class MountPointImpl : MountPoint, WithJob {
}
}

internal val MOUNT_POINT_KEY = Scope.Key<MountPoint>("MOUNT_POINT")
val MOUNT_POINT_KEY = Scope.Key<MountPoint>("MOUNT_POINT")

/**
* Allows to access the nearest [MountPoint] from any [WithScope]
Expand Down
Expand Up @@ -29,7 +29,7 @@ private data class PortalContainer<C : HTMLElement>(
val remove = PortalStack.handle { list -> list.filterNot { it.portalId == portalId } }

fun render(ctx: RenderContext) =
tag(ctx, classes, id, scope) {
tag(ctx, classes, id, scope + { ctx.scope[MOUNT_POINT_KEY]?.let { set(MOUNT_POINT_KEY, it) } }) {
content.invoke(this) { remove.invoke() }
reference?.beforeUnmount(this, null) { _, _ -> remove.invoke() }
}
Expand Down Expand Up @@ -60,7 +60,9 @@ internal object PortalRenderContext : HtmlTag<HTMLDivElement>("div", portalRootI
attr(Aria.live, "polite")

PortalStack.data.distinctUntilChangedBy { it.map { it.portalId } }
.renderEach(PortalContainer<*>::portalId, into = this) { it.render(this) }
.renderEach(PortalContainer<*>::portalId, into = this) {
it.render(this)
}

MainScope().launch {
delay(500)
Expand Down

0 comments on commit d5c1d52

Please sign in to comment.