Ensure Correct SavedStateRegistryOwner Propagation in asComposableFactory #1233
+4
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR enhances state management within
asComposableFactory
by ensuring that each view level correctly accesses its ownSavedStateRegistryOwner
, preventing premature or incorrect state restoration assumptions.Problem
Previously, nested views in a hierarchy (e.g., grandparent, parent, and child views) could potentially retrieve a
SavedStateRegistryOwner
from a higher-level view (e.g., the grandparent) before intermediate levels (e.g., the parent) fully restored their state. This caused a state inconsistency where the child view could assume that all parent states were restored when, in fact, it wasn't. This caused a crashjava.lang.IllegalStateException: You can consumeRestoredStateForKey only after super.onCreate of corresponding component.
Solution
To resolve this, this PR updates
asComposableFactory
by explicitly setting theSavedStateRegistryOwner
for each view level throughsetViewTreeSavedStateRegistryOwner
. This change ensures that each view accesses its appropriate state registry owner, maintaining accurate restoration tracking at each hierarchy level.