From ee306a46fc7f9ae929c2255e76db7ee72ba17c1e Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 21:18:58 -0800 Subject: [PATCH 1/2] Launches and satellites leave the world clock when destroyed Both layers registered their time coverage with the page's world clock when created and never unregistered it, so an application destroyed and started again kept each old layer, and its scene and tiles, reachable through the clock. They now unregister on destroy and register again on init, as earthquakes do. --- src/layers/launches/lifecycle.js | 10 ++++++++-- src/layers/satellites/lifecycle.js | 10 ++++++++-- src/layers/satellites/stale.test.mjs | 26 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/layers/launches/lifecycle.js b/src/layers/launches/lifecycle.js index 526676381..41b437af0 100644 --- a/src/layers/launches/lifecycle.js +++ b/src/layers/launches/lifecycle.js @@ -163,7 +163,7 @@ export function createLifecycle({ // has none), cut short and in capitals as the mission index shows names. // Registered once; off, the layer has no time to show, and each step tells // the clock once it has settled. - worldClock.register({ + const clockSource = { id: 'rocket-launches', coverage: () => { if (!layerState._enabled) return null; @@ -184,11 +184,15 @@ export function createLifecycle({ if (!marks.length) return null; return { start: marks[0].time, end: marks.at(-1).time, marks }; }, - }); + }; + // Unregistered on destroy, so a page that builds the app again holds no old layer; init + // registers it again. + let uncover = worldClock.register(clockSource); const methods = { init(viewer) { layerState._viewer = viewer; + uncover ??= worldClock.register(clockSource); layerState._enabled = false; parts.panel.createMissionPanel(); parts.overlays.createReplayVehicleOverlay(); @@ -324,6 +328,8 @@ export function createLifecycle({ async destroy(viewer) { hover?.destroy(); + uncover?.(); + uncover = null; hover = null; layerState._sourceController.abort(); releaseContinuousRender('rocket-launches'); // direct-destroy path (perf wave 2 fix) diff --git a/src/layers/satellites/lifecycle.js b/src/layers/satellites/lifecycle.js index d87aee431..832bf06e1 100644 --- a/src/layers/satellites/lifecycle.js +++ b/src/layers/satellites/lifecycle.js @@ -16,7 +16,7 @@ export function createLifecycle({ // While on with a catalog, satellites can be shown at any time in reach of // their element sets. Registered once; off, the layer has no time to show, // and each step tells the clock once it has settled. - worldClock.register({ + const clockSource = { id: 'satellites', coverage: () => { if (!layerState._enabled || !layerState._catalog.size) return null; @@ -26,7 +26,10 @@ export function createLifecycle({ end: now + SATELLITE_COVERAGE_MS, }; }, - }); + }; + // Unregistered on destroy, so a page that builds the app again holds no old layer; init + // registers it again. + let uncover = worldClock.register(clockSource); const { holdContinuousRender, releaseContinuousRender } = services.render; const { registerPickOwner, unregisterPickOwner } = services.picking; @@ -39,6 +42,7 @@ export function createLifecycle({ // Catalog data refresh; propagation remains preRender-owned. async init(viewer) { + uncover ??= worldClock.register(clockSource); // Asked first: a viewer without one fails before anything is built. const frame = frameOf(viewer); parts.catalog._abortActiveUpdates(); @@ -154,6 +158,8 @@ export function createLifecycle({ destroy(viewer) { parts.catalog._abortActiveUpdates(); + uncover?.(); + uncover = null; releaseContinuousRender('satellites'); // direct-destroy path (perf wave 2 fix) layerState._enabled = false; parts.tracking._clearTracking(); diff --git a/src/layers/satellites/stale.test.mjs b/src/layers/satellites/stale.test.mjs index 3670ea4a4..1c8308674 100644 --- a/src/layers/satellites/stale.test.mjs +++ b/src/layers/satellites/stale.test.mjs @@ -5,6 +5,7 @@ import http from 'node:http'; import { EventEmitter, once } from 'node:events'; import test from 'node:test'; import * as Cesium from 'cesium'; +import { worldClock } from '../../time/worldClock.js'; import { createSatelliteSource } from './source.js'; import { createState } from './state.js'; import { createControls } from './controls.js'; @@ -309,3 +310,28 @@ test('destroy aborts an in-flight response and initialization starts with new ow assert.equal(f.stats().count, CORE.length); assert.equal(f.feed(), 'nominal'); }); + +test('destroy takes the layer off the world clock, and init puts it back', async (t) => { + // Each registration the layer makes, while it stands. + const register = worldClock.register; + const standing = new Set(); + worldClock.register = (source) => { + standing.add(source); + const off = register.call(worldClock, source); + return () => { + standing.delete(source); + off(); + }; + }; + t.after(() => { + worldClock.register = register; + }); + const f = await fixture(t); + const mine = () => + [...standing].filter(({ id }) => id === 'satellites').length; + assert.equal(mine(), 1); + f.parts.lifecycle.methods.destroy(f.viewer); + assert.equal(mine(), 0); + await f.parts.lifecycle.methods.init(f.viewer); + assert.equal(mine(), 1); +}); From 9db71ad443b9865dc74040aad7bd745579db30d4 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 21:19:09 -0800 Subject: [PATCH 2/2] Add the changelog entry for the world clock fix --- changelog.d/1778-clock-sources-on-destroy.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog.d/1778-clock-sources-on-destroy.md diff --git a/changelog.d/1778-clock-sources-on-destroy.md b/changelog.d/1778-clock-sources-on-destroy.md new file mode 100644 index 000000000..7f4a49144 --- /dev/null +++ b/changelog.d/1778-clock-sources-on-destroy.md @@ -0,0 +1,3 @@ +- Launches and satellites stop holding the world clock after they are + destroyed, so an application started again in the same page no longer keeps + the old one in memory (Sameh Khamis, @samehkhamis, #1778).