From 78b8d8dc786cdc5237ac3ed1a36d1f7e9583c46b Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Mon, 16 Nov 2026 14:13:06 -0800 Subject: [PATCH] Stories: read whether the story was playing before the press stops it The director's own pointerdown listener, added first, stops a run whose camera it drives before Stories heard the press, so the tap still played the story again. Stories now reads the press in the capture phase, and its tap listeners are removed on teardown. --- src/stories/controller.js | 8 +++++--- src/stories/controller.test.mjs | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/stories/controller.js b/src/stories/controller.js index 247384365..97106fda8 100644 --- a/src/stories/controller.js +++ b/src/stories/controller.js @@ -745,7 +745,8 @@ export function createStoriesController({ let downAt = null; // Whether the story was playing when the tap began: a camera move the // scene drives frame by frame stops on the press itself, before the tap - // ends, and that tap still means pause. + // ends, and that tap still means pause. The press is read in the capture + // phase, before the director's own listener can stop the run. let playingAtDown = false; const onDown = (e) => { downAt = [e.clientX, e.clientY]; @@ -768,7 +769,7 @@ export function createStoriesController({ store.bigPlay = true; } else player.play(); }; - canvas.addEventListener('pointerdown', onDown); + canvas.addEventListener('pointerdown', onDown, true); canvas.addEventListener('pointerup', onUp); /** @returns {boolean} False when the camera is not free (Cockpit). */ @@ -1237,7 +1238,8 @@ export function createStoriesController({ useInstalledScenes(null); removeEventListener('popstate', onPopState); removeEventListener('popstate', onLandingCapture, true); - canvas.removeEventListener('pointerdown', onDown); + canvas.removeEventListener('pointerdown', onDown, true); + canvas.removeEventListener('pointerup', onUp); canvas.removeEventListener('pointerdown', onExploreInput); canvas.removeEventListener('pointerup', onExploreInput); canvas.removeEventListener('pointercancel', onExploreInput); diff --git a/src/stories/controller.test.mjs b/src/stories/controller.test.mjs index 0c613420d..6ee2039a4 100644 --- a/src/stories/controller.test.mjs +++ b/src/stories/controller.test.mjs @@ -783,7 +783,24 @@ test('a story opened while the scene tears down is not undone by the late restor }); test('a tap pauses a story whose camera move stopped on the press', async () => { - const { controller, store, director, canvas } = setup(); + setActivePinia(createPinia()); + history.replaceState(null, '', '/?x=1#v=2&lat=1'); + const store = useStoriesStore(); + const scene = fakeScene(); + const { canvas } = scene; + // As in the app, the director listens for the press before Stories does, + // and stopping its run publishes a stopped clock at once. + canvas.addEventListener('pointerdown', () => { + store.playback = { ...store.playback, playing: false }; + }); + const director = fakeDirector(); + const controller = createStoriesController({ + viewer: scene.viewer, + director, + store, + clock: fakeClock(), + }); + store.connect(controller, listStories()); controller.openStory('gev:flights-radar'); await tick(20); let starts = 0; @@ -793,9 +810,7 @@ test('a tap pauses a story whose camera move stopped on the press', async () => }; store.playback = { ...store.playback, playing: true }; canvas.dispatchEvent(new Event('pointerdown')); - // A camera move the scene drives frame by frame stops on the press, so the - // story already reads as stopped when the tap ends. - store.playback = { ...store.playback, playing: false }; + assert.equal(store.playback.playing, false, 'the press stopped the run'); canvas.dispatchEvent(new Event('pointerup')); await tick(20); assert.equal(starts, 0, 'the tap does not play it again');