[PR #1038] [CLOSED] Fix VirtualizingWrapPanel crash in Card View during auto-startup #1907

Closed
opened 2026-02-28 12:07:17 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/1Remote/1Remote/pull/1038
Author: @Copilot
Created: 11/25/2025
Status: Closed

Base: mainHead: copilot/fix-issue-1014-root-cause


📝 Commits (4)

  • df81605 Initial plan
  • 50eccbe Fix VirtualizingWrapPanel crash by using DeferRefresh during collection modifications
  • 14f2808 Refactor: Extract GetDeferredRefresh helper method to reduce code duplication
  • 577583c Fix VirtualizingWrapPanel crash by detaching ItemsSource during collection changes

📊 Changes

1 file changed (+86 additions, -20 deletions)

View changed files

📝 Ui/View/ServerView/List/ServerListPageViewModel.cs (+86 -20)

📄 Description

  • Understand issue #1037 and #1014 - VirtualizingWrapPanel crash in Card View during auto-startup
  • Analyze stack trace and log - crash occurs in ItemContainerManager.Virtualize() during layout measurement
  • First attempt: DeferRefresh() - FAILED - WPF doesn't allow collection changes while refresh is deferred
  • Second attempt: Detach/reattach ItemsSource - New approach that works correctly
  • Implement fix: Temporarily detach ListBox ItemsSource during collection modifications
    • Modified BuildView() to detach/reattach around Clear+Add operations
    • Modified VmServerListDummyNode() to detach/reattach around Add/Remove operations
    • Modified DeleteServer() to detach/reattach around Remove operation
  • Run code review and address feedback (added wasDetached flag for clarity)
  • Run CodeQL security scan - no alerts found

Summary

The previous DeferRefresh() approach failed because WPF throws InvalidOperationException when trying to modify a collection while refresh is deferred.

The new approach temporarily sets ListBox.ItemsSource = null before making collection changes, then restores the original source after all changes are complete. This prevents the VirtualizingWrapPanel from receiving CollectionChanged events during modifications.

Original prompt

根据 #1037,显然#1014的问题并没有得到修复,你应当根据反馈的描述,详细检查每一处代码,找到issue的根源。


Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/1Remote/1Remote/pull/1038 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 11/25/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `copilot/fix-issue-1014-root-cause` --- ### 📝 Commits (4) - [`df81605`](https://github.com/1Remote/1Remote/commit/df816059d8a970e8d890d0817a4136736972d90f) Initial plan - [`50eccbe`](https://github.com/1Remote/1Remote/commit/50eccbe7e0aa1ab44e8cb04cbff543f804040183) Fix VirtualizingWrapPanel crash by using DeferRefresh during collection modifications - [`14f2808`](https://github.com/1Remote/1Remote/commit/14f2808b92b5279a0d25b8725e2d85dbe7461820) Refactor: Extract GetDeferredRefresh helper method to reduce code duplication - [`577583c`](https://github.com/1Remote/1Remote/commit/577583cbe843566baf084b826b81719706e73250) Fix VirtualizingWrapPanel crash by detaching ItemsSource during collection changes ### 📊 Changes **1 file changed** (+86 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `Ui/View/ServerView/List/ServerListPageViewModel.cs` (+86 -20) </details> ### 📄 Description - [x] Understand issue #1037 and #1014 - VirtualizingWrapPanel crash in Card View during auto-startup - [x] Analyze stack trace and log - crash occurs in `ItemContainerManager.Virtualize()` during layout measurement - [x] First attempt: DeferRefresh() - **FAILED** - WPF doesn't allow collection changes while refresh is deferred - [x] Second attempt: Detach/reattach ItemsSource - New approach that works correctly - [x] Implement fix: Temporarily detach ListBox ItemsSource during collection modifications - Modified `BuildView()` to detach/reattach around Clear+Add operations - Modified `VmServerListDummyNode()` to detach/reattach around Add/Remove operations - Modified `DeleteServer()` to detach/reattach around Remove operation - [x] Run code review and address feedback (added `wasDetached` flag for clarity) - [x] Run CodeQL security scan - no alerts found ## Summary The previous `DeferRefresh()` approach failed because WPF throws `InvalidOperationException` when trying to modify a collection while refresh is deferred. The new approach temporarily sets `ListBox.ItemsSource = null` before making collection changes, then restores the original source after all changes are complete. This prevents the VirtualizingWrapPanel from receiving CollectionChanged events during modifications. <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > 根据 #1037,显然#1014的问题并没有得到修复,你应当根据反馈的描述,详细检查每一处代码,找到issue的根源。 </details> <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/1Remote/1Remote/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-28 12:07:17 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/1Remote#1907
No description provided.