Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

[Android] safeAddFeature overwrites existing features on indexed insertion

Ouverte Adaptée aux débutants
#5,977 2 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
72/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
android, react-native
Domaine
mobile

Piste de recherche

Commencez par localiser safeAddFeature et les chemins qui mettent à jour features et savedFeatures ; comparez-les à removeFeatureAt pour vérifier la gestion de l’ordre indexé. Reproduisez le Android New Architecture sample, puis confirmez que le fait de préfixer C et de réduire à B ne laisse que B visible et maintient les deux collections alignées.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Summary

On Android, dynamically inserting a map child anywhere except the end can desynchronise MapView.features from the React child list. A later removal can remove the wrong Google Maps feature and leave the intended feature orphaned on the map.

safeAddFeature, introduced by #5795, currently pads the list and calls features.set(index, mapFeature). When index < features.size(), set overwrites the existing entry instead of inserting and shifting it. The native feature that was overwritten remains on the Google map, but MapView.features no longer contains the reference needed to remove it. This is inconsistent with removeFeatureAt, which uses features.remove(index) and therefore shifts later entries.

The same issue exists in the paused path for savedFeatures.

Reproducible sample code
import React from "react"
import { Button, View } from "react-native"
import MapView, { Marker, PROVIDER_GOOGLE } from "react-native-maps"

const markers = {
  a: { latitude: 13.69, longitude: -89.22 },
  b: { latitude: 13.70, longitude: -89.21 },
  c: { latitude: 13.71, longitude: -89.20 },
}

const phases = [
  ["a", "b"],
  ["c", "a", "b"],
  ["b"],
] as const

export default function App() {
  const [phase, setPhase] = React.useState(0)

  return (
    <View style={{ flex: 1 }}>
      <MapView
        provider={PROVIDER_GOOGLE}
        style={{ flex: 1 }}
        initialRegion={{
          latitude: 13.70,
          longitude: -89.21,
          latitudeDelta: 0.05,
          longitudeDelta: 0.05,
        }}
      >
        {phases[phase].map((id) => (
          <Marker key={id} coordinate={markers[id]} title={id.toUpperCase()} />
        ))}
      </MapView>
      <Button
        title="Next marker set"
        onPress={() => setPhase((current) => Math.min(current + 1, 2))}
      />
    </View>
  )
}
Steps to reproduce
  1. Run the sample on Android with the New Architecture enabled.
  2. Confirm markers A and B are initially visible.
  3. Press Next marker set once. This prepends C before the existing children.
  4. Press Next marker set again. The declared child list now contains only B.
  5. Observe the markers without moving the camera.
Expected result

The native feature list stays aligned with the React children. After the second press, only marker B is visible.

Actual result

Inserting C at index 0 overwrites the feature reference for A in features instead of shifting it. Subsequent removals operate on the corrupted list: the wrong marker can be removed and an old marker can remain visible with no entry left in features to remove it later.

React Native Maps Version

1.27.2

What platforms are you seeing the problem on?

Android

React Native Version

0.85.3

What version of Expo are you using?

Not using Expo

Device(s)

Android emulator

Additional information

The collection overwrite mechanism was previously observed in this comment on #5750. The safeAddFeature helper was later introduced by #5795 to handle out-of-order additions after detach/attach, but its use of set makes that overwrite behavior apply to every non-tail insertion.

The corresponding fix is to pad only while size() < index, then use add(index, mapFeature) for both features and savedFeatures. This makes insertion shift entries in the same way that indexed removal shifts them back.

Langage dominant
TypeScript
Étoiles
16k
Forks
5k
Merge moyen
1 j 2 h
PR mergées (30 j)
3

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de react-native-maps/react-native-maps

Toutes les issues de react-native-maps/react-native-maps

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.