From dfffb2570420cab7021cf1b2a09c629d818af49d Mon Sep 17 00:00:00 2001 From: marination Date: Wed, 2 Feb 2022 10:16:31 +0530 Subject: [PATCH 1/3] fix: Import moment in datetime js for web portal - moment is imported via libs.bundle.js which is used in desk views - frappe's web bundle does not contain moment due to which, `undefined moment` breaks loading other js assets - for some odd reason, importing moment in the web bundle does not work, so this is a temporary fix for that --- frappe/public/js/frappe/utils/datetime.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frappe/public/js/frappe/utils/datetime.js b/frappe/public/js/frappe/utils/datetime.js index 196bdf68a3..beffa11331 100644 --- a/frappe/public/js/frappe/utils/datetime.js +++ b/frappe/public/js/frappe/utils/datetime.js @@ -1,6 +1,8 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // MIT License. See license.txt +import moment from "moment/min/moment-with-locales.js"; + frappe.provide('frappe.datetime'); frappe.defaultDateFormat = "YYYY-MM-DD"; From 3f6eb5d99db8669118d6a5e4f79ed223f6f29e63 Mon Sep 17 00:00:00 2001 From: marination Date: Wed, 2 Feb 2022 20:30:13 +0530 Subject: [PATCH 2/3] fix: Load `moment` and bind to window from new file - Introduce new file in `/lib` to import moment and bind to window - Use new lib file to load moment in web bundle and libs bundle (desk) Co-authored-by: Suraj Shetty --- frappe/public/js/frappe-web.bundle.js | 1 + frappe/public/js/frappe/utils/datetime.js | 2 -- frappe/public/js/lib/moment.js | 5 +++++ frappe/public/js/libs.bundle.js | 5 +---- 4 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 frappe/public/js/lib/moment.js diff --git a/frappe/public/js/frappe-web.bundle.js b/frappe/public/js/frappe-web.bundle.js index c962457964..b8d4006090 100644 --- a/frappe/public/js/frappe-web.bundle.js +++ b/frappe/public/js/frappe-web.bundle.js @@ -2,6 +2,7 @@ import "./jquery-bootstrap"; import "./frappe/class.js"; import "./frappe/polyfill.js"; import "./lib/md5.min.js"; +import "./lib/moment.js"; import "./frappe/provide.js"; import "./frappe/format.js"; import "./frappe/utils/number_format.js"; diff --git a/frappe/public/js/frappe/utils/datetime.js b/frappe/public/js/frappe/utils/datetime.js index beffa11331..196bdf68a3 100644 --- a/frappe/public/js/frappe/utils/datetime.js +++ b/frappe/public/js/frappe/utils/datetime.js @@ -1,8 +1,6 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // MIT License. See license.txt -import moment from "moment/min/moment-with-locales.js"; - frappe.provide('frappe.datetime'); frappe.defaultDateFormat = "YYYY-MM-DD"; diff --git a/frappe/public/js/lib/moment.js b/frappe/public/js/lib/moment.js new file mode 100644 index 0000000000..7a817a36cd --- /dev/null +++ b/frappe/public/js/lib/moment.js @@ -0,0 +1,5 @@ +// This file is used to make sure that `moment` is bound to the window +// before the bundle finishes loading, due to imports (datetime.js) in the bundle +// that depend on `moment`. +import momentTimezone from "moment-timezone/builds/moment-timezone-with-data.js"; +window.moment = momentTimezone; diff --git a/frappe/public/js/libs.bundle.js b/frappe/public/js/libs.bundle.js index 876d76875b..b71cc592a0 100644 --- a/frappe/public/js/libs.bundle.js +++ b/frappe/public/js/libs.bundle.js @@ -1,15 +1,12 @@ import "./jquery-bootstrap"; import Vue from "vue/dist/vue.esm.js"; -import moment from "moment/min/moment-with-locales.js"; -import momentTimezone from "moment-timezone/builds/moment-timezone-with-data.js"; +import "./lib/moment"; import io from "socket.io-client/dist/socket.io.slim.js"; import Sortable from "./lib/Sortable.min.js"; // TODO: esbuild // Don't think jquery.hotkeys is being used anywhere. Will remove this after being sure. // import "./lib/jquery/jquery.hotkeys.js"; -window.moment = moment; -window.moment = momentTimezone; window.Vue = Vue; window.Sortable = Sortable; window.io = io; From ab5f45a96fe5f6ae95a76b81831d61838aa2e267 Mon Sep 17 00:00:00 2001 From: marination Date: Thu, 3 Feb 2022 11:31:18 +0530 Subject: [PATCH 3/3] chore: Add `moment` to bundle instead of injection via script tag - Wherever moment is imported in html, use dependent bundle to import it instead for consistency - Remove moment import from `base.html` since it uses `frappe-web.bundle.js` anyway --- frappe/public/js/web_form.bundle.js | 1 + frappe/templates/base.html | 2 -- .../website/doctype/web_form/templates/web_form.html | 10 ++-------- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/frappe/public/js/web_form.bundle.js b/frappe/public/js/web_form.bundle.js index 01969a489c..ffb7b824bd 100644 --- a/frappe/public/js/web_form.bundle.js +++ b/frappe/public/js/web_form.bundle.js @@ -1,2 +1,3 @@ +import "./lib/moment.js"; import "./frappe/utils/datetime.js"; import "./frappe/web_form/webform_script.js"; diff --git a/frappe/templates/base.html b/frappe/templates/base.html index bc1f802cf7..8d892b5de6 100644 --- a/frappe/templates/base.html +++ b/frappe/templates/base.html @@ -105,8 +105,6 @@ // for backward compatibility of some libs frappe.sys_defaults = frappe.boot.sysdefaults; - - {{ include_script('frappe-web.bundle.js') }} {% endblock %} diff --git a/frappe/website/doctype/web_form/templates/web_form.html b/frappe/website/doctype/web_form/templates/web_form.html index a8666b55e9..72cdf07c59 100644 --- a/frappe/website/doctype/web_form/templates/web_form.html +++ b/frappe/website/doctype/web_form/templates/web_form.html @@ -92,18 +92,12 @@ $(".file-size").each(function() { }); {{ include_script("controls.bundle.js") }} -{% if is_list %} -{# web form list #} - - +{% if is_list %} {{ include_script("dialog.bundle.js") }} {{ include_script("web_form.bundle.js") }} {{ include_script("bootstrap-4-web.bundle.js") }} -{% else %} -{# web form #} +{% else %} {{ include_script("dialog.bundle.js") }} - -