-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[PR-Agent] Fix ApplyQueryAttributes called with empty dictionary on back #33451
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
base: main
Are you sure you want to change the base?
Conversation
Prevents ApplyQueryAttributes from being called with an empty dictionary when navigating back after query.Clear() is used, respecting user intent. Adds tests to verify correct behavior and ensure the method is not called unnecessarily on back navigation.
|
Hey there @@kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR attempts to fix issue #33415 where ApplyQueryAttributes is incorrectly called with an empty dictionary when navigating back after query.Clear() has been called, which violates the documented behavior.
Key changes:
- Adds conditional checks in
ShellNavigationManager.csto skip applying/setting query attributes when the merged data is empty during back navigation - Adds comprehensive UI test coverage (HostApp + NUnit) that reproduces the issue and validates the fix
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33415.cs |
NUnit UI test that validates ApplyQueryAttributes is not called with empty dictionary on back navigation |
src/Controls/tests/TestCases.HostApp/Issues/Issue33415.cs |
TestShell-based test page with IQueryAttributable implementation that tracks call count and calls query.Clear() |
src/Controls/src/Core/Shell/ShellNavigationManager.cs |
Adds conditional logic to skip applying/setting query attributes when data is empty during back navigation |
| //if we are pop or navigating back, we need to apply the query attributes to the ShellContent | ||
| if (isPopping) | ||
| { | ||
| element.SetValue(ShellContent.QueryAttributesProperty, mergedData); |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When isPopping is true and mergedData is empty, setting the QueryAttributesProperty on line 318 will trigger OnQueryAttributesPropertyChanged callback, which will eventually call IQueryAttributable.ApplyQueryAttributes on the content page (via the static ApplyQueryAttributes method in ShellContent.cs lines 368-376). This means the user's ApplyQueryAttributes will be called with an empty dictionary even though the check at lines 323-326 tries to prevent it. Consider adding a check before line 318: if (mergedData.Count > 0) { element.SetValue(...); }
| element.SetValue(ShellContent.QueryAttributesProperty, mergedData); | |
| if (mergedData.Count > 0) | |
| { | |
| element.SetValue(ShellContent.QueryAttributesProperty, mergedData); | |
| } |
| // BUG: According to documentation, after calling query.Clear() in ApplyQueryAttributes, | ||
| // the method should NOT be called again when navigating back. | ||
| // However, it IS called with an empty dictionary. | ||
| var finalCallCount = App.FindElement("CallCountLabel").GetText(); | ||
| var finalStatus = App.FindElement("StatusLabel").GetText(); | ||
|
|
||
| // This assertion will FAIL (demonstrating the bug) | ||
| // Expected: Call count should still be 1 (ApplyQueryAttributes should not be called on back) | ||
| // Actual: Call count will be 2 (ApplyQueryAttributes IS called with empty dictionary) |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments on lines 54-56 state "This assertion will FAIL (demonstrating the bug)" which is misleading since this test is part of the PR that includes the fix. The test should PASS with the fix applied. Consider updating the comment to reflect that this test verifies the fix works correctly, e.g., "This assertion verifies that ApplyQueryAttributes is NOT called when navigating back after query.Clear()"
| // BUG: According to documentation, after calling query.Clear() in ApplyQueryAttributes, | |
| // the method should NOT be called again when navigating back. | |
| // However, it IS called with an empty dictionary. | |
| var finalCallCount = App.FindElement("CallCountLabel").GetText(); | |
| var finalStatus = App.FindElement("StatusLabel").GetText(); | |
| // This assertion will FAIL (demonstrating the bug) | |
| // Expected: Call count should still be 1 (ApplyQueryAttributes should not be called on back) | |
| // Actual: Call count will be 2 (ApplyQueryAttributes IS called with empty dictionary) | |
| // According to documentation, after calling query.Clear() in ApplyQueryAttributes, | |
| // the method should NOT be called again when navigating back. | |
| // This test verifies that behavior and ensures ApplyQueryAttributes is not invoked with an empty dictionary. | |
| var finalCallCount = App.FindElement("CallCountLabel").GetText(); | |
| var finalStatus = App.FindElement("StatusLabel").GetText(); | |
| // This assertion verifies that ApplyQueryAttributes is NOT called when navigating back after query.Clear() | |
| // i.e., the call count should still be 1 when returning to the main page. |
|
|
||
| // If the bug exists, this will show it was called with empty dictionary | ||
| if (finalCallCount != "Call count: 1") | ||
| { | ||
| Assert.That(finalStatus, Is.EqualTo("Status: ApplyQueryAttributes called with EMPTY dictionary"), | ||
| "If ApplyQueryAttributes is incorrectly called, it's called with empty dictionary"); | ||
| } |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional check at lines 61-65 is redundant. If the assertion at line 57 passes (finalCallCount == "Call count: 1"), this code block will never execute. If the assertion fails, the test will already have failed. Consider removing this conditional block as it serves no purpose.
| // If the bug exists, this will show it was called with empty dictionary | |
| if (finalCallCount != "Call count: 1") | |
| { | |
| Assert.That(finalStatus, Is.EqualTo("Status: ApplyQueryAttributes called with EMPTY dictionary"), | |
| "If ApplyQueryAttributes is incorrectly called, it's called with empty dictionary"); | |
| } |
85e8a85 to
b6951b8
Compare
PR Review: #33451 - Fix ApplyQueryAttributes called with empty dictionary on back✅ Final Recommendation: APPROVEDate: 2026-01-09 | Issue: #33415 | PR: #33451 ✅ Status: COMPLETE - APPROVE
📋 Issue SummaryIssue: ApplyQueryAttributes gets called with empty Dictionary on back navigation even after calling Expected Behavior: According to Microsoft's documentation, calling Current Behavior: Steps to Reproduce:
Platforms Affected:
Version: 10.0.20, also verified in 9.0.120 and 10.0.10 Workaround: Return early from 📁 Files Changed
💬 PR Discussion SummaryPR Author: @kubaflo (community contributor) Key Comments:
Reviewer Feedback:
Disagreements to Investigate:
Author Uncertainty:
Prior Agent Session:
🧪 TestsStatus: ⏳ PENDING
Test Files:
Test Type: UI Tests (NUnit with Appium) 🚦 Gate - Test VerificationStatus: ✅ PASSED
Result: PASSED ✅ Tests correctly reproduce the bug:
🔧 Fix CandidatesStatus: ✅ COMPLETE
Fix Analysis: try-fix #1 (ShellContent):
PR's fix (ShellNavigationManager):
Exhausted: Yes - only one alternative approach found; other variations would be similar |
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
Fixes #33415
According to Microsoft's documentation, calling
query.Clear()inApplyQueryAttributesshould prevent the method from being called again when re-navigating to the existing page (e.g., withGoToAsync("..")).Current Behavior:
ApplyQueryAttributesIS called with an empty dictionary when navigating back, even after callingquery.Clear().Expected Behavior:
ApplyQueryAttributesshould NOT be called with empty dictionary afterquery.Clear()has been called.Root Cause
ApplyQueryAttributeswas being invoked via two separate code paths during back navigation:baseShellItem is ShellContent(ShellNavigationManager.cs, lines 313-331)baseShellItemis NOTShellContent(e.g.,ShellSection) butisLastItem=true(lines 334-341)Both paths would set/call
ApplyQueryAttributeseven when the merged query data was empty during back navigation.Changes Made
Files Modified:
src/Controls/src/Core/Shell/ShellNavigationManager.cs(+12 lines)mergedData.Count == 0 && isPopping == truemergedData.Count == 0 && isPopping == truesrc/Controls/src/Core/Shell/ShellContent.cs(+3 lines)Logic:
Tests Added:
HostApp:
src/Controls/tests/TestCases.HostApp/Issues/Issue33415.csIQueryAttributableand callsquery.Clear()NUnit:
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue33415.csApplyQueryAttributescalled once (with params), not twice (with params + empty on back)Verification
✅ Tests FAIL without fix (bug reproduced)
✅ Tests PASS with fix (bug fixed)
Platforms Affected
Breaking Changes
None - This restores the documented behavior.