Skip to content

Commit

Permalink
Fix a little annoyance with hot module reloading (#351)
Browse files Browse the repository at this point in the history
Hey,

Thank you for this package! I'm using it with react-leaflet for a remix-run app.

I consistently have an issue when editing code, and hot module reload happens. It seems that somehow the map instance gets destroyed before the _unload() event handler runs, hence this patch.

Let me know if you think there's a better way to do it.
  • Loading branch information
machour authored May 24, 2024
1 parent 419a29e commit a4b6cc2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/L.Control.Locate.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,10 @@ You can find the project at: https://github.com/domoritz/leaflet-locatecontrol
*/
_unload() {
this.stop();
this._map.off("unload", this._unload, this);
// May become undefined during HMR
if (this._map) {
this._map.off("unload", this._unload, this);
}
},

/**
Expand Down

0 comments on commit a4b6cc2

Please sign in to comment.