Skip to content
Open
8 changes: 8 additions & 0 deletions AIDevGallery/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
NavigatedToPageEvent.Log(nameof(HomePage));
}

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.
this.Content = null;

base.OnNavigatingFrom(e);
Comment on lines +29 to +34
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.
}
Comment on lines +29 to +35
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.

private void Page_Loaded(object sender, RoutedEventArgs e)
{
if (!App.AppData.IsDiagnosticsMessageDismissed && PrivacyConsentHelpers.IsPrivacySensitiveRegion())
Expand Down
Loading