Skip to content

Instantly share code, notes, and snippets.

@hydrixos
hydrixos / selection-bug.swift
Created January 21, 2026 14:12
macOS: Phantom row with OutlineGroup
// Simple example that results in a phantom row when using OutlineGroup.
//
// Just click on the button three times. Make sure the List is fully expanded.
// The issue seems to be that the List's selection is set to an item's ID that is not yet in the model.
//
import SwiftUI
struct ContentView: View {
@State var count = 0
@hydrixos
hydrixos / gist:6c7ef9a3417a448bf3539b3dfc3aa998
Last active January 21, 2026 13:31
macOS + SwiftUI: Bug with DisclosureGroup and Selection
// macOS + SwiftUI: Bug with DisclosureGroup and Selection
//
// This example shows a simple window with a sidebar list showing an outline.
// Just follow the instructions in the sample app. Clicking the button three times will result in a phantom row.
//
// Reason seems that
// 1. selection is set before the model update
// 2. DisclosureGroup is inside a conditional view
//
// The problem disappears if DisclosureGroup is unconditional. Or when using OutlineGroup.