fix(maps): evitar carrera MapReady/DDP que dejaba el mapa en gris

En react-leaflet v4 la capa union no se dibujaba (mundo gris a zoom 0) en
/zones, /subscriptions y el bloque Participa cuando los datos DDP llegaban
despues de montar el mapa. Se anade reintento en componentDidUpdate y se
endurece la guarda, con flag de instancia para el ajuste de bounds.
This commit is contained in:
vjrj 2026-07-28 00:35:11 +02:00
parent 07993ffb91
commit c50690cc8a

View file

@ -43,6 +43,15 @@ class SubscriptionsMap extends React.Component {
this.handleMapReady = this.handleMapReady.bind(this);
}
// The `subs-public-union` doc (~2.2MB) usually arrives via DDP *after* the map
// is ready, so the one-shot MapReady draw runs with `userSubs` still null.
// Redraw the union (and fit bounds on first real data) whenever it changes.
componentDidUpdate(prevProps) {
if (this.map && this.props.userSubs && this.props.userSubs !== prevProps.userSubs) {
this.handleLeafletLoad(this.map);
}
}
getMap() {
return this.map;
}
@ -66,7 +75,7 @@ class SubscriptionsMap extends React.Component {
handleLeafletLoad(map) {
// console.log('Map loading');
if (map && this.props.userSubs !== 'null') {
if (map && this.props.userSubs && this.props.userSubs !== 'null') {
// console.log(`Union of ${this.props.userSubs}`);
this.state.union = subsUnion(this.state.union, {
map,
@ -74,8 +83,12 @@ class SubscriptionsMap extends React.Component {
bounds: this.props.userSubsBounds,
fromServer: true,
show: true,
fit: this.state.init
// Only auto-fit to the union the first time we draw it with real data
// (and never once the user has recentred), so later reactive updates
// don't steal the current view. `fitDone` is a plain instance flag.
fit: this.state.init && !this.fitDone
});
this.fitDone = true;
}
}