Skip to content

Commit 0da343b

Browse files
fix(weather): use stable instanceId to prevent duplicate fetchers (#4092)
During the server-side migration (PR #4032), the `instanceId` was built with `Date.now()`, making it unique per client reload. This approach was fine in the old browser-based architecture where reloads cleaned up everything automatically. But now the node_helper persists across reloads, so each reconnect created a new `HTTPFetcher` while the old one kept polling - silently multiplying API calls over time. The fix is simple: use `this.identifier` as the `instanceId`, which is already stable and unique per module slot. This is the same approach the Calendar module uses. On the node_helper side, when a provider already exists for the same `instanceId`, we now skip re-creation and just resend `WEATHER_INITIALIZED` so the client picks up where it left off. Fixes https://forum.magicmirror.builders/topic/20199
1 parent 96c18ec commit 0da343b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

defaultmodules/weather/node_helper.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ module.exports = NodeHelper.create({
3131
Log.log(`Attempting to initialize provider ${identifier} for instance ${instanceId}`);
3232

3333
if (this.providers[instanceId]) {
34-
Log.log(`Weather provider ${identifier} already initialized for instance ${instanceId}`);
34+
Log.log(`Weather provider ${identifier} already initialized for instance ${instanceId}, re-sending WEATHER_INITIALIZED`);
35+
// Client may have restarted (e.g. page reload) - re-send so it recovers location name
36+
this.sendSocketNotification("WEATHER_INITIALIZED", {
37+
instanceId,
38+
locationName: this.providers[instanceId].locationName
39+
});
3540
return;
3641
}
3742

defaultmodules/weather/weather.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ Module.register("weather", {
110110
this.config.showHumidity = this.config.showHumidity ? "wind" : "none";
111111
}
112112

113-
// All providers run server-side: generate unique instance ID and initialize via node_helper
114-
this.instanceId = `${this.identifier}_${Date.now()}`;
113+
// All providers run server-side: use stable identifier so reconnects don't spawn duplicate HTTPFetchers
114+
this.instanceId = this.identifier;
115115

116116
if (window.initWeatherTheme) window.initWeatherTheme(this);
117117

0 commit comments

Comments
 (0)