Skip to content

Add reload, keepsPreviousImage, failureView, and imageTransition to LazyImage - #1100

Open
kean wants to merge 4 commits into
mainfrom
feat/lazy-image-modifiers
Open

kean wants to merge 4 commits into
mainfrom
feat/lazy-image-modifiers

Conversation

@kean

@kean kean commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Adds reload(id:), keepsPreviousImage(_:), failureView(_:), and imageTransition(_:animation:onMemoryCacheHit:) to LazyImage, reload() to LazyImageState, and reload() and keepsPreviousImage to FetchImage. A retry no longer takes .id(UUID()), which throws away the view and its state.

Proof

  • LazyImageModifiersTests: 29 tests rendered through SwiftUI, including fail → state.reload() from failureView → image. With the modifiers stubbed as no-ops on main, 18 fail. All pass here
  • NukeUI passes on macOS (666), iOS 27 (676), and tvOS 27 (676), NukeExtensions on macOS (59). watchOS and visionOS build, snippets compile
  • A cell that uses none of this, against main: +0.17% instructions per 100 cells (132.21M → 132.44M, ranges overlap, plain Image control +0.04%), iOS 27 simulator, Release, 8 interleaved rounds. LazyImage<Image> goes from 136 to 144 bytes
  • Not covered: a real tap (the test calls state.reload()), and Xcode 26.x, which only CI has. Conflicts with Show memory cache hits in the first body of LazyImage #1093 in LazyImage.swift, and after both land onMemoryCacheHit: true has to skip the first-body lookup

kean added 4 commits November 2, 2026 19:19
…azyImage

ImageLoader had the first two, and the only way to retry from SwiftUI was
`.id(UUID())`, which throws away the view and its state. `LazyImageState/reload()`
does it from inside of the content, and `reload(id:)` from outside.

`failureView(_:)` and `imageTransition(_:animation:onMemoryCacheHit:)` wrap the
content and return `LazyImage<some View>` instead of adding a branch to `body`,
so a view that doesn't use them pays nothing for them. For the same reason,
what `LazyImage` has to remember goes in `ImageLoader`, not in `FetchImage`.
SwiftUI doesn't interpolate a custom transition then, which is the state of
the macOS CI runner, so the tests counting its modifier never saw it run.
Also removes the temporary diagnostic that found this.
@kean
kean force-pushed the feat/lazy-image-modifiers branch from 8e0bbc9 to 56d6805 Compare November 3, 2026 00:51
@kean kean added this to the 14.1.0 milestone Nov 8, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant