iOS 16.1 Crashes when scroll (LazyVStack and LazyVGrid)

Code to reproduce:

struct CrashView: View {
  var body: some View {
     
    ScrollView {
      LazyVStack {
        ForEach(0...100, id: \.self) { i in
          LazyVGrid(columns: Array(repeating: .init(.fixed(100)), count: 3), content: {
            ForEach(0...20, id: \.self) { i in
              Color.red.opacity(Double(i + 1) / 20).frame(height: 300)
            }
          })
        }
      }
    }
     
  }
}

Important: it crashes on iOS 16.1 !!!

We have 21 grid item (3 item and 7 full lines) for every LazyVStack item. Scroll it until 5 LazyVStack item. Start scrolling to top. It blinks and show incorrect count: you see that it shows 1 item in line, but it is impossible. If you continue scrolling app crashes.

UPD: iOS 16.2 beta crashes as well

this is also happening to my app, have you find any alternative solution to this?

I just tried using iOS 16's Grid & Grid Row, and the crash is no longer happening.

I tried replacing the LazyVGrid with the new Grid for iOS 16 and the crash no is longer happening

Also encounter this bug, very frustrating.

Please care more about SwiftUI

From my testing, it looks like the crash occurs when there is more than one "lazy" view inside a scrollview. If you have single LazyVGrid then it does not crash.

@Kingsquat is righ,t if we have multiple LazyVGrids then it starts acting up, my only solution at the moment is using LazyHStack inside of LazyVStack. It seems to have worked better than the new Grid API, it behaves very weirdly. Though, I'm still hoping for some light regarding to the usage of multiple grids.

Just want to add that our app is also encountering this issue suddenly on devices iOS 16.1 and up 😐

Same issue here... Multiple LazyVGrids in a scrollview sharing the same grid layout with up to 4 items per row. Initial load is just fine. Scroll to the bottom no problem. Then start scrolling back to the top. Crashes when it reaches one of the LazyVGrids where the last row is a full row (i.e. has a multiple of 4 items). Other LazyVGrids with 1, 2, or 3 items in the last row have no problem. Like the OP, looks like an extra item is being inserted in the LazyVGrid that crashes as it gets pushed to an extra row, but cannot scroll up any more to see. Same non-helpful crash report too.

Crash happens regardless if I declare the GridItem as fixed, flexible, or adaptive.

Seeing the exact same thing Steepz described above. Load and scroll down fine, scroll back up and crash.

Same issue even with a LazyVGrid inside a regular VStack.

Same issue in iOS 16.3. Filed FB11800180 and in contact with DTS, who said that the the SwiftUI team has identified the underlying cause of the regression. But there is still no fix available. Very frustrating...

Is it still happening on iOS 16.5.1? I think this bug is not happening on any version > 16.3.1, as I can see in my app data.

I am having this issue on 2 physical ipads running ios 16.5.1c and 16.6 (crashing on launch). Strangely the error do not happen in my simulator running ios 16.4.

Having the same issue here. It's happening on iOS 17.1 on iPad and iPhone. Any work-arounds?

Facing the same issue on 17.1 :/

Experienced the same exact issue as Steepz where I had a LazyVGrid holding custom views which some happened to have an additional LazyVGrid. Couldn't find a workaround so I resorted to a UIViewRepresentable holding a CollectionView as it seems there aren't any workarounds at the moment.

Can reproduce this with Xcode Version 15.1 beta 3 (15C5059c) deploying to iPhone 14 Pro running iOS 17.1.1.

Make a test project with Apple's LazyVGrid sample code. Launch app in portrait, scroll to bottom, rotate to landscape, rotate to portrait, scroll to top, crash!

let columns = [GridItem(.flexible()), GridItem(.flexible())]

    var body: some View {
         ScrollView {
             LazyVGrid(columns: columns) {
                 ForEach(0x1f600...0x1f679, id: \.self) { value in
                     Text(String(format: "%x", value))
                     Text(emoji(value))
                         .font(.largeTitle)
                 }
             }
         }
    }


    private func emoji(_ value: Int) -> String {
        guard let scalar = UnicodeScalar(value) else { return "?" }
        return String(Character(scalar))
    }

id: \.self tut tut Apple sample code developer! (this is not the cause of this crash though).

Running into the same issue on my app when I scroll to the top with momentum scroll (the velocity needs to be really fast). It crashes when it reaches the top with the rubber band. It seems to only happen on iOS 17.1. Stack trace below

Looks like this might have been fixed in 17.2

for such uncorrected years! errors Apple must pay compensation for damages. I can’t imagine Toyota releasing a car for which:

  • go back
  • rotated 90 degrees
  • go forward

bam and the car fell apart

iOS 16.1 Crashes when scroll (LazyVStack and LazyVGrid)
 
 
Q