Skip to content

Commit

Permalink
Merge pull request #5280 from HSLdevcom/fix-memory-errors
Browse files Browse the repository at this point in the history
Fix memory warnings on console
  • Loading branch information
vesameskanen authored Feb 24, 2025
2 parents 6511638 + d8b9234 commit d90e7fd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/component/map/ItineraryLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class ItineraryLine extends React.Component {
if (entranceCoordinates && !this.props.passive) {
objs.push(
<EntranceMarker
key={`entrance_${entranceCoordinates[0]}_${entranceCoordinates[1]}`}
position={{
lat: entranceCoordinates[0],
lon: entranceCoordinates[1],
Expand Down
6 changes: 6 additions & 0 deletions app/component/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,13 @@ export default class Map extends React.Component {
paddingBottomRight: [0, (window.innerHeight - 64) / 2],
};
}
this.mounted = false;
}

updateZoom = () => {
if (!this.mounted) {
return;
}
// eslint-disable-next-line no-underscore-dangle
const zoom = this.map?.leafletElement?._zoom || this.props.zoom || 16;
if (zoom !== this.state.zoom) {
Expand All @@ -139,6 +143,7 @@ export default class Map extends React.Component {
};

componentDidMount() {
this.mounted = true;
if (this.props.mapLayers.vehicles) {
startClient(this.context);
}
Expand Down Expand Up @@ -173,6 +178,7 @@ export default class Map extends React.Component {
}

componentWillUnmount() {
this.mounted = false;
const { client } = this.context.getStore('RealTimeInformationStore');
if (client) {
this.context.executeAction(stopRealTimeClient, client);
Expand Down
20 changes: 18 additions & 2 deletions app/component/map/MapWithTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,12 @@ class MapWithTrackingStateHandler extends React.Component {
settingsOpen: false,
};
this.naviProps = {};
this.mounted = false;
}

async componentDidMount() {
this.mounted = true;

if (!isBrowser) {
return;
}
Expand All @@ -129,18 +132,23 @@ class MapWithTrackingStateHandler extends React.Component {
}
}

componentWillUnmount() {
this.mounted = false;
}

// eslint-disable-next-line camelcase
UNSAFE_componentWillReceiveProps(newProps) {
if (
newProps.mapTracking !== undefined &&
newProps.mapTracking !== this.state.mapTracking
newProps.mapTracking !== this.state.mapTracking &&
this.mounted
) {
this.setState({ mapTracking: newProps.mapTracking });
}
}

setMapElementRef = element => {
if (element && this.mapElement !== element) {
if (element && this.mapElement !== element && this.mounted) {
this.mapElement = element;
if (this.props.mapRef) {
this.props.mapRef(element);
Expand Down Expand Up @@ -171,6 +179,10 @@ class MapWithTrackingStateHandler extends React.Component {
};

disableMapTracking = () => {
if (!this.mounted) {
return;
}

this.setState({
mapTracking: false,
});
Expand Down Expand Up @@ -233,6 +245,10 @@ class MapWithTrackingStateHandler extends React.Component {

// eslint-disable-next-line react/no-unused-class-component-methods
setBottomPadding = padding => {
if (!this.mounted) {
return;
}

this.map?.setBottomPadding(padding);
this.setState({ bottomPadding: padding });
};
Expand Down
1 change: 0 additions & 1 deletion app/component/map/tile-layer/TileLayerContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ class TileLayerContainer extends GridLayer {
);
}
}

return showPopup ? popup : null;
}
}
Expand Down

0 comments on commit d90e7fd

Please sign in to comment.