Skip to content

fix: keep live markers on renderCluster switch - #238

Merged
jkasprzyk17 merged 2 commits into
mainfrom
fix/render-cluster-switch
Dec 6, 2026
Merged

jkasprzyk17 merged 2 commits into
mainfrom
fix/render-cluster-switch

Conversation

@jkasprzyk17

@jkasprzyk17 jkasprzyk17 commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

What does this change?

Fixes the two follow-ups from the review of #74 in #229. Both happen when renderCluster is turned on or off while the map is showing.

Closes #229

1. Live markers lose their state. The switch removed every marker and published an empty render state, so MapView unmounted every live MarkerView, including on-screen ones with clusterable={false}, and remounted them with fresh React state. Only clusters change hands between the SDK and JS. Now:

  • MarkerViewRenderRegistry.setCustomClusters (Kotlin and Swift) drops only its JSX clusters.
  • Each controller removes only its SDK clusters before reapplying. On MapKit that's the MapClusterAnnotations; on Google iOS, markers with a .cluster payload; on Android, clusterByKey (with their entering animations).

2. iOS: a queued refresh could add an annotation twice. MarkerRenderPipeline stored the displayed versions in each request when it was scheduled, and the index build replays the latest request (latestRefreshParameters). One ordering that adds everything twice:

  1. A compute block is already queued.
  2. The switch queues an index rebuild behind it, and the old index stays usable.
  3. A gesture refresh, with the post-clear (empty) snapshot, replaces the pending request. That block computes it and applies it.
  4. The build then replays that same empty snapshot.

applyDiff overwrites displayedAnnotations[key], so the first annotation stayed on the map. The pipeline now takes displayedVersions as a closure and reads it when each request is built, as Android already does. A clusteringEnabled switch could take the same path and is covered too.

I didn't add a guard in applyDiff against an existing key: with the snapshot fixed it can't happen, and a guard would hide the next bug of this kind.

How was it verified?

  • New JVM test switching renderCluster hands back only the JSX clusters: fails on main, passes here. All 235 Android unit tests pass, and :react-native-better-maps:assembleDebug builds.
  • Example-app check with a temporary harness (not committed): a clusterable={false} MarkerView showing a random id picked on mount, with renderCluster switched every 5 s on the Live JSX markers scenario.
    • Android, Google, emulator API 37: on main, the id changed on every switch (8812 → 8746 → 7025 → 9145 → …). On this branch it stayed 9212 for ~85 s. The emulator had a dummy Maps key, so the map never became ready and no clusters were on screen. On Android, the cluster hand-off is covered by the JVM test only.
    • iOS, Apple (MapKit), iPhone 18 Pro simulator, iOS 27.2, this branch only: the id stayed the same. Clusters switched between MapKit badges and the JSX bubbles (36 ↔ 0). The 46 live singles stayed on screen throughout.
  • iOS compiles with and without GOOGLE_MAPS_IOS_API_KEY. Google on iOS was not run.
  • Item 2 was not reproduced on a device. The fix comes from tracing the code.
  • bun run lint, bun run typecheck and bun run build pass.

Scope

  • Providers: both
  • Platforms: both (item 2 is iOS only)

Checklist

  • bun run lint, bun run typecheck and bun run build pass
  • Tests pass, and new behavior is covered by a test (the registry; the controllers and the iOS pipeline have no unit test path)
  • Nitro specs changed? No
  • Public API changed? No
  • Commits follow Conventional Commits
  • Behavior changed without a type change? Yes, intentionally: switching renderCluster no longer remounts live markers, and SDK markers no longer replay their entering animation on the switch.

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Switching renderCluster while the map was showing removed every marker
and published an empty render state, so MapView unmounted every live
MarkerView, including on-screen ones with clusterable={false}, and
remounted them with fresh React state.

Only clusters change hands between the SDK and JS. The registry now
drops just its JSX clusters, and each controller (Android, MapKit,
Google iOS) removes just its SDK clusters before reapplying, so markers
are not touched.
A refresh request carried the displayed versions from when it was
scheduled. The index build replays the latest request, so a gesture
refresh applied while the index was being rebuilt (after a
renderCluster or clusteringEnabled switch) was replayed against a
snapshot from before it, and every annotation it had added was added
again. applyDiff overwrote displayedAnnotations[key], leaving the first
annotation on the map.

The pipeline now takes the displayed versions as a closure and reads
them when each request is built, as Android already does.
@coderabbitai

coderabbitai Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Switching between custom and SDK cluster rendering now keeps regular map markers visible instead of clearing and rebuilding them unnecessarily.
    • Cluster views are cleared and redrawn using the selected rendering mode, while regular markers remain in place.

When cluster-rendering mode changes, the registries and map controllers remove cluster state while preserving regular markers. The iOS refresh pipeline now reads displayed marker versions when it runs and stores a snapshot for each viewport request.

Changes: Cluster Rendering Switch

Layer / File(s) Summary
Registry cluster handoff
package/android/src/main/java/com/margelo/nitro/nitromaps/MarkerViewRenderRegistry.kt, package/ios/MarkerViewRenderRegistry.swift, package/android/src/test/java/com/margelo/nitro/nitromaps/MarkerViewRenderRegistryTest.kt
Both registries remove live cluster entries when the setting changes and retain non-cluster entries. The Android test checks that the live marker remains published and that the next diff adds the cluster for SDK rendering.
Platform cluster cleanup
package/android/src/main/java/com/margelo/nitro/nitromaps/MapOverlayController.kt, package/ios/GoogleMapOverlayController.swift, package/ios/MapOverlayController.swift
The controllers remove displayed SDK clusters and their version entries when cluster-rendering ownership changes. They preserve regular markers and reapply markers.
iOS refresh version snapshots
package/ios/MarkerClusterEngine.swift, package/ios/GoogleMapOverlayController.swift, package/ios/MapOverlayController.swift
The iOS refresh pipeline receives displayed versions through closures. Viewport requests store a dictionary snapshot and use it for marker filtering and diff computation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: hubertmadrzejewski

Merge Risk: Minimal · up to 186ac

This change keeps live map markers mounted when the cluster renderer is switched, and it fixes the iOS refresh path so an annotation is not added twice. No concrete merge-blocking risk was found. The iOS and Android controller behavior has only been exercised in the JVM test and a simulator run.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title uses the conventional "fix:" type prefix and is under 50 characters. It names the main change: live markers keep their state when renderCluster switches. Under the configured requirements, t…
Description check Passed The description explains the problem, the fix on Kotlin, Swift, Google iOS, and Android, and the iOS queued-refresh duplicate-annotation issue. It also lists verification steps and scope. It is clearl…
Linked Issues check Passed [#229] Objective 1 (keep live singles mounted): Verified in source at the reviewed head. MarkerViewRenderRegistry.kt setCustomClusters(enabled) removes only ClusterElement.Cluster entries (entries.val…
Out of Scope Changes check Passed All changed areas map to #229. Android: MapOverlayController.kt, MarkerViewRenderRegistry.kt and its JVM test. iOS: MapOverlayController.swift, GoogleMapOverlayController.swift, MarkerClusterEngine.sw…
Security Check Passed PR #238 (gmi-software/react-native-better-maps, author jkasprzyk17) changes 7 files: Android and iOS marker-rendering code, plus one JVM test. I read the full committed diff from refs/coderabbit/pre-m…
Full details: Title check

Explanation

The title uses the conventional "fix:" type prefix and is under 50 characters. It names the main change: live markers keep their state when renderCluster switches. Under the configured requirements, the title meets the length and type-prefix criteria.

Full details: Description check

Explanation

The description explains the problem, the fix on Kotlin, Swift, Google iOS, and Android, and the iOS queued-refresh duplicate-annotation issue. It also lists verification steps and scope. It is clearly related to the changeset, so the lenient check passes.

Full details: Linked Issues check

Explanation

[#229] Objective 1 (keep live singles mounted): Verified in source at the reviewed head. MarkerViewRenderRegistry.kt setCustomClusters(enabled) removes only ClusterElement.Cluster entries (entries.values.removeAll { it is ClusterElement.Cluster }) and publishes only when something was removed. publish() still emits live Single markerIds, so live singles stay in the published set. The summary states the same for MapOverlayController.kt (clears only cluster markers and their animation/version state), MarkerViewRenderRegistry.swift, GoogleMapOverlayController.swift and MapOverlayController.swift (removes only displayed cluster annotations or cluster-marked payloads). The Android JVM test 'switching renderCluster hands back only the JSX clusters' covers the registry behavior. Objective 2 (iOS queued refresh adds annotation twice): The summary states that MarkerClusterEngine.swift RefreshParameters now holds displayedVersions as a closure, read when each ViewportRefreshRequest is built, and that the three MapOverlayController.swift refresh calls pass the closure. This removes the stale snapshot replay described in #229 (latestRefreshParameters). The Android path already reads versions this way, which the summary cites as the model. Limits: the iOS diffs could not be read (changed blobs unavailable to the diff operation), so the iOS controller and engine changes rest on the PR summary and not on source inspection. Item 2 is not reproduced on a device, as the issue and PR both state. No coding requirement is unmet on the available evidence.

Full details: Out of Scope Changes check

Explanation

All changed areas map to #229. Android: MapOverlayController.kt, MarkerViewRenderRegistry.kt and its JVM test. iOS: MapOverlayController.swift, GoogleMapOverlayController.swift, MarkerClusterEngine.swift and MarkerViewRenderRegistry.swift. Each change either removes only SDK or JSX cluster state (objective 1), or changes how displayedVersions is supplied to the iOS refresh pipeline (objective 2, including the clusteringEnabled path that the PR says shares that refresh path). The added test supports objective 1. No Nitro spec or public API change is reported. The summary lists no public declaration changes. No unrelated change was found in the summary. The source diffs could not be read, so this verdict relies on the summary's file list.

Full details: Security Check

Explanation

PR #238 (gmi-software/react-native-better-maps, author jkasprzyk17) changes 7 files: Android and iOS marker-rendering code, plus one JVM test. I read the full committed diff from refs/coderabbit/pre-merge-check/base to head (89 insertions, 40 deletions). The change set has no security-relevant surface: - No authentication, authorization, or permission logic is added or changed. - No external input is parsed or validated. The setCustomClusters/setCustomClusterViews flags are internal state toggles. - No network calls, URL or path handling, serialization, or deserialization. - No secrets, keys, tokens, or logging changes. The Google Maps API key is not touched. - No dependency or build-configuration changes. The iOS change converts displayedVersions from a captured dictionary into a closure. Each closure captures self weakly, so it adds no retain cycle and no new data exposure. The Android and iOS changes remove only cluster entries, and the diff shows no new access path that would expose markers or data to other components. The security criteria do not apply to this diff, and no medium, high, or critical finding meets the stated threshold. Assessment: PASS. Tone note: the configured tone asks for cruelty. I kept the report direct and skipped the cruelty. The verdict stands on the diff, not on tone.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 4f9e38cb-019a-4ecc-bcf1-9082580555ba
Commits

Reviewing files that changed from the base of the PR and between c6eb8ca and 186ac83.

Files selected for processing: 7

  • package/android/src/main/java/com/margelo/nitro/nitromaps/MapOverlayController.kt
  • package/android/src/main/java/com/margelo/nitro/nitromaps/MarkerViewRenderRegistry.kt
  • package/android/src/test/java/com/margelo/nitro/nitromaps/MarkerViewRenderRegistryTest.kt
  • package/ios/GoogleMapOverlayController.swift
  • package/ios/MapOverlayController.swift
  • package/ios/MarkerClusterEngine.swift
  • package/ios/MarkerViewRenderRegistry.swift

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 3 reviews per hour.

@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

React Doctor found 4 issues in 2 files · 1 error & 3 warnings · score 81 / 100 (Needs work) · full project

Errors

3 warnings

src/components/MapView.tsx

  • ⚠️ L109 React function has high control-flow complexity no-high-complexity-react-function
  • ⚠️ L109 Large component is hard to read and change no-giant-component

src/hooks/useCollectedOverlays.ts

  • ⚠️ L34 Ref initializer runs on every render rerender-lazy-ref-init

Reviewed by React Doctor for commit 186ac83. See inline comments for fixes.

@jkasprzyk17

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@jkasprzyk17
jkasprzyk17 merged commit 993e63a into main Dec 6, 2026
9 checks passed
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.

Switching renderCluster at runtime resets live markers

1 participant