Skip to content

Commit 92350dd

Browse files
authored
Fix Leaflet SSR bug (#2501)
1 parent 278e47a commit 92350dd

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

packages/vue/src/components/organisms/SfStoreLocator/SfStoreLocator.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ import { focus } from "../../../utilities/directives";
6969
import SfIcon from "../../atoms/SfIcon/SfIcon.vue";
7070
import SfLoader from "../../atoms/SfLoader/SfLoader.vue";
7171
import SfStore from "./_internal/SfStore.vue";
72-
import { Icon } from "leaflet";
73-
delete Icon.Default.prototype._getIconUrl;
74-
Icon.Default.mergeOptions({
75-
iconRetinaUrl: require("leaflet/dist/images/marker-icon-2x.png"),
76-
iconUrl: require("leaflet/dist/images/marker-icon.png"),
77-
shadowUrl: require("leaflet/dist/images/marker-shadow.png"),
78-
});
7972
8073
Vue.component("SfStore", SfStore);
8174
export default {
@@ -178,7 +171,16 @@ export default {
178171
},
179172
},
180173
},
181-
mounted() {
174+
async mounted() {
175+
// Fix lack of marker icons
176+
const { Icon } = await import('leaflet');
177+
delete Icon.Default.prototype._getIconUrl;
178+
Icon.Default.mergeOptions({
179+
iconRetinaUrl: require("leaflet/dist/images/marker-icon-2x.png"),
180+
iconUrl: require("leaflet/dist/images/marker-icon.png"),
181+
shadowUrl: require("leaflet/dist/images/marker-shadow.png"),
182+
});
183+
182184
import("leaflet/dist/leaflet.css");
183185
import("vue2-leaflet").then(
184186
({ LMap, LTileLayer, LMarker, LIcon, LControl, LControlZoom }) => {

0 commit comments

Comments
 (0)