mirror of
https://github.com/maputnik/editor.git
synced 2026-12-05 16:24:20 +00:00
Fix shouldComponentUpdate blocking state updates
1. shouldComponentUpdate compares state fields by reference instead of JSON.stringify, which threw on the MapLibre Map in state and blocked every state update 2. The skipped update after style.load left the map on the initial empty style until a prop changed, e.g. by moving the map 3. Remove the setStyle call on style.load added earlier in this PR 4. zoom is excluded from the comparison: it is set on every zoom frame but only read when a layer popup opens, and React keeps this.state.zoom current without a re-render 5. Including zoom would run componentDidUpdate (a setStyle diff) on every zoom frame: 69 instead of 3 calls in a short zoom test 6. Risk: future code reading state.zoom in render or componentDidUpdate will not refresh on zoom Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WDkBFXcoMv8K4QSHA6P3Fg
This commit is contained in:
1 file changed
+1
-2
@@ -107,7 +107,7 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
|
||||
shouldComponentUpdate(nextProps: MapMaplibreGlInternalProps, nextState: MapMaplibreGlState) {
|
||||
let should = false;
|
||||
try {
|
||||
should = JSON.stringify(this.props) !== JSON.stringify(nextProps) || JSON.stringify(this.state) !== JSON.stringify(nextState);
|
||||
should = JSON.stringify(this.props) !== JSON.stringify(nextProps) || (Object.keys(nextState) as (keyof MapMaplibreGlState)[]).some(key => key !== "zoom" && this.state[key] !== nextState[key]);
|
||||
} catch(_e) {
|
||||
// no biggie, carry on
|
||||
}
|
||||
@@ -236,7 +236,6 @@ class MapMaplibreGlInternal extends React.Component<MapMaplibreGlInternalProps,
|
||||
zoomControl,
|
||||
zoom: map.getZoom()
|
||||
});
|
||||
map.setStyle(this.props.replaceAccessTokens(this.props.mapStyle), {diff: true});
|
||||
});
|
||||
|
||||
map.on("data", e => {
|
||||
|
||||
Reference in new issue
Block a user