From ea2aa07bfe00735c1ebe1bdae1fb2f94cdb190a6 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Mon, 27 May 2024 11:47:47 +0200 Subject: [PATCH] fix: dont add to parent from _setupAsRootView --- packages/core/ui/core/view-base/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/core/ui/core/view-base/index.ts b/packages/core/ui/core/view-base/index.ts index daab36d9e7..aeea90503b 100644 --- a/packages/core/ui/core/view-base/index.ts +++ b/packages/core/ui/core/view-base/index.ts @@ -1011,8 +1011,17 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition // } } + /** + * if _setupAsRootView is called it means it is not supposed to be + * added to a parent. However parent can be set before for the purpose + * of CSS variables/classes. That variable ensures that _addViewToNativeVisualTree + * is not called in _setupAsRootView + */ + mIsRootView = false; _setupAsRootView(context: any): void { + this.mIsRootView = true; this._setupUI(context); + this.mIsRootView = false; } /** @@ -1025,7 +1034,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition // this check is unnecessary as this function should never be called when this._context === context as it means the view was somehow detached, // which is only possible by setting reusable = true. Adding it either way for feature flag safety if (this.reusable) { - if (this.parent && !this._isAddedToNativeVisualTree) { + if (!this.mIsRootView && this.parent && !this._isAddedToNativeVisualTree) { const nativeIndex = this.parent._childIndexToNativeChildIndex(atIndex); this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, nativeIndex); } @@ -1100,7 +1109,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition this.setNativeView(nativeView); - if (this.parent) { + if (!this.mIsRootView && this.parent) { const nativeIndex = this.parent._childIndexToNativeChildIndex(atIndex); this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, nativeIndex); }