Skip to content

Commit f2abe70

Browse files
fix: re-register dayjs plugins in start to prevent cross-module conflicts
Move dayjs plugin initialization into `start()` and re-extend all loaded `dayjs_plugin_*` plugins after module scripts are loaded. This makes CalendarExt2 resilient when another module overwrites the global dayjs instance, and removes the now-redundant `lib/dayjs-init.js`.
1 parent 3b2befd commit f2abe70

2 files changed

Lines changed: 8 additions & 41 deletions

File tree

MMM-CalendarExt2.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-eval */
2-
/* global Module Scene config */
2+
/* global Module Scene config dayjs */
33

44
Module.register("MMM-CalendarExt2", {
55
predefined: {
@@ -247,7 +247,6 @@ Module.register("MMM-CalendarExt2", {
247247
}
248248

249249
scripts.push(
250-
this.file("lib/dayjs-init.js"),
251250
"CALEXT2_Scene.js",
252251
"CALEXT2_View.js",
253252
"CALEXT2_Event.js",
@@ -281,6 +280,13 @@ Module.register("MMM-CalendarExt2", {
281280
},
282281

283282
start () {
283+
// Re-register all dayjs plugins after all module scripts are loaded to
284+
// prevent other modules from overwriting the global dayjs object.
285+
for (const key of Object.keys(window)) {
286+
if (key.startsWith("dayjs_plugin_")) dayjs.extend(window[key]);
287+
}
288+
if (config.language) dayjs.locale(config.language.toLowerCase());
289+
284290
this.rotateTimer = null;
285291
this.updateTimer = null;
286292
this.currentSceneUid = 0;

lib/dayjs-init.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)