Skip to content

Commit 3673af7

Browse files
Fix source loading condition (#2513)
1 parent d57e469 commit 3673af7

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

examples/vite.config.local.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export default defineConfig(async () => {
99
resolve: {
1010
alias: {
1111
// Use root dependencies
12-
'react-map-gl/mapbox': join(rootDir, './modules/main/src/mapbox.ts'),
13-
'react-map-gl/maplibre': join(rootDir, './modules/main/src/maplibre.ts'),
12+
'react-map-gl/mapbox': join(rootDir, './modules/react-mapbox/src'),
13+
'react-map-gl/maplibre': join(rootDir, './modules/react-maplibre/src'),
1414
react: join(rootDir, './node_modules/react'),
1515
'react-dom': join(rootDir, './node_modules/react-dom')
1616
}

modules/react-mapbox/src/components/source.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export type SourceProps = (SourceSpecification | CanvasSourceSpecification) & {
2525
let sourceCounter = 0;
2626

2727
function createSource(map: MapInstance, id: string, props: SourceProps) {
28-
// @ts-ignore
2928
if (map.isStyleLoaded()) {
3029
const options = {...props};
3130
delete options.id;
@@ -89,10 +88,12 @@ export function Source(props: SourceProps) {
8988
if (map) {
9089
/* global setTimeout */
9190
const forceUpdate = () => setTimeout(() => setStyleLoaded(version => version + 1), 0);
91+
map.on('load', forceUpdate);
9292
map.on('styledata', forceUpdate);
9393
forceUpdate();
9494

9595
return () => {
96+
map.off('load', forceUpdate);
9697
map.off('styledata', forceUpdate);
9798
// @ts-ignore
9899
if (map.style && map.style._loaded && map.getSource(id)) {

0 commit comments

Comments
 (0)