Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Correct SavedStateRegistryOwner Propagation in asComposableFactory #1233

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

ekeitho
Copy link
Contributor

@ekeitho ekeitho commented Nov 15, 2024

This PR enhances state management within asComposableFactory by ensuring that each view level correctly accesses its own SavedStateRegistryOwner, 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 crash java.lang.IllegalStateException: You can consumeRestoredStateForKey only after super.onCreate of corresponding component.

Solution

To resolve this, this PR updates asComposableFactory by explicitly setting the SavedStateRegistryOwner for each view level through setViewTreeSavedStateRegistryOwner. This change ensures that each view accesses its appropriate state registry owner, maintaining accurate restoration tracking at each hierarchy level.

@ekeitho ekeitho marked this pull request as ready for review November 15, 2024 21:20
@ekeitho ekeitho requested review from a team as code owners November 15, 2024 21:20
@ekeitho ekeitho changed the title specify registry owner Ensure Correct SavedStateRegistryOwner Propagation in ScreenComposableFactory Nov 15, 2024
@ekeitho ekeitho force-pushed the kabdulla/specify-registry-owner branch from e4eee94 to 759521c Compare November 15, 2024 21:26
@ekeitho ekeitho changed the title Ensure Correct SavedStateRegistryOwner Propagation in ScreenComposableFactory Ensure Correct SavedStateRegistryOwner Propagation in asComposableFactory Nov 15, 2024
@ekeitho ekeitho force-pushed the kabdulla/specify-registry-owner branch from 759521c to fe44ac4 Compare November 15, 2024 21:28
@rjrjr rjrjr merged commit b2e04e8 into main Nov 15, 2024
30 checks passed
@rjrjr rjrjr deleted the kabdulla/specify-registry-owner branch November 15, 2024 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants