From ca98ed191998e7320a487b8cce978ed3d978d423 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Thu, 19 Nov 2026 14:19:45 -0800 Subject: [PATCH 1/2] feat(app): a host names the layers a bare address starts with createApplicationControls takes startLayers, the layer ids that turn on when the address carries no link (none by default). They restore through the passive start-up path, so they are never written as the user's own choice, and a link's own layers always win. --- docs/CURRENT-STATE.md | 3 +++ src/app/controls.js | 4 +++ src/data/layerState.test.mjs | 43 +++++++++++++++++++++++++++++++ src/data/layerStateCoordinator.js | 9 ++++++- src/ui/applicationShell.js | 4 +++ src/ui/shareRestoration.js | 4 +++ 6 files changed, 66 insertions(+), 1 deletion(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index b89acd8ae3..2889698b97 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -8824,6 +8824,9 @@ remembers" are different promises: a link restores what its hash carries, and a bare URL starts with the default layers and options (`src/ui/shareRestoration.js` passes `allowLocalState: false`), so clearing the address always resets the view. + A host may name the layers a bare URL starts with (`startLayers` on + `createApplicationControls`, e.g. `['flights', 'satellites']`); they are + restored passively, never written to storage, and a link's own layers win. - **Detection mode/density and scope feather have NO storage key at all.** Their only durable carrier is the URL hash (`dm`/`dd`, `scf`), written on a 500 ms debounce. A same-URL reload therefore keeps them only if that debounce already diff --git a/src/app/controls.js b/src/app/controls.js index 8e152a1e02..e7965f39ed 100644 --- a/src/app/controls.js +++ b/src/app/controls.js @@ -21,6 +21,8 @@ export { START_VIEW }; * `homeView` is where the title's logo goes back to (with the clock live): the * start view unless given, for a host whose `startView` only carries a view * across a rebuild. + * `startLayers` are the layer ids a bare address (one that carries no link) + * starts with: none by default; a host may pass `['flights', 'satellites']`. * `services.cockpitSubjects` adds the application's own first-person subjects * to the Cockpit (src/cockpitSubjectProviders.js). */ @@ -36,6 +38,7 @@ export function createApplicationControls({ localePicker = true, startView = START_VIEW, homeView = startView, + startLayers = [], }) { // Every boot starts from the same view, before share restoration flies on. applyStartView(viewer, startView); @@ -59,6 +62,7 @@ export function createApplicationControls({ initialShareCode, localePicker, homeView, + startLayers, }); defer(() => styleManager.orbitController.stop()); defer(() => styleManager.hud.destroy()); diff --git a/src/data/layerState.test.mjs b/src/data/layerState.test.mjs index 116a77c883..93f4f8e568 100644 --- a/src/data/layerState.test.mjs +++ b/src/data/layerState.test.mjs @@ -3231,3 +3231,46 @@ test('an application with every layer registered keeps every requested layer', a ]); coordinator.destroy(); }); + +test('start layers turn on when nothing names any, and are never written as the user choice', async () => { + const storage = memoryStorage(); + const manager = productionManager(); + const coordinator = new LayerStateCoordinator(manager, shareSink(), { + storage, + }); + const results = await coordinator.start({ + allowLocalState: false, + startLayerIds: ['earthquakes', 'traffic', 'not-a-layer'], + }); + assert.equal(coordinator.source, 'start'); + assert.deepEqual(coordinator.getDurableState().enabledLayerIds, [ + 'earthquakes', + 'traffic', + ]); + assert.equal(manager.isEnabled('earthquakes'), true); + assert.equal(manager.isEnabled('traffic'), true); + assert.equal( + results.every((result) => result.persistenceWrite === false), + true, + ); + assert.deepEqual(storage.writes, []); + coordinator.destroy(); +}); + +test('a shared layer payload wins over start layers', async () => { + const manager = productionManager(); + const coordinator = new LayerStateCoordinator(manager, shareSink(), { + storage: memoryStorage(), + }); + const shared = createDefaultLayerState(); + shared.enabledLayerIds = ['radio']; + await coordinator.start({ + shareLayerState: shared, + allowLocalState: false, + startLayerIds: ['earthquakes'], + }); + assert.equal(coordinator.source, 'share'); + assert.deepEqual(coordinator.getDurableState().enabledLayerIds, ['radio']); + assert.equal(manager.isEnabled('earthquakes'), false); + coordinator.destroy(); +}); diff --git a/src/data/layerStateCoordinator.js b/src/data/layerStateCoordinator.js index 7cd5545392..ad1b3e31aa 100644 --- a/src/data/layerStateCoordinator.js +++ b/src/data/layerStateCoordinator.js @@ -103,6 +103,7 @@ export class LayerStateCoordinator { shareLayerState = null, allowLocalState = true, shareCreatedAtMs = null, + startLayerIds = [], } = {}) { if (this._destroyed) throw new Error('Layer-state coordinator is destroyed'); @@ -125,7 +126,13 @@ export class LayerStateCoordinator { selected = this._normalize(stored); this._source = 'local'; } - } else { + } + if (!selected && startLayerIds.length) { + // The layers the application starts with when nothing names any: + // restored passively, so they are never written as the user's choice. + selected = this._normalize({ enabledLayerIds: startLayerIds }); + this._source = 'start'; + } else if (!selected && !allowLocalState) { // A valid historical camera/style share with no v2 layer payload keeps // the exact legacy default-layer behavior. It must not inherit an // unrelated recipient's saved local layer preferences. diff --git a/src/ui/applicationShell.js b/src/ui/applicationShell.js index cf270e6c47..1adbe4ad84 100644 --- a/src/ui/applicationShell.js +++ b/src/ui/applicationShell.js @@ -117,6 +117,8 @@ export class StyleManager extends ShellFacade { * @param {{lon: number, lat: number, height: number, heading?: number, * pitch?: number}|null} [options.homeView] - where the title's logo goes * back to (degrees): the view the app started from. + * @param {string[]} [options.startLayers] - the layers a bare address (one + * that carries no link) starts with; none by default. */ constructor( viewer, @@ -128,6 +130,7 @@ export class StyleManager extends ShellFacade { initialShareCode = null, localePicker = true, homeView = null, + startLayers = [], } = {}, ) { super(); @@ -256,6 +259,7 @@ export class StyleManager extends ShellFacade { updateFeedback: () => this._updateGlobalLoadingFeedback(), applyFollowOffset: (followed, offset) => applyShareFollowOffset(viewer, followed, offset), + startLayers, }); this._visualSettings = new VisualSettings({ diff --git a/src/ui/shareRestoration.js b/src/ui/shareRestoration.js index 6d93d5061c..0b34ffbd55 100644 --- a/src/ui/shareRestoration.js +++ b/src/ui/shareRestoration.js @@ -167,7 +167,10 @@ export class ShareRestoration { feedback, updateFeedback, applyFollowOffset = null, + startLayers = [], }) { + // The layers a bare address starts with; a link names its own. + this._startLayers = startLayers; Object.assign(this, { viewer, navigation, @@ -421,6 +424,7 @@ export class ShareRestoration { // with the default layers. Saved layer choices never come back on // their own, so clearing the address always resets the view. allowLocalState: false, + startLayerIds: this._initialShareState ? [] : this._startLayers, }); if (this._initialShareSelectionSuperseded) { this._layerStateCoordinator.cancelPendingShareTracking( From 23837768e1ae2acb95e4237146f3789fc0b1ca41 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Thu, 19 Nov 2026 14:19:55 -0800 Subject: [PATCH 2/2] Add the changelog entry for #1867 --- changelog.d/1867-start-layers.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog.d/1867-start-layers.md diff --git a/changelog.d/1867-start-layers.md b/changelog.d/1867-start-layers.md new file mode 100644 index 0000000000..d617556057 --- /dev/null +++ b/changelog.d/1867-start-layers.md @@ -0,0 +1,4 @@ +- An application can name the layers a bare address starts with + (`startLayers` on `createApplicationControls`; none by default): they turn on + without being saved as the user's own choice, and a link's own layers always + win (samehkhamis, #1867).