Skip to content

fix: don't create a fallback map when a map-view factory has no map - #4419

Merged
mfazekas merged 1 commit into
mainfrom
fix/external-map-no-fallback
Oct 27, 2026
Merged

mfazekas merged 1 commit into
mainfrom
fix/external-map-no-fallback

Conversation

@mfazekas

Copy link
Copy Markdown
Contributor

Description

When mapViewImpl names a registered map-view factory (iOS) or external-map factory (Android) and it returns nil/null, for example for a stale car map id after the car map was replaced, RNMBXMapView used to fall back to creating its own full MapView. <CarMap>'s children then went into an invisible map that loaded the default style and fired events. Now the view stays empty: it logs one warning, children aren't added, props aren't applied, and MapView commands reject with "The MapView has no map". Remounting (e.g. with the new id) creates the map again.

Normal MapViews are unaffected, and so is an Android Factory returning null, which still falls back as before. iOS has only one factory kind, so there the rule applies to any registered factory that returns nil; an unregistered mapViewImpl still falls back with the existing error log.

This is SPI-only. It came up in the review of rnmapbox/navigation#17, whose RNMBXNavigationCarMap.kt already assumes this behavior. It's intended for 10.3.16.

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder
  • I have tested the new feature on /example app.
    • In V11 mode/ios
    • In New Architecture mode/ios (example build only)
    • In V11 mode/android
    • In New Architecture mode/android (emulator)
  • I added/updated a sample - if a new feature was implemented (/example)

Screenshot OR Video

On the Android emulator, with the reproducer below:

  1. Unfixed: the nullext:1 RNMBXMapView gets its own com.mapbox.maps.MapView, renders the default style and the red circle, and fires onDidFinishLoadingStyle ("stale external style loads: 1").
  2. Fixed: that RNMBXMapView has no child MapView (checked with dumpsys activity top) and stays empty, with "stale external style loads: 0" and the warning The nullext:1 factory has no map for this MapView, it stays empty. The normal map above it still renders.

There are no unit tests: the Android JVM tests can't construct an RNMBXMapView, and iOS has no native test target. yarn lint, yarn type:check, yarn unittest and yarn generate are clean; the example builds with assembleDebug and for the generic iOS simulator.

Component to reproduce the issue you're fixing

Register a factory that returns null in MainApplication.onCreate():

com.rnmapbox.rnmbx.components.mapview.RNMBXMapViewFactory.registerExternalMap("nullext") { _, _ -> null }

Then render:

import { useState } from 'react';
import { Text, View } from 'react-native';
import Mapbox from '@rnmapbox/maps';

const shape = {
  type: 'Feature',
  geometry: { type: 'Point', coordinates: [19.04, 47.5] },
  properties: {},
};

export default function NoFallbackRepro() {
  const [normalStyleLoads, setNormalStyleLoads] = useState(0);
  const [externalStyleLoads, setExternalStyleLoads] = useState(0);
  return (
    <View style={{ flex: 1, paddingTop: 40 }}>
      <Text>
        normal style loads: {normalStyleLoads} | stale external style loads: {externalStyleLoads}
      </Text>
      <Mapbox.MapView style={{ flex: 1 }} onDidFinishLoadingStyle={() => setNormalStyleLoads((n) => n + 1)}>
        <Mapbox.Camera zoomLevel={4} centerCoordinate={[19.04, 47.5]} />
      </Mapbox.MapView>
      <Text>below: mapViewImpl="nullext:1" (factory returns null)</Text>
      <View style={{ flex: 1, backgroundColor: '#fdd' }}>
        <Mapbox.MapView
          mapViewImpl="nullext:1"
          style={{ flex: 1 }}
          onDidFinishLoadingStyle={() => setExternalStyleLoads((n) => n + 1)}
        >
          <Mapbox.Camera zoomLevel={4} centerCoordinate={[19.04, 47.5]} />
          <Mapbox.ShapeSource id="pt" shape={shape}>
            <Mapbox.CircleLayer id="pt-circle" style={{ circleRadius: 20, circleColor: 'red' }} />
          </Mapbox.ShapeSource>
        </Mapbox.MapView>
      </View>
    </View>
  );
}

When the factory named by mapViewImpl returns nil/null (e.g. a stale car map
id), RNMBXMapView stays empty instead of creating its own MapView; its
children and commands become no-ops.
@mfazekas
mfazekas merged commit 6db5f59 into main Oct 27, 2026
10 checks passed
@mfazekas
mfazekas deleted the fix/external-map-no-fallback branch October 27, 2026 15:28

This branch was previously deployed

1 inactive deployment
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