From 2c04b2015b2e627d3996686513043ac04aa14ad6 Mon Sep 17 00:00:00 2001 From: Taylor Aanenson Date: Mon, 27 Jul 2026 11:31:29 -0500 Subject: [PATCH] Refresh the FlowLink tap closure in updateUIView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GestureContainer's coordinator is created once and reused, and updateUIView was empty, so the UIButton kept invoking the first onTap it was ever handed. That closure captured the FlowLink struct from its first body evaluation — including `value` and `label` — so a link whose content is refreshed in place kept pushing the value it had at first render and snapshotting the label it had at first render, however many times SwiftUI re-rendered it. Two visible symptoms in an app that renders a disk cache and then swaps in a fetched payload under the same identity: taps open the cached copy of a row for the rest of the session, and the transition snapshot shows numbers the card no longer displays. retakeSnapshots can't help with the latter — it faithfully re-renders the stale label. --- Sources/FlowStack/FlowLink.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/FlowStack/FlowLink.swift b/Sources/FlowStack/FlowLink.swift index 838173d..b975fa4 100644 --- a/Sources/FlowStack/FlowLink.swift +++ b/Sources/FlowStack/FlowLink.swift @@ -103,7 +103,17 @@ struct GestureContainer: UIViewRepresentable { return button } - func updateUIView(_ uiView: UIViewType, context: Context) { } + func updateUIView(_ uiView: UIViewType, context: Context) { + // The coordinator is made once and reused for the life of the + // representable, so without this the button keeps calling the very + // first onTap it was given — and that closure captured the FlowLink + // as it was on its first render, including its `value` and its + // `label`. A link whose row is refreshed in place (a cached list + // replaced by a fetched one, a count that moves) then pushes the + // stale value and snapshots the stale label, no matter how many + // times SwiftUI re-renders it. + context.coordinator.onTap = onTap + } func makeCoordinator() -> Coordinator { Coordinator(isPressed: $isPressed, onTap: onTap)