Skip to content

Refresh views from any Observable type, not just Skip-aware ones - #174

Draft
piercifani wants to merge 1 commit into
mainfrom
feature/body-observation-tracking
Draft

piercifani wants to merge 1 commit into
mainfrom
feature/body-observation-tracking

Conversation

@piercifani

@piercifani piercifani commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Today a Fuse view refreshes only when it reads a Skip-aware model: one whose @Observable expanded against Skip's bridged ObservationRegistrar. Types that use the stock Observation module never invalidate Compose. That covers models in modules without the Skip plugin, hand-written Observable conformances, and libraries built on Observable (swift-sharing, sqlite-data, and soon TCA). On Android those views silently go stale.

This change runs bridged view evaluation inside withObservationTracking, the same mechanism SwiftUI uses. Any Observable read refreshes the view on change, regardless of which registrar it uses.

  • Java_withBodyObservationTracking: called by skipstone-generated Swift_composableBody. It subscribes the current recompose scope through skip.model.trackBodyInvalidation() (one JNI call) and invalidates it from onChange, which may run on any thread.
  • Content that runs after body returns is wrapped too: lazy ForEach items, navigationDestination(for:), GeometryReader, ScrollViewReader, AsyncImage, and Binding.wrappedValue. The Binding wrap covers controls that read a binding only from Compose, such as a Toggle.
  • Nested evaluation is not re-tracked, because Observation merges inner accesses into the enclosing tracking.
  • BodyObservationTracking.isEnabled (default true) is an escape hatch.

Skip-aware models keep working unchanged: they now invalidate through both paths, which is harmless.

Cost: about 3.4 µs per tracked evaluation in a release build on a Pixel 10 Pro Fold. For comparison, a bridged property read is about 0.74 µs and Observation alone is about 1.35 µs.

Limitations:

  • Observation has no API to cancel a pending one-shot tracking. Registrations for properties that never change stay in the model's registrar (Swift memory only) until the property changes or the model deinits. Scrolling a 2,000-row lazy list showed no measurable heap growth; a synthetic 100k-evaluation loop did grow it. A cancellable tracking API in Observation would remove this.
  • withAnimation writes to non-Skip-aware models refresh the view but do not animate.

Tests: testStockObservableRefreshesViews covers the body, a lazy row, and a binding-only Toggle. testStockObservableIsStaleWithTrackingDisabled is the control.

Requires skip-model 1.9.0. Part of https://github.com/orgs/skiptools/discussions/755.

Related PRs (release in this order):

  1. Add body invalidation support for native observation tracking skip-model#33
  2. Refresh views from any Observable type, not just Skip-aware ones #174
  3. Evaluate bridged view bodies inside observation tracking skip#764

🤖 Generated with Claude Code

Evaluate bridged view bodies, and content evaluated after them (lazy ForEach
items, navigationDestination(for:), GeometryReader, ScrollViewReader,
AsyncImage and Binding reads from Compose), inside withObservationTracking.
Types on the stock Observation registrar, such as third-party models, now
refresh views on Android. BodyObservationTracking.isEnabled is an escape
hatch. Requires skip-model 1.9.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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