diff --git a/litho-core/src/main/java/com/facebook/litho/ComponentContext.java b/litho-core/src/main/java/com/facebook/litho/ComponentContext.java index 75f32980cd7..c69784c6036 100644 --- a/litho-core/src/main/java/com/facebook/litho/ComponentContext.java +++ b/litho-core/src/main/java/com/facebook/litho/ComponentContext.java @@ -524,6 +524,7 @@ static ComponentContext withComponentTree(ComponentContext context, ComponentTre ComponentContext componentContext = new ComponentContext(context, new StateHandler(), null, null, null); componentContext.mComponentTree = componentTree; + componentContext.mComponentScope = null; componentContext.mLayoutStateFuture = null; return componentContext; diff --git a/litho-it/src/test/java/com/facebook/litho/ComponentTreeTest.java b/litho-it/src/test/java/com/facebook/litho/ComponentTreeTest.java index bcafee320f2..7615c57c40b 100644 --- a/litho-it/src/test/java/com/facebook/litho/ComponentTreeTest.java +++ b/litho-it/src/test/java/com/facebook/litho/ComponentTreeTest.java @@ -165,6 +165,16 @@ public void testCreate() { Assert.assertFalse(componentTreeHasSizeSpec(componentTree)); } + @Test + public void testCreate_ContextIsNotScoped() { + ComponentContext scopedContext = + ComponentContext.withComponentScope(mContext, Row.create(mContext).build()); + ComponentTree componentTree = ComponentTree.create(scopedContext, mComponent).build(); + + ComponentContext c = Whitebox.getInternalState(componentTree, "mContext"); + Assert.assertNull(c.getComponentScope()); + } + @Test public void testSetSizeSpec() { ComponentTree componentTree = @@ -202,6 +212,25 @@ public void testSetSizeSpecAsync() { postSizeSpecChecks(componentTree, "mBackgroundLayoutState"); } + @Test + public void testLayoutState_ContextIsNotScoped() { + ComponentContext scopedContext = + ComponentContext.withComponentScope(mContext, Row.create(mContext).build()); + Component root = Column.create(scopedContext).build(); + + ComponentTree componentTree = ComponentTree.create(scopedContext, root).build(); + + componentTree.setSizeSpecAsync(mWidthSpec, mHeightSpec); + + mLayoutThreadShadowLooper.runOneTask(); + + LayoutState layoutState = getInternalState(componentTree, "mBackgroundLayoutState"); + ComponentContext c = getInternalState(componentTree, "mContext"); + assertThat(c).isNotEqualTo(scopedContext); + Assert.assertNull(c.getComponentScope()); + assertThat(layoutState.getRootComponent().getScopedContext()).isNotEqualTo(scopedContext); + } + @Test public void testSetSizeSpecAsyncThenSyncBeforeRunningTask() { ComponentTree componentTree =