Describe the bug
I have a stateless widget that builds a Query widget, the builder method of which returns a stateful widget. The widget structure is: Stateless -> Query -> Stateful. I pass fetchMore from the Query widget to the stateful widget. The stateful widget then calls fetchMore when going to the next page. When fetchMore is called, the initState of the stateful widget is also called. It seems like the stateful widget is getting disposed and recreated by the Query builder.
To Reproduce
Steps to reproduce the behavior:
initState hookbuild method of the stateless widget, return the graphql Query widget, in the builder method, return the stateful widget and pass fetchMore into it.fetchMore from the stateful widget. See that the print statement from initState is executed.Expected behavior
Fetching more does not dispose and recreate the child widget. It just updates the props.
Desktop (please complete the following information):
Smartphone (please complete the following information):
If I am getting what you said correctly if the Query is the one building the Stateful widget, then the rebuild of the stateful widget is almost expected. Whenever fetchmore is called, you are explicitly saying you want the previous results and new results to be merged. When the new data arrives, it is merged behind the scenes, the stream is updated with data containing both results as one and this is what triggers a rebuild.
@mainawycliffe thank you for the reply. Yes, I do expect a rebuild but that doesn't look like what is happening. I would expect the stateful widget to fire didUpdateWidget, rather than initState. This means that whenever I want to fetchMore, any state I was maintaining in the stateful widget is now lost. For example, if my stateful widget was a counter widget that fetched more on every 5 counts, it would reset to 0 with every fetchMore instead of fetching at 5, 10, 15, and so on. Is there a way around this?
Okay, that makes sense. You can try and lift the state up for now as we find a solution to this. I will investigate further.
@mainawycliffe @KevinShiCA any solution did you find?
:tada: This issue has been resolved in version 4.0.0-beta.3 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
:tada: This issue has been resolved in version 4.0.0 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket:
Most helpful comment
Okay, that makes sense. You can try and lift the state up for now as we find a solution to this. I will investigate further.