Skip to content

Reduce AnyView usage in PaneGridView to improve SwiftUI diffing #64

@2witstudios

Description

@2witstudios

Problem

PaneGridView.swift wraps all nodes in AnyView to break the recursive opaque return type:

private func rootView(_ node: PaneSplitNode) -> AnyView { ... }
private func nodeView(_ node: PaneSplitNode) -> AnyView { ... }

AnyView defeats SwiftUI's structural diffing — it cannot efficiently compare old and new view trees, leading to full view hierarchy destruction/recreation on any change. For a grid of terminals, this means split ratio changes or focus changes can cause terminal views to be needlessly torn down and rebuilt.

Impact

  • Terminal views may be destroyed and recreated unnecessarily when focus changes or splits are adjusted
  • Animation transitions may not work correctly
  • SwiftUI's identity tracking is broken for the entire grid subtree

Suggested approach

Options to explore:

  1. Use @ViewBuilder with explicit conditional logic and stable view identities
  2. Use Group with stable .id() values at the leaf level
  3. Only type-erase at the leaf PaneCellView level, not the entire tree
  4. Consider a custom layout container that doesn't require type erasure

This is a complex change since the recursive tree structure genuinely needs type erasure somewhere — the goal is minimizing its scope.

Files

  • apps/purepoint-macos/purepoint-macos/Views/PaneGrid/PaneGridView.swift

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions