@sjvair/monitor-map 3.3.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from "svelte";
3
- import { onDestroy } from "svelte";
3
+ import { onDestroy, untrack } from "svelte";
4
4
  import MapShell from "./map/MapShell.svelte";
5
5
  import MonitorsDisplayOptions from "./monitors/components/MonitorsDisplayOptions.svelte";
6
6
  import MapLayersDisplayOptions from "./components/MapLayersDisplayOptions.svelte";
@@ -54,10 +54,15 @@
54
54
  // applies a later "?pollutant=" change (e.g. navigating in from elsewhere) to an already-running manager.
55
55
  $effect(() => {
56
56
  const urlPollutant = route.search.pollutant;
57
+ // Read monitorsManager.pollutant via untrack: this effect must only react to the URL
58
+ // changing (e.g. navigating in from elsewhere), not to monitorsManager.pollutant itself.
59
+ // Tracking it here would make a UI-driven pollutant change (e.g. the display-options
60
+ // toggle) re-trigger this effect before the manager->URL effect below can sync the URL,
61
+ // so this effect would see the still-stale URL and immediately revert the user's change.
57
62
  if (
58
63
  monitorsManager.initialized &&
59
64
  (urlPollutant === "pm25" || urlPollutant === "o3") &&
60
- monitorsManager.pollutant !== urlPollutant
65
+ untrack(() => monitorsManager.pollutant) !== urlPollutant
61
66
  ) {
62
67
  monitorsManager.pollutant = urlPollutant;
63
68
  }
@@ -70,8 +70,12 @@
70
70
  const TRANSITION_MS = 300;
71
71
 
72
72
  $effect(() => {
73
+ // mapManager.map is only ever assigned once its own initial "load" has
74
+ // already fired (see initializeMap in map.svelte.ts), so by the time this
75
+ // effect sees a non-null map, it's already safe to reveal — waiting for a
76
+ // further "idle" event here is unreliable since one may never fire again.
73
77
  if (mapManager.map && ready) {
74
- mapManager.map.once("idle", () => disableLoadScreen());
78
+ disableLoadScreen();
75
79
  }
76
80
  });
77
81
 
@@ -42,7 +42,7 @@ export const initializeMap = (container) => {
42
42
  preset: "milkyway"
43
43
  }
44
44
  });
45
- map.once("idle", () => {
45
+ map.once("load", () => {
46
46
  mapManager.map = map;
47
47
  });
48
48
  return () => map.remove();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sjvair/monitor-map",
3
3
  "description": "SJVAir's interactive monitor map",
4
- "version": "3.3.0",
4
+ "version": "3.3.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SJVAir/monitor-map"
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from "svelte";
3
- import { onDestroy } from "svelte";
3
+ import { onDestroy, untrack } from "svelte";
4
4
  import MapShell from "$lib/map/MapShell.svelte";
5
5
  import MonitorsDisplayOptions from "$lib/monitors/components/MonitorsDisplayOptions.svelte";
6
6
  import MapLayersDisplayOptions from "$lib/components/MapLayersDisplayOptions.svelte";
@@ -54,10 +54,15 @@
54
54
  // applies a later "?pollutant=" change (e.g. navigating in from elsewhere) to an already-running manager.
55
55
  $effect(() => {
56
56
  const urlPollutant = route.search.pollutant;
57
+ // Read monitorsManager.pollutant via untrack: this effect must only react to the URL
58
+ // changing (e.g. navigating in from elsewhere), not to monitorsManager.pollutant itself.
59
+ // Tracking it here would make a UI-driven pollutant change (e.g. the display-options
60
+ // toggle) re-trigger this effect before the manager->URL effect below can sync the URL,
61
+ // so this effect would see the still-stale URL and immediately revert the user's change.
57
62
  if (
58
63
  monitorsManager.initialized &&
59
64
  (urlPollutant === "pm25" || urlPollutant === "o3") &&
60
- monitorsManager.pollutant !== urlPollutant
65
+ untrack(() => monitorsManager.pollutant) !== urlPollutant
61
66
  ) {
62
67
  monitorsManager.pollutant = urlPollutant;
63
68
  }
@@ -70,8 +70,12 @@
70
70
  const TRANSITION_MS = 300;
71
71
 
72
72
  $effect(() => {
73
+ // mapManager.map is only ever assigned once its own initial "load" has
74
+ // already fired (see initializeMap in map.svelte.ts), so by the time this
75
+ // effect sees a non-null map, it's already safe to reveal — waiting for a
76
+ // further "idle" event here is unreliable since one may never fire again.
73
77
  if (mapManager.map && ready) {
74
- mapManager.map.once("idle", () => disableLoadScreen());
78
+ disableLoadScreen();
75
79
  }
76
80
  });
77
81
 
@@ -61,7 +61,7 @@ export const initializeMap: Attachment<HTMLDivElement> = (container: string | HT
61
61
  }
62
62
  });
63
63
 
64
- map.once("idle", () => {
64
+ map.once("load", () => {
65
65
  mapManager.map = map;
66
66
  });
67
67