State Value is not preserved when ComponentsConfiguration.isEndToEndTestRun = true;
See original GitHub issue- I have searched existing issues and this is not a duplicate
Version
***implementation ‘com.facebook.litho:litho-core:0.21.0’ implementation ‘com.facebook.litho:litho-widget:0.21.0’ compileOnly ‘com.facebook.litho:litho-annotations:0.21.0’
annotationProcessor 'com.facebook.litho:litho-processor:0.21.0'
// SoLoader
implementation 'com.facebook.soloader:soloader:0.5.1'
// For testing
testImplementation 'com.facebook.litho:litho-testing:0.21.0'***
Issues and Steps to Reproduce
Enable the flag ComponentsConfiguration.isEndToEndTestRun = true in MainActivity. State values are not preserved with ComponentsConfiguration.isEndToEndTestRun = true
Expected Behavior
State values should be preserved with ComponentsConfiguration.isEndToEndTestRun = true
Link to Code
MainActivity
Add ComponentsConfiguration.isEndToEndTestRun = true
MyColumnComponentSpec.java : Create 3 TextWithState Components with state values
@LayoutSpec
public class MyColumnComponentSpec {
@OnCreateLayout
static Component onCreateLayout(ComponentContext c) {
return Column.create(c)
.child(TextWithState.create(c).initial(1))
.child(TextWithState.create(c).initial(2))
.child(TextWithState.create(c).initial(3))
.build();
}
}
TextWithStateSpec.java Same state value is present in all 3 TextWithState components even though I pass different state value "in @Prop initial "
@LayoutSpec
public class TextWithStateSpec {
@OnCreateInitialState
static void OnCreateInitialState(
ComponentContext c,
StateValue<Integer> counter,
@Prop int initial) {
counter.set(initial);
}
@OnCreateLayout
static Component onCreateLayout(
ComponentContext c,
@State int counter) {
return Text.create(c).text("count = "+counter).textSizeDip(30)
.build();
}
}
Screenshots : When ComponentsConfiguration.isEndToEndTestRun = false State Values are maintained individually
When ComponentsConfiguration.isEndToEndTestRun = true Same state value for all 3 text components.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Thank you @astreet for looking into this quickly and fixing it.
While debugging this, I found https://github.com/facebook/litho/blob/master/litho-core/src/main/java/com/facebook/litho/Component.java#L600
When I remove the check “!ComponentsConfiguration.isEndToEndTestRun” - UI is rendered properly and state values are preserved individually . Since the key is not registered for every component when ComponentsConfiguration.isEndToEndTestRun = true , Key is duplicated and state value is also duplicated.