From 5f6a6a025a3029a59b220c3f5556e67a646e7096 Mon Sep 17 00:00:00 2001 From: marination Date: Fri, 19 May 2023 16:56:54 +0530 Subject: [PATCH] fix: Load map libraries at build time to avoid async issues during geolocation render - When gelocation control is built, it awaits loading of libraries - Withi the control everything is await but a layer above where multiple controls are sequentially built this breaks - Form render goes ahead without waiting for the gelocation control - The `onload_post_render` in `Location` cannot find the map wrapper as the control is still being built - Therefore, on a hard load, the control does not show up and appears on soft reload. --- .../public/js/frappe/form/controls/geolocation.js | 14 -------------- .../lib/leaflet_control_locate/L.Control.Locate.js | 2 +- frappe/public/js/libs.bundle.js | 4 ++++ frappe/public/scss/desk.bundle.scss | 5 +++++ 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/frappe/public/js/frappe/form/controls/geolocation.js b/frappe/public/js/frappe/form/controls/geolocation.js index 42534a3c39..aa75a2282b 100644 --- a/frappe/public/js/frappe/form/controls/geolocation.js +++ b/frappe/public/js/frappe/form/controls/geolocation.js @@ -4,7 +4,6 @@ frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.f static horizontal = false; async make() { - await frappe.require(this.required_libs); super.make(); } @@ -216,17 +215,4 @@ frappe.ui.form.ControlGeolocation = class ControlGeolocation extends frappe.ui.f this.editableLayers.removeLayer(l); }); } - - get required_libs() { - return [ - "assets/frappe/js/lib/leaflet_easy_button/easy-button.css", - "assets/frappe/js/lib/leaflet_control_locate/L.Control.Locate.css", - "assets/frappe/js/lib/leaflet_draw/leaflet.draw.css", - "assets/frappe/js/lib/leaflet/leaflet.css", - "assets/frappe/js/lib/leaflet/leaflet.js", - "assets/frappe/js/lib/leaflet_easy_button/easy-button.js", - "assets/frappe/js/lib/leaflet_draw/leaflet.draw.js", - "assets/frappe/js/lib/leaflet_control_locate/L.Control.Locate.js", - ]; - } }; diff --git a/frappe/public/js/lib/leaflet_control_locate/L.Control.Locate.js b/frappe/public/js/lib/leaflet_control_locate/L.Control.Locate.js index 8544e17a04..8ea44ce00c 100644 --- a/frappe/public/js/lib/leaflet_control_locate/L.Control.Locate.js +++ b/frappe/public/js/lib/leaflet_control_locate/L.Control.Locate.js @@ -17,7 +17,7 @@ You can find the project at: https://github.com/domoritz/leaflet-locatecontrol if (typeof window !== 'undefined' && window.L) { module.exports = factory(L); } else { - module.exports = factory(require('leaflet')); + module.exports = factory(require('../leaflet/leaflet.js')); } } diff --git a/frappe/public/js/libs.bundle.js b/frappe/public/js/libs.bundle.js index e4e172c1b4..77704bb173 100644 --- a/frappe/public/js/libs.bundle.js +++ b/frappe/public/js/libs.bundle.js @@ -1,5 +1,9 @@ import "./jquery-bootstrap"; import "./lib/moment"; +import "../js/lib/leaflet/leaflet.js"; +import "../js/lib/leaflet_easy_button/easy-button.js"; +import "../js/lib/leaflet_draw/leaflet.draw.js"; +import "../js/lib/leaflet_control_locate/L.Control.Locate.js"; import Sortable from "sortablejs"; window.SetVueGlobals = (app) => { diff --git a/frappe/public/scss/desk.bundle.scss b/frappe/public/scss/desk.bundle.scss index 10fd116d6c..6b192bb3ff 100644 --- a/frappe/public/scss/desk.bundle.scss +++ b/frappe/public/scss/desk.bundle.scss @@ -4,3 +4,8 @@ @import "~frappe-charts/dist/frappe-charts.min"; @import "~plyr/dist/plyr"; @import "./desk/index"; + +@import "frappe/public/js/lib/leaflet/leaflet.css"; +@import "frappe/public/js/lib/leaflet_easy_button/easy-button.css"; +@import "frappe/public/js/lib/leaflet_control_locate/L.Control.Locate.css"; +@import "frappe/public/js/lib/leaflet_draw/leaflet.draw.css"; \ No newline at end of file