From d380ee5f09dfc31e9966af1d707ad080aa747386 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Fri, 24 Nov 2023 12:55:01 +0100 Subject: [PATCH] skip first value from observable --- .../core/tree/tree-item-base/tree-item-base.context.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item-base/tree-item-base.context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item-base/tree-item-base.context.ts index 14306252c3..13a245f703 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item-base/tree-item-base.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/tree/tree-item-base/tree-item-base.context.ts @@ -26,6 +26,7 @@ export class UmbTreeItemContextBase #hasChildren = new UmbBooleanState(false); hasChildren = this.#hasChildren.asObservable(); + #hasChildrenInitValueFlag = false; #isLoading = new UmbBooleanState(false); isLoading = this.#isLoading.asObservable(); @@ -194,9 +195,14 @@ export class UmbTreeItemContextBase const observable = await this.treeContext.childrenOf(this.unique); - // observe if any children will be added runtime to a tree item + // observe if any children will be added runtime to a tree item. Nested items/folders etc. this.observe(observable.pipe(map((children) => children.length > 0)), (hasChildren) => { - this.#hasChildren.next(hasChildren); + // we need to skip the first value, because it will also return false until a child is in the store + // we therefor rely on the value from the tree item itself + if (this.#hasChildrenInitValueFlag === true) { + this.#hasChildren.next(hasChildren); + } + this.#hasChildrenInitValueFlag = true; }); }