Skip to content

Control recycling fixes#1012

Merged
wieslawsoltes merged 20 commits intomasterfrom
fix/issue-1010-recycling
Jan 28, 2026
Merged

Control recycling fixes#1012
wieslawsoltes merged 20 commits intomasterfrom
fix/issue-1010-recycling

Conversation

@wieslawsoltes
Copy link
Owner

@wieslawsoltes wieslawsoltes commented Jan 28, 2026

Overview

This change set fixes control recycling across floating host windows and strengthens view reuse/detachment behavior throughout Dock's Avalonia integration. It also tightens document navigation behavior so previously closed documents reopen correctly, plus adds targeted tests.

Key Changes

  • Share a ControlRecycling instance per factory across DockControl instances so floating windows reuse the same cached views; keep TryToUseIdAsKey aligned when a local setting differs.
  • Improve recycling behavior to update cached controls via IRecyclingDataTemplate, detach controls from their visual/logical parents safely (including ContentPresenter.Child), and rebuild fallback controls when detachment fails.
  • Update ControlRecyclingDataTemplate and TemplateHelper to honor existing controls and detach/rebuild safely to avoid orphaned visual parents.
  • Make ManagedDockWindowDocument reuse the existing control parameter and detach direct/template content with a safe fallback, preventing recycled controls from staying attached elsewhere.
  • Harden OverlayHost pipeline rebuilding to detach templated content by checking both ContentPresenter.Child and ContentPresenter.Content.
  • Adjust DockNavigationService.OpenDocument to only short-circuit when the document is still in its owner dock; otherwise re-add the document.
  • Avoid reassigning the same ViewModel instance in the ReactiveUI canonical sample to prevent redundant updates.

Tests Added/Updated

  • Added coverage for detaching controls from ContentPresenter and preserving bindings during recycling reparenting.
  • Added overlay pipeline test to ensure detaching from visual parent works with templated content.
  • Added tests for document reopen logic when a document was removed from its owner.

Tests Run

  • dotnet test tests/Dock.Model.ReactiveUI.UnitTests/Dock.Model.ReactiveUI.UnitTests.csproj
  • dotnet build src/Dock.Avalonia/Dock.Avalonia.csproj -c Debug
  • dotnet test (timed out after 2m and 4m)

Avoid clearing bound presenter content and fallback to new controls when detach fails.
Cover detached presenters and cached control reuse paths.
Skip recycling when a ContentPresenter template already recycles.
This prevents reparenting errors without reflection.
Cover fallback behavior when cached controls remain attached.
Allow reparenting cached controls from ContentPresenter
regardless of recycling templates.
Exercise reparenting through recycling templates and
ContentPresenter detachment paths.
Avoid reusing attached views when ids collide.
Cover id collisions while a cached control is still visible.
Remove instance tracking and the test that depended on it.
Activate matching documents by Id and cover with unit tests.
Handle visual parents when rebuilding overlay pipeline.
Always add new documents unless the instance is already docked.
Avoid reusing an existing control when building a new key and add
coverage for cross-key recycling.
Ensure recycled ViewModelViewHost refreshes ViewModel.
Use a per-factory cache so floating hosts reuse controls.
Only short-circuit OpenDocument when the owner still contains the doc.
Align TryToUseIdAsKey when sharing recyclers.
Handle ContentPresenter child detachment before rebuilding pipeline.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant