Skip to content

Commit 09de598

Browse files
committed
Revert "Fix addSource condition (#2524)"
This reverts commit 19e778b.
1 parent e83c9a6 commit 09de598

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import {useContext, useEffect, useMemo, useCallback, useState, useRef, cloneElement} from 'react';
2+
import {useContext, useEffect, useMemo, useState, useRef, cloneElement} from 'react';
33
import {MapContext} from './map';
44
import assert from '../utils/assert';
55
import {deepEqual} from '../utils/deep-equal';
@@ -83,16 +83,17 @@ export function Source(props: SourceProps) {
8383
const [, setStyleLoaded] = useState(0);
8484

8585
const id = useMemo(() => props.id || `jsx-source-${sourceCounter++}`, []);
86-
const forceUpdate = useCallback(() => setStyleLoaded(version => version + 1), []);
8786

8887
useEffect(() => {
8988
if (map) {
90-
// Fired on initial load signaling the map is ready to add custom sources
91-
// Subsequently fired on style changes
89+
/* global setTimeout */
90+
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)) {
@@ -124,20 +125,6 @@ export function Source(props: SourceProps) {
124125
}
125126
propsRef.current = props;
126127

127-
useEffect(() => {
128-
if (!source) {
129-
// on `styledata` event, `map.isStyleLoaded()` still returns false.
130-
// `load` and `style.load` only fire once and not when `isStyleLoaded` changes from true to false to true.
131-
// `sourcedata` potentially suggests that `isStyleLoaded` has changed. But it fires on every tile load.
132-
// Unsubscribe once source is added.
133-
map.on('sourcedata', forceUpdate);
134-
return () => {
135-
map.off('sourcedata', forceUpdate);
136-
};
137-
}
138-
return undefined;
139-
}, [map, source]);
140-
141128
return (
142129
(source &&
143130
React.Children.map(

0 commit comments

Comments
 (0)