Skip to content

Conversation

@HotCakeX
Copy link
Contributor

The carousel on the home page visually leaks to other pages after navigation, that means we can see the carousel on other pages briefly after clicking on the tiles in the home page carousel. This PR fixes this problem completely; however, you need to accept my previous PR first, otherwise this change won't work, and you will get an error after navigation: https://github.com/microsoft/ai-dev-gallery/pull/458/files

Please see the videos below for more details as they exactly show the issue this PR fixes:


Before

BEFORE.mp4

After

AFTER.mp4

HotCakeX and others added 6 commits September 28, 2025 21:06
Event handlers in the HoverLight weren't being unsubscribed On Disconnected.
OpacityMaskView wasn't handling resources properly on unload, causing memory leaks and also changing 

```csharp
private static CompositionBrush GetVisualBrush(UIElement element)
```

to 

```csharp
   private static CompositionSurfaceBrush GetVisualBrush(UIElement element)
```

improves performance.
The carousel on the home page visually leaks to other pages after navigation, that means we can see the carousel on other pages briefly after clicking on the tiles in the home page carousel. This PR fixes this problem completely, however, you need to accept my previous PR first, otherwise this change won't work: https://github.com/microsoft/ai-dev-gallery/pull/458/files
@weiyuanyue
Copy link
Contributor

Appreciate the intent to ensure resources are released when navigating away. However, I don’t think we should add this change as-is:

  • WinUI navigation already triggers Unloaded and tears down the visual tree. Forcibly clearing rootGrid.Children and setting this.Content = null can interfere with back navigation, page caching, and transition animations, and may cause blank pages or NREs on return.
  • This assumes this.Content is a Grid, which isn’t guaranteed long-term and is fragile.
  • Clearing mostRecentlyUsedItems is unnecessary; the page-level collection is repopulated on Loaded and will be GC’d when the page is disposed. If we need a fresh list per navigation, we can reset it in OnNavigatedTo/Loaded without tearing down the UI

@HotCakeX
Copy link
Contributor Author

HotCakeX commented Oct 16, 2025

Hi @weiyuanyue
Thanks for reviewing my PR, I believe I've addressed all of the points you raised while fixing the visual bug shown in the video. Will you please do another review?

Copilot AI review requested due to automatic review settings December 31, 2025 06:38
Copy link
Contributor

Copilot AI left a 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 fixes a visual bug where the home page carousel briefly appears on other pages during navigation. The fix adds an OnNavigatingFrom override that sets the page's Content to null before navigation completes, preventing the carousel from rendering during the transition.

Key Changes:

  • Added OnNavigatingFrom lifecycle method to HomePage that nulls the page content
  • Includes reference comment linking to this PR for context

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +29 to +35
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
// Remove all content to guarantee nothing can be rendered; reference issue: https://github.com/microsoft/ai-dev-gallery/pull/460
this.Content = null;

base.OnNavigatingFrom(e);
}
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

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

The pattern of using OnNavigatingFrom for page cleanup is inconsistent with how other pages in the codebase handle cleanup. Sample pages like SemanticSearch.xaml.cs (line 87), AppIndexCapability.xaml.cs (line 74), and KnowledgeRetrieval.xaml.cs (line 141) use OnNavigatedFrom for cleanup operations. SettingsPage uses OnNavigatingFrom specifically to cancel navigation when a cache move is in progress (SettingsPage.xaml.cs:53-60).

For HomePage, which doesn't need to cancel navigation, using OnNavigatedFrom would be more consistent with the established pattern and would ensure the navigation completes before cleanup begins.

Copilot uses AI. Check for mistakes.
Comment on lines +29 to +34
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
// Remove all content to guarantee nothing can be rendered; reference issue: https://github.com/microsoft/ai-dev-gallery/pull/460
this.Content = null;

base.OnNavigatingFrom(e);
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

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

Setting this.Content = null during navigation may have unintended side effects. When Content is set to null before the navigation completes, it can prevent the Unloaded event from firing properly on child controls like the HeaderCarousel. The HeaderCarousel has cleanup logic in its UserControl_Unloaded handler (HeaderCarousel.xaml.cs:211-214) that stops timers and unsubscribes from events. If this cleanup doesn't run, the timers may continue to fire and could cause issues when trying to access controls that no longer exist.

A more robust solution would be to ensure the HeaderCarousel's cleanup runs reliably, either by using OnNavigatedFrom instead (which fires after navigation completes), or by explicitly calling cleanup on the HeaderCarousel before setting Content to null.

Suggested change
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
// Remove all content to guarantee nothing can be rendered; reference issue: https://github.com/microsoft/ai-dev-gallery/pull/460
this.Content = null;
base.OnNavigatingFrom(e);
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
// Remove all content to guarantee nothing can be rendered; reference issue: https://github.com/microsoft/ai-dev-gallery/pull/460
this.Content = null;

Copilot uses AI. Check for mistakes.

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
// Remove all content to guarantee nothing can be rendered; reference issue: https://github.com/microsoft/ai-dev-gallery/pull/460
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

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

The comment references PR #460, but according to the PR metadata, this is PR #460. The reference should likely point to the dependency PR #458 mentioned in the description, or the issue being fixed. This creates confusion about what issue is being referenced.

Suggested change
// Remove all content to guarantee nothing can be rendered; reference issue: https://github.com/microsoft/ai-dev-gallery/pull/460
// Remove all content to guarantee nothing can be rendered; reference issue: https://github.com/microsoft/ai-dev-gallery/pull/458

Copilot uses AI. Check for mistakes.
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.

3 participants