Separate scene handoff and attachment from the page shell

Move the page handoff sequence into SceneSwitcher and include restoration
in the application's candidate attachment. Release a failed candidate once
before the request coordinator recovers the working engine. Keep address
ordering, parked renderers, retained layers and cockpit resumption intact.

Define the layer session and its field owners. Share its retention decision
across teardown paths. Separate layer scene binding from lifecycle policy,
and shell scene composition from page controls. Keep failed renderer
releases in the binding owner, with the existing retry behavior.

Give Director the scene and use the engine host for its canvas and pack
container. Keep the existing tracked-subject interaction guard so neither
engine's behavior changes. Pass startup chrome the first backend's explicit
welcome policy instead of testing for a viewer. Cesium remains the behavior
reference; this restructuring intentionally changes no visible behavior on
either engine.

Viewer references outside the Cesium engine fall from 948 to 933. All other
coupling counts stay unchanged. Scene service ownership, raw debug access,
and the remaining shell and host queues still need consolidation.

Checked in the browser, keyless, on the dev server: the engine switch,
Director engine switch, layer panel and layer visibility on both engines
pass, and 14 of 15 strict scenarios pass (rapid, hidden-tab, context-loss,
parked-release, Navara HD, failure matrix and soak among them). app-once
and the Director next-shot step fail the same way before this change.
This commit is contained in:
German Khokhlov committed 2026-11-07 15:44:03 +04:00
1 parent f385986383
commit 656943641c
23 files changed
+1265 -888

No files matched your search

+23 -7
View File
@@ -1,3 +1,4 @@
import { retainsLayerSession } from '../app/layerSession.js';
import { createStandaloneCatalog } from './catalog.js';
import { createStandalonePlaceSearch } from './placeSearch.js';
import { CITY_POIS } from '../cityPois.js';
@@ -94,7 +95,9 @@ export function createStandaloneApplication({
async function openScene(kind) {
const controller = new AbortController();
const releases = [];
const release = async () => {
let releasing;
const release = () => (releasing ??= releaseResources());
const releaseResources = async () => {
// A reason made here would keep this call's stack, and with it the
// released scene, alive in every closure that still holds `signal`.
controller.abort(SCENE_RELEASED);
@@ -156,6 +159,7 @@ export function createStandaloneApplication({
});
return Object.freeze({
...scene,
signal,
kind,
catalog: sceneCatalog,
release,
@@ -254,10 +258,7 @@ export function createStandaloneApplication({
// the globe's renderer is parked or released.
context.defer(async () => {
await sceneHost.detach({
handoff: Boolean(
layerSession?.handoffLayers &&
!layerSession.lifetime.signal.aborted,
),
handoff: retainsLayerSession(layerSession),
});
const scene = current;
current = null;
@@ -332,14 +333,30 @@ export function createStandaloneApplication({
* detaches what attached and releases the candidate; the session stays as
* it was, ready for the working engine to attach again.
*/
async function attachScene(kind) {
async function attachScene(kind, { resume } = {}) {
if (application.getState().status !== 'ready')
throw new Error('The application is not running');
if (current) throw new Error('A globe is attached; detach it first');
const next = await openScene(kind);
try {
await sceneHost.attach(next);
current = next;
await resume?.();
lifetime.throwIfAborted();
} catch (error) {
// attach() releases partial parts itself; a failed resume leaves a
// complete attachment for this transaction to detach.
if (current === next) {
current = null;
await sceneHost
.detach({ handoff: !lifetime.aborted })
.catch((cleanupError) =>
console.error(
'A failed globe could not be released:',
cleanupError,
),
);
}
await next
.release()
.catch((cleanupError) =>
@@ -347,7 +364,6 @@ export function createStandaloneApplication({
);
throw error;
}
current = next;
return sceneView;
}