Skip to content

fix: prevent ComposeUiClusterRenderer crash on fast back gesture with compose-ui 1.10+#930

Draft
kikoso wants to merge 1 commit into
mainfrom
fix/cluster-renderer-compose-lifecycle-crash
Draft

fix: prevent ComposeUiClusterRenderer crash on fast back gesture with compose-ui 1.10+#930
kikoso wants to merge 1 commit into
mainfrom
fix/cluster-renderer-compose-lifecycle-crash

Conversation

@kikoso

@kikoso kikoso commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Fixes #875

Summary

  • DefaultClusterRenderer's MarkerModifier uses an Android Handler queue that continues processing render tasks after the Compose scope is cancelled (e.g. fast back gesture). When a new ComposeView is created at that point, it attempts composition using an already-disposed CompositionContext, triggering the crash.
  • The ViewTreeLifecycleOwner fix shipped in v8.3.0 addressed the static case (no lifecycle owner on detached views) but not this dynamic teardown case.

Changes

  • Add scope.isActive guard at the top of getDescriptorForCluster and onBeforeClusterItemRendered. When the coroutine scope is cancelled, these methods fall through to the default super implementation (standard Google Maps rendering) instead of creating new off-screen ComposeViews with a stale/disposed CompositionContext.
  • Add ViewTreeSavedStateRegistryOwner alongside the existing ViewTreeLifecycleOwner on off-screen views, providing full compose-ui 1.10+ compatibility for cluster content that uses rememberSaveable or other saved-state APIs.

Test plan

  • Navigate to a map screen with Clustering() using custom clusterContent/clusterItemContent and many markers (so MarkerModifier is still actively rendering)
  • Immediately perform a fast back gesture (predictive back or physical back key)
  • Confirm no crash occurs — map falls back to default cluster rendering during the transition
  • Confirm normal clustering still works as expected when staying on the screen

… compose-ui 1.10+

Addresses issue #875: IllegalStateException "Composed into the View which
doesn't propagate ViewTreeLifecycleOwner!" when navigating back while
DefaultClusterRenderer's MarkerModifier handler is still processing.

- Add scope.isActive guards in getDescriptorForCluster and
  onBeforeClusterItemRendered so that after the Compose scope is
  cancelled (e.g. on back navigation), render callbacks fall through to
  the default super implementation instead of attempting to create new
  ComposeViews with a disposed CompositionContext.
- Set ViewTreeSavedStateRegistryOwner alongside ViewTreeLifecycleOwner on
  off-screen views for full compose-ui 1.10+ compatibility.
@googlemaps-bot

Copy link
Copy Markdown
Contributor

Code Coverage

Overall Project 24.82%

There is no coverage information present for the Files changed

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

Labels

None yet

Projects

None yet

2 participants