Skip to content

RichSuggestBox: close suggestion popup on unload - #899

Draft
azchohfi wants to merge 3 commits into
CommunityToolkit:mainfrom
azchohfi:azchohfi-richsuggestbox-unload-popup
Draft

azchohfi wants to merge 3 commits into
CommunityToolkit:mainfrom
azchohfi:azchohfi-richsuggestbox-unload-popup

Conversation

@azchohfi

@azchohfi azchohfi commented Nov 24, 2026 •

Copy link
Copy Markdown

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 21d2800c52f1636fd73b9b82376e50804434ec7d

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ Both regression rows fail on the test-only head and pass after the fix in native CI.
↑ After-fix native suite completed with 384 total, 381 passed and 3 skipped.
↑ The merge of main brought in only .github/workflows/build.yml. The product and test diff is identical to the native-tested commits.
↑ The Copilot review of the current head found no issues. It is a COMMENTED review, not a human approval.
↓ The current-head CI run 45710245897 is awaiting maintainer approval and has run no jobs. Native, UWP and Uno results for this head are therefore missing.
↓ UWP ran no component tests on the earlier heads.
↓ The agent approved both gated fork CI runs with the account's admin rights. No maintainer approved them.
Diagnosis confidence 9/10 ↑ The baseline fails only at the reopen-after-completion assertion, which matches the unguarded continuation.
↑ The assertion right after unload passed, so WinUI already closes the popup when it unloads.
Evidence fit 7.5/10 ↑ Explains an unloaded, unfocused owner whose popup is open with the full list, intermittently.
↓ The reported app runs were not traced to a request pending at unload.

Fixes

No linked issue. A native-only WinUI app sometimes left an unloaded RichSuggestBox's suggestion popup open with its full list. A fresh box's popup then appeared alongside it. The app used no third-party wrapper.

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

RequestSuggestionsAsync awaits SuggestionRequested.InvokeAsync(...), then calls ShowSuggestionsPopup(true). It never checks whether the request is still current or whether the control is still loaded. The control also has no Unloaded handling, so a request pending at unload is never cancelled. When its deferral completes, the continuation reopens the popup on the unloaded control.

This also covers a deferral that completes just before unload. Its continuation is already queued on the dispatcher and runs after unload.

What is the new behavior?

  • On Unloaded, the control cancels the pending query's existing CancellationTokenSource and closes the popup through the existing ShowSuggestionsPopup(false) path.
  • After the awaited request returns, the popup opens only if the request's token was not cancelled. A request cancelled by unload or replaced by a newer query no longer reopens the popup.

No public API changes. No delays were added.

The new Test_RichSuggestBox_UnloadClosesSuggestionPopup test types @ through the document selection. Its SuggestionRequested handler takes a deferral, so the request stays pending until the test completes it after unload. This ordering is deterministic, with no sleeps or retries. The test has two rows:

  • Popup open, request pending. It first asserts that the popup opened for @, then types A to leave a second request pending.
  • Popup closed, request pending. The first request is pending before the popup ever opens.

Both rows assert that the popup is closed after unload and still closed after the deferral completes.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • Tested code with current supported SDKs
  • New component
    • Documentation has been added
    • Sample in sample app has been added
    • Analyzers are passing for documentation and samples
    • Icon has been created (if new sample) following the Thumbnail Style Guide and templates
  • Tests for the changes have been added (if applicable)
  • Header has been added to all new source files
  • Contains NO breaking changes

Other information

The standard Windows App SDK component suite ran in the existing, unchanged CI workflow. Both runs restored Microsoft.WindowsAppSDK.WinUI 1.8.260204000.

  • Before the fix, test-only commit 3158c9e1f1e217c4c4617ab660bfa08e6a8ebe70 compiled. Both rows failed at Suggestion popup reopened after a pending request completed on an unloaded control. The assertion right after unload passed, so WinUI closes the popup on unload and the pending continuation reopens it. The full suite finished with 384 total, 379 passed, 2 failed and 3 skipped. Native baseline job.
  • After the fix, on commit d7dfbc92021c1feed1d35719ba186d61f56d444d, both unchanged rows passed. The full suite finished with 384 total, 381 passed and 3 skipped. After-fix native job.

Both UWP jobs built and passed the 39 source-generator tests (baseline, after fix). Both reported No test is available in entrypoint\CommunityToolkit.Tests.Uwp.exe for component tests, so they show only that the code builds.

Eight Uno-target jobs failed in Run Uno Check to Install Dependencies, before compiling. That is the shared CI issue fixed by #893.

Main, including #893 (af067edcc29e92cb28376aaf54f4cd99c8ac523f), was merged into this branch without rewriting history. The merge brought in only .github/workflows/build.yml. The current-head run 45710245897 on 21d2800c52f1636fd73b9b82376e50804434ec7d is awaiting maintainer approval for fork workflows and has run no jobs. The Uno jobs' behavior after #893 is therefore unverified on this PR. The native before/after results above belong to the commits named there, not to the current head.

The Copilot review of 21d2800c52f1636fd73b9b82376e50804434ec7d completed with no open issues or inline comments. Its state is COMMENTED, not a human approval.

Both earlier fork workflow runs (45497230771 and 45499992386) were waiting for approval. The agent approved them with the account's admin rights, not a maintainer. The agent has not approved the current-head run.

This PR remains draft. No merge or auto-merge is requested. No CI workflow was changed. No local GUI, Appx or OS operations were used.

azchohfi and others added 2 commits November 24, 2026 22:03
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Cancel the pending suggestion request and close the popup when the
control unloads, and do not reopen the popup from a request that was
superseded or cancelled while awaiting SuggestionRequested.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
…-unload-popup

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change preventing pending suggestion requests from reopening the popup after unload.

No open issues 🎉

What changed in this PR

Prevents pending suggestion requests from reopening a RichSuggestBox popup after the control unloads, without changing the public API.

Changes:

  • Cancels the current query and closes the suggestion popup on unload.
  • Checks cancellation before showing suggestions after an asynchronous request completes.
  • Adds regression tests for unloading with a pending request while the popup is either open or closed.
File Description
components/​RichSuggestBox/​tests/​Test_RichSuggestBox.cs Adds two deferred-request regression cases covering popup state after unload and request completion.
components/​RichSuggestBox/​src/​RichSuggestBox.Suggestion.cs Prevents cancelled requests from reopening the popup.
components/​RichSuggestBox/​src/​RichSuggestBox.cs Registers unload handling to cancel the current query and close the popup.

Review effort: Balanced

This branch has not been deployed

No deployments
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