Issues with List selection in Sequoia (SwiftUI)

In one of my applications I use several List views with Sections. After upgrading to Sequoia I faced the issue, that after selecting an item, the List suddenly scrolls to a different position. Sometimes the selection even gets out of the view, but in every case a double click just went to the wrong item.

At one list I found out, that the issue could be solved after changing the data source. I used a computed property, what seems to be a stupid idea. After changing this it now works.

Unfortunately there is another List, where this didn't bring the solution. And unfortunately, I cannot reproduce the issue in a code example. One guess of mine is, that it could be related to the fact, that the rows have different heights (because in some are two lines of text and in some are three). And it seems to happen only in very long lists.

It worked perfectly in Sonoma.

Does anyone face the same issue?

I just filed a bug (FB15269193). It happens only in very long lists and only when scrolling down the first time. List seems to recalculate the heights of the cells and there must be a bug. I hope, that Apple will fix this in the next release.

@joachim_me Thanks for filling the bug report. I looked at the Sample project and I wasn't able to reproduce the issue. Selecting an item in the List doesn't perform any additional action apart from highlighting the item.

Perhaps is there any additional steps needed to reproduce the issue in the sample code you provided.

Since you're able to reproduce the issue consistently in your actual project, I would suggest you could start with a copy of your existing project, and remove code not essential to the issue. Remove code iteratively, re-testing after every removal. If you find that you can no longer demonstrate the issue after removing a particular piece of code, it’s likely that the issue is within the last-removed code. After restoring this code to the project, keep reducing the surrounding code until everything remaining is essential to the issue.

Thank you very much for your answer. Did you saw the video I made from the behaviour? It's interesting, that you couldn't reproduce. Please scroll nearly to the bottom and then select an item.

In my other project I could solve the problem after deleting everything what was displayed in the list and I only had one Text element. But that surely cannot be the solution ;)

Could you reproduce this bug? Do you need any additional informations? I couldn't find a workaround for this bug.

I didn't change any line of code and I didn't have the problem with Sonoma.

Sorry to bother again, but please: Any reaction to this? The bug still exists in 15.1. Am I the only one experiencing this bug?

Maybe it has to do sth. with this change?

Fixed: List on macOS 15 does not use NSTableView for showing non-outline content anymore. (77273697)

I will send my whole code at the end of this post. But if you test it, I do the following. I just compile my app and start it. I then scroll down to "section 14" Then I click on "element 4" and the scroll position will randomly change.

It will look like this:

With Instruments I see internal stuff like this when selecting:

[NSTableRowHeightData computeTotalRowsSpan]

or

[NSTableRowHeightData _estimatedRowAtOffset:]

This is my code, anyone can try.

import SwiftUI

struct ListElement: Identifiable {
	var id = UUID()
	var section: String
	var entries: [Entry]
}

struct Entry: Identifiable, Hashable {
	var id = UUID()
	var text: String
}

struct ContentView: View {
	
	let listElements = [
		ListElement(
			section: "Section 1",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 2",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 3",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 4",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 5",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 6",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 7",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 8",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 9",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 10",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 11",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 12",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 13",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 14",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 15",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 16",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
		ListElement(
			section: "Section 17",
			entries: [
				Entry(text: "Element 1"),
				Entry(text: "Element 2"),
				Entry(text: "Element 3"),
				Entry(text: "Element 4"),
				Entry(text: "Element 5"),
				Entry(text: "Element 6"),
				Entry(text: "Element 7"),
			]),
	]
	
	@State var selected: UUID?
	
    var body: some View {
		List(selection: self.$selected) {
			ForEach(self.listElements) { element in
				Section {
					ForEach(element.entries) { entry in
						EntryView(entry: entry)
					}
				} header: {
					Text(element.section)
				}
			}
		}
    }
}

struct EntryView: View {
	let entry: Entry
	var body: some View {
		VStack(alignment: .leading, spacing: 2) {
			Text(entry.text)
			Text("another line")
		}
	}
}

#Preview {
    ContentView()
}
Issues with List selection in Sequoia (SwiftUI)
 
 
Q