From 38c3a44bf9b81c28757108d12e7847e9a6f8faea Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Mon, 20 Sep 2021 16:03:02 +1000 Subject: [PATCH] FIX: return empty array when no parent for range (#14386) If parent element for range does not exists, range calculator should return empty array. In that case duration calculations will stop because of: ``` if (_rangeElements(element).length === 2) { opts.duration = _calculateDuration(element); } ``` --- .../javascripts/initializers/discourse-local-dates.js.es6 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js.es6 b/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js.es6 index 50d543c971e..dad88fbd251 100644 --- a/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js.es6 +++ b/plugins/discourse-local-dates/assets/javascripts/initializers/discourse-local-dates.js.es6 @@ -63,6 +63,9 @@ function buildOptionsFromElement(element, siteSettings) { } function _rangeElements(element) { + if (!element.parentElement) { + return []; + } return Array.from(element.parentElement.children).filter( (span) => span.dataset.date );