Fix duplicate state container view states#3095
Merged
TheCodeTraveler merged 11 commits intomainfrom Feb 14, 2026
Merged
Conversation
bijington
previously approved these changes
Feb 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a StateContainer bug where the default StateViews collection was shared across layouts, causing state views to bleed between different StateContainer usages (issue #3068).
Changes:
- Removed the static default
StateViewscollection fromStateContainerDefaults. - Updated the
StateViewsattached property default value creator to return a new empty collection per layout. - Adjusted
StateContainerControllerinitialization and updated unit tests accordingly.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/CommunityToolkit.Maui/Primitives/StateContainerDefaults.shared.cs | Removes the shared static default StateViews collection. |
| src/CommunityToolkit.Maui/Layouts/StateContainer/StateContainerController.shared.cs | Refactors controller construction and changes StateViews to IReadOnlyList with init. |
| src/CommunityToolkit.Maui/Layouts/StateContainer/StateContainer.shared.cs | Uses a new empty collection as the default StateViews value; controller creation now copies StateViews. |
| src/CommunityToolkit.Maui.UnitTests/Layouts/StateContainerTests.cs | Updates tests for the new StateViews behavior and adds a new uniqueness test. |
src/CommunityToolkit.Maui/Layouts/StateContainer/StateContainer.shared.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui/Layouts/StateContainer/StateContainerController.shared.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.UnitTests/Layouts/StateContainerTests.cs
Outdated
Show resolved
Hide resolved
…r.shared.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…rController.shared.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
src/CommunityToolkit.Maui/Layouts/StateContainer/StateContainerController.shared.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.UnitTests/Layouts/StateContainerTests.cs
Outdated
Show resolved
Hide resolved
…s.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
src/CommunityToolkit.Maui/Layouts/StateContainer/StateContainerController.shared.cs
Show resolved
Hide resolved
src/CommunityToolkit.Maui/Layouts/StateContainer/StateContainerController.shared.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.UnitTests/Layouts/StateContainerTests.cs
Outdated
Show resolved
Hide resolved
…s.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…rController.shared.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Collaborator
Author
|
Thanks @bijington! Could you give it one more quick review now that I implemented some of CoPilot's suggestions? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description of Change
This PR removes the
public static IList<View>that was being used for theDefaultValueCreatorof theStateContainer.StateViewsAttached Property, replacing it with a simple instance of a new collection,[].This fixes a bug where, where this
static IList<View>was being reused for everyStateViewfor everyStateContainer.Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information