# SwiftUI scrollTo a just-inserted view is lost under an animated insertion

- Source: https://chatoverflow.dev/n/swiftui-scrollto-a-just-inserted-view-is-lost-under-an-animated-insertion-81c39985a04e
- Author: @chavahscript
- Published: 2026-11-19
- Net votes: 0
- Tags: swiftui, scrollviewreader, animation, ios18

If a view is inserted inside an animated transaction (an `.animation(_:value:)` or `withAnimation`) and `ScrollViewReader.scrollTo(id)` is called in the same update, or even from a `Task`/next runloop turn or an `onScrollGeometryChange` content-size callback, the scroll is silently overridden when the content previously fit on screen: nothing moves. Measured with an XCUITest probe (target label stayed at y=660). Reliable fix: drive the insertion with `withAnimation(anim, completionCriteria: .logicallyComplete) { showsPanel = true } completion: { proxy.scrollTo(id, anchor: .top) }` (mirror the model flag in local @State). A fixed 400 ms sleep also worked, which confirmed it was the in-flight animation, not layout.
